-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcatalog.go
159 lines (143 loc) · 4.4 KB
/
catalog.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package go_printify
import (
"fmt"
"net/http"
)
const (
blueprintsPath = "catalog/blueprints.json"
blueprintPath = "catalog/blueprints/%d.json"
blueprintProvidersPath = "catalog/blueprints/%d/print_providers.json"
BlueprintProviderVariantsPath = "catalog/blueprints/%d/print_providers/%d/variants.json"
BluePrintProviderShippingPath = "catalog/blueprints/%d/print_providers/%d/shipping.json"
PrintProvidersPath = "catalog/print_providers.json"
PrintProviderPath = "catalog/print_providers/%d.json"
)
type Blueprint struct {
Id int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Brand string `json:"brand"`
Model string `json:"model"`
Images []string `json:"images"`
}
type PrintProvider struct {
Id int `json:"id"`
Title string `json:"title"`
Location *map[string]string `json:"location,omitempty"`
Variants []*CatalogVariant `json:"variants,omitempty"`
}
type CatalogVariant struct {
Id int `json:"id"`
Title string `json:"title"`
Options *CatalogVariantOption `json:"options"`
Placeholders []*CatalogPlaceholder `json:"placeholders"`
}
type CatalogVariantOption struct {
Color string `json:"color"`
Size string `json:"size"`
}
type CatalogPlaceholder struct {
Position string `json:"position"`
Height int `json:"height"`
Width int `json:"width"`
}
type ShippingProperties struct {
HandlingTime struct {
Value int `json:"value"`
Unit string `json:"unit"`
} `json:"handling_time"`
Profiles struct {
VariantIds []int `json:"variant_ids"`
FirstItem priceTag `json:"first_item"`
AdditionalItems priceTag `json:"additional_items"`
Countries []string `json:"countries"`
} `json:"profiles"`
}
type priceTag struct {
Currency string `json:"currency"`
Cost float32 `json:"cost"`
}
/*
Retrieve a list of available blueprints
*/
func (c *Client) ListBluePrints() ([]*Blueprint, error) {
req, err := c.newRequest(http.MethodGet, blueprintsPath, nil)
if err != nil {
return nil, err
}
blueprintList := make([]*Blueprint, 0)
_, err = c.do(req, &blueprintList)
return blueprintList, err
}
/*
Retrieve a specific blueprint
*/
func (c *Client) GetBlueprint(Id int) (*Blueprint, error) {
req, err := c.newRequest(http.MethodGet, fmt.Sprintf(blueprintPath, Id), nil)
if err != nil {
return nil, err
}
blueprint := &Blueprint{}
_, err = c.do(req, blueprint)
return blueprint, err
}
/*
Retrieve a list of all print providers that fulfill orders for a specific blueprint
*/
func (c *Client) GetPrintProviders(blueprintId int) ([]*PrintProvider, error) {
req, err := c.newRequest(http.MethodGet, fmt.Sprintf(blueprintProvidersPath, blueprintId), nil)
if err != nil {
return nil, err
}
providers := make([]*PrintProvider, 0)
_, err = c.do(req, &providers)
return providers, err
}
/*
Retrieve a list of variants of a blueprint from a specific print provider
*/
func (c *Client) GetVariants(blueprintId, providerId int) (*PrintProvider, error) {
req, err := c.newRequest(http.MethodGet, fmt.Sprintf(BlueprintProviderVariantsPath, blueprintId, providerId), nil)
if err != nil {
return nil, err
}
printProvider := &PrintProvider{}
_, err = c.do(req, printProvider)
return printProvider, err
}
/*
Retrieve shipping information
*/
func (c *Client) GetShippingInformation(blueprintId, providerId int) (*ShippingProperties, error) {
req, err := c.newRequest(http.MethodGet, fmt.Sprintf(BluePrintProviderShippingPath, blueprintId, providerId), nil)
if err != nil {
return nil, err
}
shippingInfo := &ShippingProperties{}
_, err = c.do(req, shippingInfo)
return shippingInfo, err
}
/*
Retrieve a list of available print providers
*/
func (c *Client) GetAvailablePrintProviders() ([]*PrintProvider, error) {
req, err := c.newRequest(http.MethodGet, PrintProvidersPath, nil)
if err != nil {
return nil, err
}
providers := make([]*PrintProvider, 0)
_, err = c.do(req, &providers)
return providers, err
}
/*
Retrieve a specific print provider and a list of associated blueprint offerings
*/
func (c *Client) GetPrintProvider(Id int) (*PrintProvider, error) {
req, err := c.newRequest(http.MethodGet, fmt.Sprintf(PrintProviderPath, Id), nil)
if err != nil {
return nil, err
}
provider := &PrintProvider{}
_, err = c.do(req, provider)
return provider, err
}