-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.go
53 lines (39 loc) · 1.21 KB
/
api.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
package rdapi
import (
"encoding/json"
"strconv"
"time"
"github.com/tellthechef/rdapi/models"
)
const DiaryDateFormat = "2006-01-02"
type RDConfig struct {
ConsumerKey string
ConsumerSecret string
SecondSecret string
RestaurantID int
Endpoint string
ServiceEndpoint string
firstAuth authKeys
secondAuth authKeys
}
func (api *RDConfig) GetDiary(date time.Time) ([]models.ShortBooking, error) {
var bookings []models.ShortBooking
client, req, _ := api.RestaurantRequest("GET", "/DiaryData?date="+date.Format(DiaryDateFormat), nil)
res, _ := client.Do(req)
err := json.NewDecoder(res.Body).Decode(&bookings)
return bookings, err
}
func (api *RDConfig) GetBooking(id int) (models.Booking, error) {
var booking models.Booking
client, req, _ := api.RestaurantRequest("GET", "/Booking/"+strconv.Itoa(id), nil)
res, _ := client.Do(req)
err := json.NewDecoder(res.Body).Decode(&booking)
return booking, err
}
func (api *RDConfig) GetRestaurant() (models.RestaurantConsolidated, error) {
var restaurant models.Restaurant
client, req, _ := api.RestaurantRequest("GET", "", nil)
res, _ := client.Do(req)
err := json.NewDecoder(res.Body).Decode(&restaurant)
return restaurant.Consolidate(), err
}