-
Notifications
You must be signed in to change notification settings - Fork 3
/
resources.go
48 lines (41 loc) · 1.81 KB
/
resources.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
package corbel
import (
"fmt"
"net/http"
)
// ResourcesService handles the interface for retrival resource's representation
// on Corbel.
//
// Full API info: http://docs.corbelresources.apiary.io/
type ResourcesService struct {
client *Client
}
// UserACL defines the content of an ACL for a user
type UserACL struct {
Permission string `json:"permission"`
Properties map[string]interface{} `json:"properties"`
}
func (r *ResourcesService) createRequest(method, accept, uri string, body interface{}) (*http.Request, error) {
return r.client.NewRequestContentType(method, "resources", uri, "application/json", accept, body)
}
// CollectionRequest perform a specific collection request on resources
func (r *ResourcesService) CollectionRequest(method, accept, collectionName string, send interface{}) (*http.Request, error) {
uri := fmt.Sprintf("/v1.0/resource/%s", collectionName)
return r.createRequest(method, accept, uri, send)
}
// ResourceRequest perform a specific resource request on resources
func (r *ResourcesService) ResourceRequest(method, accept, collectionName, id string, send interface{}) (*http.Request, error) {
uri := fmt.Sprintf("/v1.0/resource/%s/%s", collectionName, id)
return r.createRequest(method, accept, uri, send)
}
// RelationRequest perform a specific relation request on resources
func (r *ResourcesService) RelationRequest(method, accept, collectionName, resourceID, relationName, relatedCollectionName, relatedID string, send interface{}) (*http.Request, error) {
uri := fmt.Sprintf("/v1.0/resource/%s/%s/%s", collectionName, resourceID, relationName)
if relatedCollectionName != "" || relatedID != "" {
uri = fmt.Sprintf("%s;r=%s", uri, relatedCollectionName)
}
if relatedID != "" {
uri = fmt.Sprintf("%s/%s", uri, relatedID)
}
return r.createRequest(method, accept, uri, send)
}