-
Notifications
You must be signed in to change notification settings - Fork 3
/
datamodel.go
326 lines (283 loc) · 12.8 KB
/
datamodel.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package closeio
import (
"encoding/json"
"fmt"
"strings"
"time"
)
type Contact struct {
LeadID string `json:"lead_id,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
DateCreated *time.Time `json:"date_created,omitempty"`
DateUpdated *time.Time `json:"date_updated,omitempty"`
Emails []Email `json:"emails,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Phones []Phone `json:"phones,omitempty"`
Title string `json:"title,omitempty"`
}
type Address struct {
City string `json:"city,omitempty"`
State string `json:"state,omitempty"`
Country string `json:"country,omitempty"`
Zipcode string `json:"zipcode,omitempty"`
Address string `json:"address_1,omitempty"`
}
type Email struct {
Email string `json:"email,omitempty"`
Type string `json:"type,omitempty"`
}
type Phone struct {
Phone string `json:"phone,omitempty"`
PhoneFormatted string `json:"phone_formatted,omitempty"`
Type string `json:"type,omitempty"`
}
type Activity struct {
Type string `json:"_type,omitempty"`
ID string `json:"id,omitempty"`
//Email
Attachments []Attachment `json:"attachments,omitempty"`
Bcc []string `json:"bcc,omitempty"`
BodyHtml string `json:"body_html,omitempty"`
BodyHtmlQuoted []HtmlQuoted `json:"body_html_quoted,omitempty"`
BodyPreview string `json:"body_preview,omitempty"`
BodyText string `json:"body_text,omitempty"`
BodyTextQuoted []TextQuoted `json:"body_text_quoted,omitempty"`
Cc []string `json:"cc,omitempty"`
ContactID string `json:"contact_id,omitempty"`
DateScheduled *time.Time `json:"date_scheduled,omitempty"`
DateSent *time.Time `json:"date_sent,omitempty"`
EmailAccountID string `json:"email_account_id,omitempty"`
Enveloppe Enveloppe `json:"enveloppe,omitempty"`
InReplyToID string `json:"in_reply_to_id,omitempty"`
MessageIDs []string `json:"message_ids,omitempty"`
NeedSmtpCredentials bool `json:"need_smtp_credentials,omitempty"`
Opens []Opens `json:"opens,omitempty"`
OpensSummary string `json:"opens_summary,omitempty"`
References []string `json:"references,omitempty"`
SendAttempts []SendAttempt `json:"send_attempts,omitempty"`
Sender string `json:"sender,omitempty"`
Status string `json:"status,omitempty"`
Subject string `json:"subject,omitempty"`
TemplateID string `json:"template_id,omitempty"`
TemplateName string `json:"template_name,omitempty"`
ThreadID string `json:"thread_id,omitempty"`
To []string `json:"to,omitempty"`
//LeadStatusChange
NewStatusID string `json:"new_status_id,omitempty"`
NewStatus string `json:"new_status_label,omitempty"`
OldStatusID string `json:"old_status_id,omitempty"`
OldStatus string `json:"old_status_label,omitempty"`
//OpportunityStatusChange
NewStatusType string `json:"new_status_type,omitempty"`
OldStatusType string `json:"old_status_type,omitempty"`
OpportunityConfidence int `json:"opportunity_confidence,omitempty"`
OpportunityDateWon *time.Time `json:"opportunity_date_won,omitempty"`
OpportunityID string `json:"opportunity_id,omitempty"`
OpportunityValue float64 `json:"opportunity_value,omitempty"`
OpportunityValueCurrency string `json:"opportunity_value_currency,omitempty"`
OpportunityValueFormatted string `json:"opportunity_value_formatted,omitempty"`
OpportunityValuePeriod string `json:"opportunity_value_period,omitempty"`
//Call
Direction string `json:"direction,omitempty"`
CallDuration int64 `json:"duration,omitempty"`
LocalPhone string `json:"local_phone,omitempty"`
Note string `json:"note,omitempty"`
Phone string `json:"phone,omitempty"`
RecordingUrl string `json:"recording_url,omitempty"`
RemotePhone string `json:"remote_phone,omitempty"`
Source string `json:"source,omitempty"`
TransferredFrom string `json:"transferred_from,omitempty"`
TransferredTo string `json:"transferred_to,omitempty"`
VoiceMailDuration int64 `json:"voicemail_duration,omitempty"`
VoiceMailUrl string `json:"voicemail_url,omitempty"`
//TaskCompleted
TaskAssignedTo string `json:"task_assigned_to,omitempty"`
TaskAssignedToName string `json:"task_assigned_to_name,omitempty"`
TaskID string `json:"task_id,omitempty"`
TaskText string `json:"task_text,omitempty"`
//Created
ImportID string `json:"import_id,omitempty"`
//General
LeadID string `json:"lead_id,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
CreatedByName string `json:"created_by_name,omitempty"`
DateCreated *time.Time `json:"date_created,omitempty"`
DateUpdated *time.Time `json:"date_updated,omitempty"`
FollowUpDate *time.Time `json:"followup_date,omitempty"`
OrganizationID string `json:"organization_id,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
UpdatedByName string `json:"updated_by_name,omitempty"`
UserID string `json:"user_id,omitempty"`
UserName string `json:"user_name,omitempty"`
Users []string `json:"users,omitempty"`
}
//structs for emails
type Opens struct {
IpAddress string `json:"ip_address,omitempty"`
OpenedAt *time.Time `json:"opened_at,omitempty"`
OpenedBy string `json:"opened_by,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
}
type SendAttempt struct {
Date *time.Time `json:"date,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
ErrorClass string `json:"error_class,omitempty"`
}
type Enveloppe struct {
Bcc []string `json:"bcc,omitempty"`
Cc []string `json:"cc,omitempty"`
Date *time.Time `json:"date,omitempty"`
From []From `json:"from,omitempty"`
InReplyTo string `json:"in_reply_to,omitempty"`
IsAutoReply bool `json:"is_autoreply,omitempty"`
MessageID string `json:"message_id,omitempty"`
ReplyTo []string `json:"reply_to,omitempty"`
Sender []From `json:"sender,omitempty"`
Subject string `json:"subject,omitempty"`
To []From `json:"to,omitempty"`
}
type From struct {
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
}
type HtmlQuoted struct {
Expand bool `json:"expand,omitempty"`
Html string `json:"html,omitempty"`
}
type TextQuoted struct {
Expand bool `json:"expand,omitempty"`
Text string `json:"text,omitempty"`
}
type Attachment struct {
ContentID string `json:"content_id,omitempty"`
ContentType string `json:"content_type,omitempty"`
FileName string `json:"filename,omitempty"`
Size int `json:"size,omitempty"`
URL string `json:"url,omitempty"`
}
func JSONToLead(ser []byte) (*Lead, error) {
var lead Lead
err := json.Unmarshal(ser, &lead)
if err != nil {
return nil, err
}
lead.Custom = make(map[string]interface{})
var keyValues map[string]interface{}
err = json.Unmarshal(ser, &keyValues)
if err != nil {
return nil, err
}
for key, value := range keyValues {
if strings.HasPrefix(key, "custom.") {
lead.Custom[strings.Replace(key, "custom.", "", 1)] = value
}
}
return &lead, nil
}
func LeadToJSON(lead Lead) ([]byte, error) {
bytes, _ := json.Marshal(lead)
var dynamicFields map[string]interface{}
json.Unmarshal(bytes, &dynamicFields)
for key, value := range lead.Custom {
dynamicFields[fmt.Sprintf("custom.%s", key)] = value
}
return json.Marshal(dynamicFields)
}
type Lead struct {
Addresses []Address `json:"addresses,omitempty"`
Contacts []Contact `json:"contacts,omitempty"`
CreationDate *time.Time `json:"date_created,omitempty"`
Custom map[string]interface{} `json:"-"`
Description string `json:"description,omitempty"`
DisplayName string `json:"display_name,omitempty"`
HtmlURL string `json:"html_url,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
OrganizationID string `json:"organization_id,omitempty"`
Opportunities []Opportunity `json:"opportunities,omitempty"`
StatusID string `json:"status_id,omitempty"`
StatusLabel string `json:"status_label,omitempty"`
Tasks []Task `json:"tasks,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
UpdatedByName string `json:"updated_by_name,omitempty"`
URL string `json:"url,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
CreatedName string `json:"created_by_name,omitempty"`
Activities []Activity `json:"activities,omitempty`
}
type Task struct {
Type string `json:"_type"`
AssignedTo string `json:"assigned_to,omitempty"`
AssignedToName string `json:"assigned_to_name,omitempty"`
ContactID string `json:"contact_id,omitempty"`
ContactName string `json:"contact_name,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
CreatedName string `json:"created_by_name,omitempty"`
Date string `json:"date,omitempty"`
DateCreated *time.Time `json:"date_created,omitempty"`
DateUpdated *time.Time `json:"date_updated,omitempty"`
ID string `json:"id,omitempty"`
IsComplete *bool `json:"is_complete,omitempty"`
IsDateLess bool `json:"is_dateless,omitempty"`
LeadID string `json:"lead_id,omitempty"`
LeadName string `json:"lead_name,omitempty"`
ObjectID string `json:"object_id,omitempty"`
ObjectType string `json:"object_type,omitempty"`
OrganizationID string `json:"organization_id,omitempty"`
Text string `json:"text,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
UpdatedByName string `json:"updated_by_name,omitempty"`
View string `json:"view,omitempty"`
}
type Opportunity struct {
Confidence int `json:"confidence,omitempty"`
ContactID string `json:"contact_id,omitempty"`
ContactName string `json:"contact_name,omitempty"`
CreationDate *time.Time `json:"date_created,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
CreatedName string `json:"created_by_name,omitempty"`
DateCreated *time.Time `json:"date_created,omitempty"`
DateLost *time.Time `json:"date_lost,omitempty"`
DateUpdated *time.Time `json:"date_updated,omitempty"`
DateWon string `json:"date_won,omitempty"` //not classic format
ID string `json:"id,omitempty"`
LeadID string `json:"lead_id,omitempty"`
LeadName string `json:"lead_name,omitempty"`
Note string `json:"note,omitempty"`
OrganizationID string `json:"organization_id,omitempty"`
StatusID string `json:"status_id,omitempty"`
StatusLabel string `json:"status_label,omitempty"`
StatusType string `json:"status_type,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
UpdatedByName string `json:"updated_by_name,omitempty"`
UserID string `json:"user_id,omitempty"`
UserName string `json:"user_name,omitempty"`
Value float64 `json:"value,omitempty"`
ValueCurrency string `json:"value_currency,omitempty"`
ValueFormatted string `json:"value_formatted,omitempty"`
ValuePeriod string `json:"value_period,omitempty"`
}
type Status struct {
ID string `json:"id,omitempty"`
Label string `json:"label,omitempty"`
Type string `json:"type,omitempty"`
}
type User struct {
ID string `json:"id,omitempty"`
Email string `json:"email,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
Image string `json:"image,omitempty"`
Organizations []string `json:"organizations,omitempty"`
DateCreated time.Time `json:"date_created,omitempty"`
DateUpdated time.Time `json:"date_updated,omitempty"`
}
type Sequence struct {
SequenceID string `json:"sequence_id,omitempty"`
ContactID string `json:"contact_id,omitempty"`
ContactEmail string `json:"contact_email,omitempty"`
SenderAccountID string `json:"sender_account_id,omitempty"`
SenderName string `json:"sender_name,omitempty"`
SenderEmail string `json:"sender_email,omitempty"`
}