-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclass.go
58 lines (51 loc) · 1.5 KB
/
class.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
package goparse
import (
"encoding/json"
"errors"
"net/url"
)
// ParseClass is an object that contains the ParseSession
type ParseClass struct {
Session *ParseSession
Name string
ClassURL string
UseMaster bool
}
// Select gets class data information
func (c *ParseClass) Select(objectID string, result interface{}) error {
path := c.ClassURL
if objectID != "" {
path = c.ClassURL + "/" + objectID
}
return do(c.Session.get(path, c.UseMaster), &result)
}
// Select gets class data information by custom query
func (c *ParseClass) SelectQuery(query map[string]interface{}, result interface{}) error {
b, err := json.Marshal(query)
if err != nil {
return err
}
where := url.Values{
"where": []string{string(b)},
}
path := c.ClassURL + "?" + where.Encode()
return do(c.Session.get(path, c.UseMaster), &result)
}
// Create creates class from data
func (c *ParseClass) Create(data interface{}, result interface{}) error {
return do(c.Session.post(c.ClassURL, c.UseMaster).Send(data), &result)
}
// Update updates class by ID
func (c *ParseClass) Update(objectID string, data interface{}, result interface{}) error {
if objectID == "" {
return errors.New("ObjectID must not be empty")
}
return do(c.Session.put(c.ClassURL+"/"+objectID, c.UseMaster).Send(data), &result)
}
// Delete deletes class by ID
func (c *ParseClass) Delete(objectID string) error {
if objectID == "" {
return errors.New("ObjectID must not be empty")
}
return do(c.Session.del(c.ClassURL+"/"+objectID, c.UseMaster), nil)
}