-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgosellix.go
236 lines (220 loc) · 6.45 KB
/
gosellix.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package goSellix
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type SellixClient struct {
Client *http.Client
Request *http.Request
AuthKey string
Method string
Url string
}
func (r *SellixClient) getBody() []byte {
r.Request.Header.Add("Authorization", "Bearer "+r.AuthKey)
res, err := r.Client.Do(r.Request)
if err != nil {
return []byte("error making request")
}
buf, err := ioutil.ReadAll(res.Body)
if err != nil {
return []byte("error making request")
}
return buf
}
func NewClient(authKey string) SellixClient {
return SellixClient{
Client: http.DefaultClient,
AuthKey: authKey,
}
}
func (r *SellixClient) GetAllQueries() Queries {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/queries"
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixQuery Queries
err := json.Unmarshal(buf, &SellixQuery)
if err != nil {
return Queries{}
}
return SellixQuery
}
func (r *SellixClient) GetAllProducts() Product {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/products"
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixProduct Product
err := json.Unmarshal(buf, &SellixProduct)
if err != nil {
return Product{}
}
return SellixProduct
}
func (r *SellixClient) GetAllFeedbacks() Feedback {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/feedback"
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixFeedback Feedback
err := json.Unmarshal(buf, &SellixFeedback)
if err != nil {
return Feedback{}
}
return SellixFeedback
}
func (r *SellixClient) FeedbackFromProduct(productUniqid string) UserFeedback {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/feedback/" + productUniqid
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixFeedback UserFeedback
err := json.Unmarshal(buf, &SellixFeedback)
if err != nil {
return UserFeedback{}
}
return SellixFeedback
}
func (r *SellixClient) DeleteCoupon(couponUniqid string) CouponDelete {
r.Method = "DELETE"
r.Url = "https://dev.sellix.io/v1/coupons/" + couponUniqid
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixCoupon CouponDelete
err := json.Unmarshal(buf, &SellixCoupon)
if err != nil {
return CouponDelete{}
}
return SellixCoupon
}
func (r *SellixClient) MakeCoupon(couponCode string, couponDiscount, couponUses int, couponProducts []string) CouponCreation {
r.Method = "POST"
r.Url = "https://dev.sellix.io/v1/coupons"
payload := map[string]interface{}{"code": couponCode, "discount_value": couponDiscount, "max_uses": couponUses, "products_bound": couponProducts}
byts, err := json.Marshal(payload)
if err != nil {
return CouponCreation{}
}
req, _ := http.NewRequest(r.Method, r.Url, bytes.NewBuffer(byts))
r.Request = req
buf := r.getBody()
var SellixResponse CouponCreation
err = json.Unmarshal(buf, &SellixResponse)
if err != nil {
return CouponCreation{}
}
return SellixResponse
}
func (r *SellixClient) CouponList() CouponResp {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/coupons"
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixResponse CouponResp
err := json.Unmarshal(buf, &SellixResponse)
if err != nil {
return CouponResp{}
}
return SellixResponse
}
func (r *SellixClient) DeleteBlacklist(blacklistUniqid string) BlacklistCreation {
r.Method = "DELETE"
r.Url = "https://dev.sellix.io/v1/blacklists/" + blacklistUniqid
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixBlacklist BlacklistCreation
err := json.Unmarshal(buf, &SellixBlacklist)
if err != nil {
return BlacklistCreation{}
}
return SellixBlacklist
}
func (r *SellixClient) EditBlacklist(blacklistUniqid, blacklistType, blacklistData, blacklistMessage string) BlacklistCreation {
r.Method = "PUT"
r.Url = "https://dev.sellix.io/v1/blacklists/" + blacklistUniqid
payload := map[string]interface{}{"type": blacklistType, "data": blacklistData, "note": blacklistMessage}
byts, err := json.Marshal(payload)
if err != nil {
return BlacklistCreation{}
}
req, _ := http.NewRequest(r.Method, r.Url, bytes.NewBuffer(byts))
req.Header.Set("Content-Type", "application/json")
r.Request = req
buf := r.getBody()
var SellixBlacklist BlacklistCreation
err = json.Unmarshal(buf, &SellixBlacklist)
if err != nil {
return BlacklistCreation{}
}
return SellixBlacklist
}
func (r *SellixClient) CreateBlacklist(blacklistType, blacklistData, blacklistMessage string) BlacklistCreation {
r.Method = "POST"
r.Url = "https://dev.sellix.io/v1/blacklists"
payload := map[string]interface{}{"type": blacklistType, "data": blacklistData, "note": blacklistMessage}
byts, err := json.Marshal(payload)
if err != nil {
return BlacklistCreation{}
}
req, _ := http.NewRequest(r.Method, r.Url, bytes.NewBuffer(byts))
req.Header.Set("Content-Type", "application/json")
r.Request = req
buf := r.getBody()
var SellixBlacklist BlacklistCreation
err = json.Unmarshal(buf, &SellixBlacklist)
if err != nil {
return BlacklistCreation{}
}
return SellixBlacklist
}
func (r *SellixClient) BlacklistByID(blacklistID string) BlacklistSpec {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/blacklists/" + blacklistID
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixBlacklist BlacklistSpec
err := json.Unmarshal(buf, &SellixBlacklist)
if err != nil {
return BlacklistSpec{}
}
return SellixBlacklist
}
func (r *SellixClient) AllBlacklist() Blacklist {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/blacklists"
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixBlacklist Blacklist
err := json.Unmarshal(buf, &SellixBlacklist)
if err != nil {
return Blacklist{}
}
return SellixBlacklist
}
func (r *SellixClient) OrderByID(orderUniqID string) Order {
r.Method = "GET"
r.Url = "https://dev.sellix.io/v1/orders/" + orderUniqID
req, _ := http.NewRequest(r.Method, r.Url, nil)
r.Request = req
buf := r.getBody()
var SellixOrder Order
err := json.Unmarshal(buf, &SellixOrder)
if err != nil {
fmt.Println(err)
return Order{}
}
return SellixOrder
}