-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.go
72 lines (65 loc) · 1.5 KB
/
client.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
68
69
70
71
72
package destination
import (
"net/http"
"github.com/onfleet/gonfleet"
"github.com/onfleet/gonfleet/netwrk"
)
type Client struct {
apiKey string
rlHttpClient *netwrk.RlHttpClient
url string
call netwrk.Caller
}
func Plug(apiKey string, rlHttpClient *netwrk.RlHttpClient, url string, call netwrk.Caller) *Client {
return &Client{
apiKey: apiKey,
rlHttpClient: rlHttpClient,
url: url,
call: call,
}
}
// Reference https://docs.onfleet.com/reference/get-single-destination
func (c *Client) Get(destinationId string) (onfleet.Destination, error) {
destination := onfleet.Destination{}
err := c.call(
c.apiKey,
c.rlHttpClient,
http.MethodGet,
c.url,
[]string{destinationId},
nil,
nil,
&destination,
)
return destination, err
}
// Reference https://docs.onfleet.com/reference/create-destination
func (c *Client) Create(params onfleet.DestinationCreateParams) (onfleet.Destination, error) {
destination := onfleet.Destination{}
err := c.call(
c.apiKey,
c.rlHttpClient,
http.MethodPost,
c.url,
nil,
nil,
params,
&destination,
)
return destination, err
}
// Reference https://docs.onfleet.com/reference/querying-by-metadata
func (c *Client) ListWithMetadataQuery(metadata []onfleet.Metadata) ([]onfleet.Destination, error) {
destinations := []onfleet.Destination{}
err := c.call(
c.apiKey,
c.rlHttpClient,
http.MethodPost,
c.url,
[]string{"metadata"},
nil,
metadata,
&destinations,
)
return destinations, err
}