-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmiot_client.go
56 lines (45 loc) · 1.05 KB
/
cmiot_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
package cmiot_v2
import "encoding/json"
type CMIOTClient struct {
client *CMIOTHttp
debug bool
forwarderIp string
apiId string
apiPassword string
ecid string
}
func NewCMIOTClient(apiId string, apiPassword string, ecid string) *CMIOTClient {
return &CMIOTClient{apiId: apiId, apiPassword: apiPassword, ecid: ecid,
client: NewCMIOTHttp(),
}
}
func (c *CMIOTClient) setProxy(proxyUrl string) {
c.client.setProxy(proxyUrl)
}
func (c *CMIOTClient) unsetProxy() {
c.client.unsetProxy()
}
func (c *CMIOTClient) SetDebug(debug bool) {
c.client.isDebug = debug
}
func (c *CMIOTClient) call(ebid string, query interface{}, body interface{}) error {
url := buildUrl(ebid)
qry, err := encodeQuery(query)
if err != nil {
return err
}
url += "?" + qry
result, err := c.client.request("GET", url, "", 30000, c.forwarderIp)
if err != nil {
return err
}
err = json.Unmarshal([]byte(result), body)
if err != nil {
return err
}
return nil
}
func (c *CMIOTClient) SetForwarderId(ip string) bool {
c.forwarderIp = ip
return true
}