This repository has been archived by the owner on Jul 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresto.go
67 lines (58 loc) · 1.56 KB
/
resto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package gobizApi
import (
"bytes"
"fmt"
"net/http"
)
type RestaurantStatusResponse struct {
OpenStatus struct {
Status string `json:"status"`
NextOpen string `json:"next_open"`
NextClose string `json:"next_close"`
} `json:"open_status"`
ForceClose bool `json:"force_close"`
}
func GetRestoStatus(restaurantID, authorization string) (string, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.gojekapi.com/gofood/merchant/v2/restaurants/%s/open_status", restaurantID), nil)
printError(err)
body, err := sendRequest(req, authorization)
if err != nil {
printError(err)
return "", err
}
printResponse(string(body))
var statusResponse RestaurantStatusResponse
err = unmarshalJSON(body, &statusResponse)
if err != nil {
printError(err)
return "", err
}
return statusResponse.OpenStatus.Status, nil
}
func SetRestoClose(restaurantID, authorization string, status bool) (bool, error) {
jsonData := map[string]bool{
"force_close": status,
}
jsonValue, err := marshalJSON(jsonData)
if err != nil {
printError(err)
return false, err
}
req, err := http.NewRequest("PATCH", fmt.Sprintf("https://api.gojekapi.com/gofood/merchant/v2/restaurants/%s", restaurantID), bytes.NewBuffer(jsonValue))
if err != nil {
printError(err)
return false, err
}
body, err := sendRequest(req, authorization)
if err != nil {
printError(err)
return false, err
}
var statusResponse RestaurantStatusResponse
err = unmarshalJSON(body, &statusResponse)
if err != nil {
printError(err)
return false, err
}
return statusResponse.ForceClose, nil
}