/
api.go
84 lines (73 loc) · 2.77 KB
/
api.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
// Package deals covers the Deals API which has been exposed to allow for easy integration with the HubSpot CRM objects.
package deals
import "encoding/json"
// Associations is a struct generated from the HubSpot API
type Associations struct {
AssociatedVids []int64 `json:"associatedVids"`
AssociatedCompanyIDS []interface{} `json:"associatedCompanyIds"`
AssociatedDealIDS []interface{} `json:"associatedDealIds"`
AssociatedTicketIDS []interface{} `json:"associatedTicketIds"`
}
// Deal is a struct generated from the HubSpot API
type Deal struct {
PortalID int64 `json:"portalId"`
DealID int64 `json:"dealId"`
IsDeleted bool `json:"isDeleted"`
Associations Associations `json:"associations"`
Properties map[string]Property `json:"properties"`
Imports []interface{} `json:"imports"`
StateChanges []interface{} `json:"stateChanges"`
}
// Properties is a struct generated from the HubSpot API
type Properties struct {
Properties []Property `json:"properties"`
}
// Property is a struct generated from the HubSpot API
type Property struct {
Name string `json:"name,omitempty"`
Value string `json:"value"`
Timestamp int64 `json:"timestamp,omitempty"`
Source string `json:"source,omitempty"`
SourceID string `json:"sourceId,omitempty"`
Versions []Version `json:"versions,omitempty"`
}
// RecentDeals is a struct generated from the HubSpot API
type RecentDeals struct {
Results []Result `json:"results"`
HasMore bool `json:"hasMore"`
Offset int64 `json:"offset"`
Total int64 `json:"total"`
}
// Result is a struct generated from the HubSpot API
type Result struct {
PortalID int64 `json:"portalId"`
DealID int64 `json:"dealId"`
IsDeleted bool `json:"isDeleted"`
Associations Associations `json:"associations"`
Properties map[string]Property `json:"properties"`
Imports []interface{} `json:"imports"`
StateChanges []interface{} `json:"stateChanges"`
}
// Version is a struct generated from the HubSpot API
type Version struct {
Name string `json:"name"`
Value string `json:"value"`
Timestamp int64 `json:"timestamp"`
SourceID string `json:"sourceId,omitempty"`
Source string `json:"source"`
SourceVid []interface{} `json:"sourceVid"`
}
// Marshal takes an Properties struct and transforms it into a byte array
func (r *Properties) Marshal() ([]byte, error) {
return json.Marshal(r)
}
func unmarshalDeal(data []byte) (Deal, error) {
var r Deal
err := json.Unmarshal(data, &r)
return r, err
}
func unmarshalRecentDeals(data []byte) (RecentDeals, error) {
var r RecentDeals
err := json.Unmarshal(data, &r)
return r, err
}