-
Notifications
You must be signed in to change notification settings - Fork 0
/
coupons.go
69 lines (55 loc) · 1.34 KB
/
coupons.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
package tebexgo
import (
"encoding/json"
"fmt"
"github.com/itschip/tebexgo/internal"
)
func (s *Session) GetAllCoupons() (*Coupons, error) {
resp, err := internal.GetRequest(s.Secret, CouponsEndpoint)
if err != nil {
return nil, err
}
var coupons Coupons
err = internal.UnmarshalResponse(resp, &coupons)
if err != nil {
return nil, err
}
return &coupons, nil
}
func (s *Session) GetCoupon(couponId string) (*Coupon, error) {
endpoint := fmt.Sprintf("%s/%s", CouponsEndpoint, couponId)
resp, err := internal.GetRequest(s.Secret, endpoint)
if err != nil {
return nil, err
}
var coupon Coupon
err = internal.UnmarshalResponse(resp, &coupon)
if err != nil {
return nil, err
}
return &coupon, nil
}
func (s *Session) CreateCoupon(createObject *CreateCouponObject) (*CouponData, error) {
jsonBody, err := json.Marshal(&createObject)
if err != nil {
return nil, err
}
resp, err := internal.PostRequest(s.Secret, CouponsEndpoint, jsonBody)
if err != nil {
return nil, err
}
var coupon CouponData
err = internal.UnmarshalResponse(resp, &coupon)
if err != nil {
return nil, err
}
return &coupon, nil
}
func (s *Session) DeleteCoupon(couponId string) error {
endpoint := fmt.Sprintf("%s/%s", CouponsEndpoint, couponId)
_, err := internal.DeleteRequest(s.Secret, endpoint, nil)
if err != nil {
return err
}
return nil
}