forked from bold-commerce/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect.go
58 lines (49 loc) · 1.66 KB
/
collect.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 goshopify
import (
"fmt"
"time"
)
const collectsBasePath = "admin/collects"
// CollectService is an interface for interfacing with the collect endpoints
// of the Shopify API.
// See: https://help.shopify.com/api/reference/products/collect
type CollectService interface {
List(interface{}) ([]Collect, error)
Count(interface{}) (int, error)
}
// CollectServiceOp handles communication with the collect related methods of
// the Shopify API.
type CollectServiceOp struct {
client *Client
}
// Collect represents a Shopify collect
type Collect struct {
ID int `json:"id,omitempty"`
CollectionID int `json:"collection_id,omitempty"`
ProductID int `json:"product_id,omitempty"`
Featured bool `json:"featured,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Position int `json:"position,omitempty"`
SortValue string `json:"sort_value,omitempty"`
}
// Represents the result from the collects/X.json endpoint
type CollectResource struct {
Collect *Collect `json:"collect"`
}
// Represents the result from the collects.json endpoint
type CollectsResource struct {
Collects []Collect `json:"collects"`
}
// List collects
func (s *CollectServiceOp) List(options interface{}) ([]Collect, error) {
path := fmt.Sprintf("%s.json", collectsBasePath)
resource := new(CollectsResource)
err := s.client.Get(path, resource, options)
return resource.Collects, err
}
// Count collects
func (s *CollectServiceOp) Count(options interface{}) (int, error) {
path := fmt.Sprintf("%s/count.json", collectsBasePath)
return s.client.Count(path, options)
}