-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlibrarycalls.go
115 lines (106 loc) · 3.84 KB
/
librarycalls.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package GoSDK
import (
//"fmt"
"strconv"
)
const (
_LIB_PREAMBLE = "/codeadmin/v/2/library"
_HIST_PREAMBLE = "/codeadmin/v/2/history/library"
)
//GetLibrary returns a list of libraries for a system
//Returns an object of the following []map[string]interface{}{map[string]interface{}{"system_key":"associated system key","name":"the name of the library","description":"library description","version":1,"code":"function blabla(){return "blahbla"}","dependencies":"clearblade"}, ...}
func (d *DevClient) GetLibraries(systemKey string) ([]interface{}, error) {
creds, err := d.credentials()
if err != nil {
return nil, err
}
resp, err := get(d, _LIB_PREAMBLE+"/"+systemKey, nil, creds, nil)
resp, err = mapResponse(resp, err)
if err != nil {
return nil, err
}
return resp.Body.([]interface{}), nil
}
//GetLibrary returns information about a specific library
//Returns a single object following the pattern specified in GetLibraries
func (d *DevClient) GetLibrary(systemKey, name string) (map[string]interface{}, error) {
creds, err := d.credentials()
if err != nil {
return nil, err
}
resp, err := get(d, _LIB_PREAMBLE+"/"+systemKey+"/"+name, nil, creds, nil)
resp, err = mapResponse(resp, err)
if err != nil {
return nil, err
}
return resp.Body.(map[string]interface{}), nil
}
//CreateLibrary allows the developer to create a library to be called by other service functions
//returns a single object following the pattern specified in GetLibraries for the newly-created library
func (d *DevClient) CreateLibrary(systemKey, name string, data map[string]interface{}) (map[string]interface{}, error) {
creds, err := d.credentials()
if err != nil {
return nil, err
}
resp, err := post(d, _LIB_PREAMBLE+"/"+systemKey+"/"+name, data, creds, nil)
resp, err = mapResponse(resp, err)
if err != nil {
return nil, err
}
return resp.Body.(map[string]interface{}), nil
}
//UpdateLibrary allows the developer to change the content of the library
//returns a single object following the pattern specified in GetLibraries with the updated details
func (d *DevClient) UpdateLibrary(systemKey, name string, data map[string]interface{}) (map[string]interface{}, error) {
creds, err := d.credentials()
if err != nil {
return nil, err
}
resp, err := put(d, _LIB_PREAMBLE+"/"+systemKey+"/"+name, data, creds, nil)
resp, err = mapResponse(resp, err)
if err != nil {
return nil, err
}
return resp.Body.(map[string]interface{}), nil
}
//DeleteLibrary allows the developer to remove library content
func (d *DevClient) DeleteLibrary(systemKey, name string) error {
creds, err := d.credentials()
if err != nil {
return err
}
resp, err := delete(d, _LIB_PREAMBLE+"/"+systemKey+"/"+name, nil, creds, nil)
resp, err = mapResponse(resp, err)
if err != nil {
return err
}
return nil
}
//GetVersionHistory returns a slice of library descriptions corresponding to each library
//Returns an object with the same shape as that of GetLibrariesForSystem, but with each version of the specified library
func (d *DevClient) GetVersionHistory(systemKey, name string) ([]interface{}, error) {
creds, err := d.credentials()
if err != nil {
return nil, err
}
resp, err := get(d, _HIST_PREAMBLE+"/"+systemKey+"/"+name, nil, creds, nil)
resp, err = mapResponse(resp, err)
if err != nil {
return nil, err
}
return resp.Body.([]interface{}), nil
}
//GetVersion gets the current version of a library
//Returns an object with the same shape as that of GetLibrariesForSystem, but a specific version thereof
func (d *DevClient) GetVersion(systemKey, name string, version int) (map[string]interface{}, error) {
creds, err := d.credentials()
if err != nil {
return nil, err
}
resp, err := get(d, _HIST_PREAMBLE+"/"+systemKey+"/"+name+"/"+strconv.Itoa(version), nil, creds, nil)
resp, err = mapResponse(resp, err)
if err != nil {
return nil, err
}
return resp.Body.(map[string]interface{}), nil
}