-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase_client.go
43 lines (38 loc) · 981 Bytes
/
base_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
package goly
import (
"encoding/json"
"net/http"
"net/url"
"strings"
)
var envs = map[string]string{
"production": "https://lydia-app.com",
"homologation": "https://homologation.lydia-app.com",
}
func (c *Client) Init(publicVendorToken string, privateVendorToken string, env string) {
c.identity.PublicVendorToken = publicVendorToken
c.identity.PrivateVendorToken = privateVendorToken
c.env = env
endpoint, ok := envs[env]
if !ok {
endpoint = envs["production"]
}
c.endpoint = endpoint
c.options = ClientOptions{
MinExpirationDelay: 1,
}
}
func (c *Client) isIdentified() bool {
return len(c.identity.PublicVendorToken) > 0
}
func (c *Client) request(uri string, data url.Values, result interface{}) error {
res, err := http.Post(c.endpoint+"/api"+uri, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
if err != nil {
return err
}
err = json.NewDecoder(res.Body).Decode(&result)
if err != nil {
return err
}
return nil
}