-
Notifications
You must be signed in to change notification settings - Fork 7
/
integration.go
118 lines (105 loc) · 3.32 KB
/
integration.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
package sendcloud
import (
"encoding/json"
"time"
)
type IntegrationParams struct {
ID int64
Name string
URL string
IsWebhooksEnabled bool
WebhookURL string
}
type IntegrationRequest struct {
ShopName string `json:"shop_name"`
ShopURL string `json:"shop_url"`
ServicePointEnabled bool `json:"service_point_enabled"`
ServicePointCarriers []string `json:"service_point_carriers"`
WebhookActive bool `json:"webhook_active"`
WebhookURL string `json:"webhook_url"`
}
type IntegrationListResponseContainer []IntegrationResponseContainer
type IntegrationResponseContainer struct {
ID int64 `json:"id"`
ShopName string `json:"shop_name"`
ShopURL string `json:"shop_url"`
System string `json:"system"`
FailingSince string `json:"failing_since"`
LastFetch string `json:"last_fetch"`
LastUpdatedAt time.Time `json:"last_updated_at"`
ServicePointEnabled bool `json:"service_point_enabled"`
ServicePointCarriers []string `json:"service_point_carriers"`
WebhookActive bool `json:"webhook_active"`
WebhookURL string `json:"webhook_url"`
}
type Integration struct {
ID int64
Name string
URL string
Type string
IsServicePointEnabled bool
ServicePointCarriers []string
IsWebhooksEnabled bool
WebhookURL string
UpdatedAt time.Time
}
func (i *IntegrationParams) GetPayload() interface{} {
return IntegrationRequest{
ShopName: i.Name,
ShopURL: i.URL,
ServicePointEnabled: false,
ServicePointCarriers: []string{},
WebhookActive: i.IsWebhooksEnabled,
WebhookURL: i.WebhookURL,
}
}
//Get formatted response
func (i *IntegrationListResponseContainer) GetResponse() interface{} {
var integrations []*Integration
for _, r := range *i {
integration := Integration{
ID: r.ID,
Name: r.ShopName,
URL: r.ShopURL,
Type: r.System,
IsServicePointEnabled: r.ServicePointEnabled,
ServicePointCarriers: r.ServicePointCarriers,
IsWebhooksEnabled: r.ServicePointEnabled,
WebhookURL: r.WebhookURL,
UpdatedAt: r.LastUpdatedAt,
}
integrations = append(integrations, &integration)
}
return integrations
}
//Get formatted response
func (r *IntegrationResponseContainer) GetResponse() interface{} {
integration := &Integration{
ID: r.ID,
Name: r.ShopName,
URL: r.ShopURL,
Type: r.System,
IsServicePointEnabled: r.ServicePointEnabled,
ServicePointCarriers: r.ServicePointCarriers,
IsWebhooksEnabled: r.ServicePointEnabled,
WebhookURL: r.WebhookURL,
UpdatedAt: r.LastUpdatedAt,
}
return integration
}
//Set the response
func (r *IntegrationResponseContainer) SetResponse(body []byte) error {
err := json.Unmarshal(body, &r)
if err != nil {
return err
}
return nil
}
//Set the response
func (i *IntegrationListResponseContainer) SetResponse(body []byte) error {
err := json.Unmarshal(body, &i)
if err != nil {
return err
}
return nil
}