-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmailchimp.go
1136 lines (1011 loc) · 31 KB
/
mailchimp.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Package mailchimp implements version 1.3 of Mailchimp's API
Routines are implemented as methods on type API, which should
be created with the New function
chimp := mailchimp.New("apikey123apikey123-us1")
The comment for each method contains a link to the corresonding
Mailchimp routine documentation in lieu of a description of parameters
used with each method
TODO: implement timeouts and corresponding error
*/
package mailchimp
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"strconv"
"time"
)
type API struct {
Key string
endpoint string
}
var datacenter = regexp.MustCompile("[a-z]+[0-9]+$")
func New(apikey string, https ...bool) (*API, error) {
u := url.URL{}
if https[0] {
u.Scheme = "https"
} else {
u.Scheme = "http"
}
u.Host = fmt.Sprintf("%s.api.mailchimp.com", datacenter.FindString(apikey))
u.Path = "/1.3/"
return &API{apikey, u.String() + "?method="}, nil
}
func run(a *API, method string, parameters map[string]interface{}) ([]byte, error) {
if parameters == nil {
parameters = make(map[string]interface{})
}
parameters["apikey"] = a.Key
b, err := json.Marshal(parameters)
if err != nil {
return nil, err
}
//os.Stdout.Write([]byte(b))
resp, err := http.Post(a.endpoint+method, "application/json", bytes.NewBuffer(b))
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
os.Stdout.Write(body)
if err = errorCheck(body); err != nil {
return nil, err
}
return body, nil
}
type ChimpError struct {
Err string `json:"error"`
Code int
}
func (e ChimpError) Error() string {
return fmt.Sprintf("%v: %v", e.Code, e.Err)
}
func errorCheck(body []byte) error {
var e ChimpError
json.Unmarshal(body, &e)
if e.Err != "" || e.Code != 0 {
return e
}
return nil
}
//ChimpTime is a named struct with a single anonymous field of type time.Time
//and inherits all its methods except UnmarshalJSON, which is overridden since
//Mailchimp does not adhere to the RFC3339 format
type ChimpTime struct {
time.Time
}
func (t *ChimpTime) UnmarshalJSON(data []byte) (err error) {
s := string(data)
l := len(s)
switch {
case l == 12:
t.Time, err = time.Parse(`"2006-01-02"`, s)
case l == 21:
t.Time, err = time.Parse(`"2006-01-02 15:04:05"`, s)
case l == 9:
t.Time, err = time.Parse(`"2006-01"`, s)
}
return
}
//format string for time.Format
const ChimpTimeFormat = "2006-01-02 15:04:05"
func chimpTime(t interface{}) interface{} {
switch ti := t.(type) {
case time.Time:
return ti.Format(ChimpTimeFormat)
case string:
return ti
}
return t
}
func parseInt(body []byte, err error) (int, error) {
i, err := strconv.ParseInt(string(body), 10, 0)
if err != nil {
return 0, err
}
return int(i), nil
}
func parseString(body []byte, err error) (string, error) {
if err != nil {
return "", err
}
return strconv.Unquote(string(body))
}
func parseBoolean(body []byte, err error) (bool, error) {
if err != nil {
return false, err
}
return strconv.ParseBool(string(body))
}
type alterJsoner interface {
alterJson(b []byte) []byte
}
func parseJson(a *API, method string, parameters map[string]interface{}, retVal interface{}) error {
body, err := run(a, method, parameters)
if err != nil {
return err
}
switch r := retVal.(type) {
case alterJsoner:
blob := r.alterJson(body)
os.Stdout.Write(blob)
json.Unmarshal(r.alterJson(body), retVal)
default:
json.Unmarshal(body, retVal)
}
return nil
}
type CampaignContentResult struct {
Html string
Text string
}
func (a *API) CampaignContent(parameters map[string]interface{}) (retVal *CampaignContentResult, err error) {
retVal = new(CampaignContentResult)
err = parseJson(a, "campaignContent", parameters, retVal)
return
}
func (a *API) CampaignCreate(parameters map[string]interface{}) (string, error) {
return parseString(run(a, "campaignCreate", parameters))
}
func (a *API) CampaignDelete(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignDelete", parameters))
}
//CampaignEcommOrderAdd method has not been tested with real return data
func (a *API) CampaignEcommOrderAdd(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignEcommOrderAdd", parameters))
}
func (a *API) CampaignPause(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignPause", parameters))
}
func (a *API) CampaignReplicate(parameters map[string]interface{}) (string, error) {
return parseString(run(a, "campaignReplicate", parameters))
}
func (a *API) CampaignResume(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignResume", parameters))
}
func (a *API) CampaignSchedule(parameters map[string]interface{}) (bool, error) {
//convert times to Mailchimp's format
if parameters == nil {
return false, errors.New("missing required parameters")
}
parameters["schedule_time"] = chimpTime(parameters["schedule_time"])
parameters["schedule_time_b"] = chimpTime(parameters["schedule_time_b"])
return parseBoolean(run(a, "campaignSchedule", parameters))
}
func (a *API) CampaignSegmentTest(parameters map[string]interface{}) (int, error) {
return parseInt(run(a, "campaignSegmentTest", parameters))
}
func (a *API) CampaignSendNow(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignSendNow", parameters))
}
func (a *API) CampaignSendTest(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignSendTest", parameters))
}
type CampaignShareReportResult struct {
Title string
Url string
Secure_url string
Password string
}
func (a *API) CampaignShareReport(parameters map[string]interface{}) (retVal *CampaignShareReportResult, err error) {
retVal = new(CampaignShareReportResult)
err = parseJson(a, "campaignShareReport", parameters, retVal)
return
}
//CampaignTemplateContent method returns a map[string]interface{} of all content sections for the campaign
//Section names are dependent upon the template used and thus can't be documented
//TODO: If all values in the resulting map are string, change return type to map[string]string to obviate type assertions
func (a *API) CampaignTemplateContent(parameters map[string]interface{}) (retVal map[string]interface{}, err error) {
err = parseJson(a, "campaignTemplateContent", parameters, &retVal)
return
}
func (a *API) CampaignUnschedule(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignUnschedule", parameters))
}
func (a *API) CampaignUpdate(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "campaignUpdate", parameters))
}
type CampaignsResult struct {
Total int
Data []CampaignsResultData
}
type CampaignsResultData struct {
Id string
Web_id int
List_id string
Folder_id int
Template_id int
Content_type string
Title string
Type string
Create_time string
Send_time string
Emails_sent int
Status string
From_name string
From_email string
Subject string
To_name string
Archive_url string
Inline_css bool
Analytics string
Analytics_tag string
Authenticate bool
Ecomm360 bool
Auto_tweet bool
Auto_fb_post string
Auto_footer bool
Timewarp bool
Timewarp_schedule string
Tracking CampaignsResultDataTracking
Segment_text string
Segment_opts CampaignsResultDataSegment_opts
Type_opts map[string]interface{}
}
type CampaignsResultDataTracking struct {
Html_clicks bool
Text_clicks bool
Opens bool
}
type CampaignsResultDataSegment_opts struct {
Match string
Conditions []map[string]interface{}
}
func (a *API) Campaigns(parameters map[string]interface{}) (retVal *CampaignsResult, err error) {
retVal = new(CampaignsResult)
err = parseJson(a, "campaigns", parameters, retVal)
return
}
type CampaignAbuseReportsResultDataItem struct {
Date string
Email string
Type string
}
type CampaignAbuseReportsResult struct {
Total int
Data []CampaignAbuseReportsResultDataItem
}
func (a *API) CampaignAbuseReports(parameters map[string]interface{}) (retVal *CampaignAbuseReportsResult, err error) {
retVal = new(CampaignAbuseReportsResult)
err = parseJson(a, "campaignAbuseReports", parameters, retVal)
return
}
type CampaignAdviceResultItem struct {
Msg string
Type string
}
func (a *API) CampaignAdvice(parameters map[string]interface{}) (retVal []CampaignAdviceResultItem, err error) {
err = parseJson(a, "campaignAdvice", parameters, &retVal)
return
}
type CampaignAnalyticsResultGoals struct {
Name string
Conversions int
}
type CampaignAnalyticsResult struct {
Visits int
Pages int
New_visits int
Bounces int
Time_on_site float64
Goal_conversions int
Goal_value float64
Revenue float64
Transactions int
Ecomm_conversions int
Goals CampaignAnalyticsResultGoals
}
func (a *API) CampaignAnalytics(parameters map[string]interface{}) (retVal *CampaignAnalyticsResult, err error) {
retVal = new(CampaignAnalyticsResult)
err = parseJson(a, "campaignAnalytics", parameters, retVal)
return
}
type CampaignBounceMessageResult struct {
Date string
Email string
Message string
}
func (a *API) CampaignBounceMessage(parameters map[string]interface{}) (retVal *CampaignBounceMessageResult, err error) {
retVal = new(CampaignBounceMessageResult)
err = parseJson(a, "campaignBounceMessage", parameters, retVal)
return
}
type CampaignBounceMessagesResult struct {
Total int
Data []CampaignBounceMessageResult
}
func (a *API) CampaignBounceMessages(parameters map[string]interface{}) (retVal *CampaignBounceMessagesResult, err error) {
retVal = new(CampaignBounceMessagesResult)
err = parseJson(a, "campaignBounceMessages", parameters, retVal)
return
}
//CampaignClickStats method returns a map where the keys are urls extracted from the campaign
type CampaignClickStatsResultItem struct {
Clicks int
Unique int
}
func (a *API) CampaignClickStats(parameters map[string]interface{}) (retVal map[string]CampaignClickStatsResultItem, err error) {
err = parseJson(a, "campaignClickStats", parameters, &retVal)
return
}
//CampaignEcommOrders method has not been tested with real response data
//The json returned by this routine might not unmarshal correctly into the return struct for this method
type CampaignEcommOrdersResultDataItemLinesItem struct {
Line_num int
Product_id int
Product_name string
Product_sku string
Product_category_id int
Product_category_name int
Qty int
Cost float64
}
type CampaignEcommOrdersResultDataItem struct {
Store_id string
Store_name string
Order_id string
Email string
Order_total float64
Tax_total float64
Ship_total float64
Order_date string
Lines []CampaignEcommOrdersResultDataItemLinesItem
}
type CampaignEcommOrdersResult struct {
Total int
Data []CampaignEcommOrdersResultDataItem
}
func (a *API) CampaignEcommOrders(parameters map[string]interface{}) (retVal *CampaignEcommOrdersResult, err error) {
retVal = new(CampaignEcommOrdersResult)
err = parseJson(a, "campaignEcommOrders", parameters, retVal)
return
}
//Mailchimp's documentation for CampaignEepUrlStats is incorrect and I don't have any examples of non-empty JSON
//return values from this routine, so there is no way to design accurate types to unmarshal responses into.
//Therefore, this method returns an interface{} and users will have to use type assertion or type
//switching to unpack the response. The custom types for this method are not used yet.
type CampaignEepUrlStatsResultTwitterClicksLocations struct {
Country string
Region string
Total int
}
type CampaignEepUrlStatsResultTwitterClicksReferrers struct {
Referrer string
Clicks int
First_click string
Last_click string
}
type CampaignEepUrlStatsResultTwitterClicks struct {
Clicks int
First_click string
Last_click string
Locations CampaignEepUrlStatsResultTwitterClicksLocations
Referrers []CampaignEepUrlStatsResultTwitterClicksReferrers
}
type CampaignEepUrlStatsResultTwitterStatuses struct {
Status string
Screen_name string
Status_id string
Datetime string
Is_retweet bool
}
type CampaignEepUrlStatsResultTwitter struct {
Tweets int
First_tweet string
Last_tweet string
Retweets int
First_retweet string
Last_retweet string
Statuses CampaignEepUrlStatsResultTwitterStatuses
Clicks CampaignEepUrlStatsResultTwitterClicks
}
type CampaignEepUrlStatsResult struct {
Twitter CampaignEepUrlStatsResultTwitter
}
func (a *API) CampaignEepUrlStats(parameters map[string]interface{}) (retVal interface{}, err error) {
err = parseJson(a, "campaignEepUrlStats", parameters, &retVal)
return
}
type CampaignEmailDomainPerformanceResultItem struct {
Domain string
Total_sent int
Email int
Bounces int
Opens int
Clicks int
Unsubs int
Delivered int
Emails_pct int
Opens_pct int
Clicks_pct int
Unsubs_pct int
}
func (a *API) CampaignEmailDomainPerformance(parameters map[string]interface{}) (retVal []CampaignEmailDomainPerformanceResultItem, err error) {
err = parseJson(a, "campaignEmailDomainPerformance", parameters, &retVal)
return
}
type CampaignGeoOpensResultItem struct {
Code string
Name string
Opens int
Region_detail bool
}
func (a *API) CampaignGeoOpens(parameters map[string]interface{}) (retVal []CampaignGeoOpensResultItem, err error) {
err = parseJson(a, "campaignGeoOpens", parameters, &retVal)
return
}
type CampaignGeoOpensForCountryReturnItem struct {
Code string
Name string
Opens int
}
func (a *API) CampaignGeoOpensForCountry(parameters map[string]interface{}) (retVal []CampaignGeoOpensForCountryReturnItem, err error) {
err = parseJson(a, "campaignGeoOpensForCountry", parameters, &retVal)
return
}
type CampaignMembersResult struct {
Total int
Data []struct {
Email string
Status string
Absplit_group string
Tz_group string
}
}
func (a *API) CampaignMembers(parameters map[string]interface{}) (retVal *CampaignMembersResult, err error) {
retVal = new(CampaignMembersResult)
err = parseJson(a, "campaignMembers", parameters, retVal)
return
}
//CampaignStatsResult method has only been tested with limited return data
//The nested structs in the return struct in particular may be incorrect
type CampaignStatsResult struct {
Syntax_errors int
Hard_bounces int
Soft_bounces int
Unsubscribes int
Abuse_reports int
Forwards int
Forwards_opens int
Opens int
Last_open string
Unique_opens int
Clicks int
Unique_clicks int
Last_click string
Users_who_clicked int
Emails_sent int
Unique_likes int
Recipient_likes int
Facebook_likes int
Absplit struct {
Bounces_a int
Bounces_b int
Forwards_a int
Forwards_b int
Abuse_reports_a int
Abuse_reports_b int
Unsubs_a int
Unsubs_b int
Recipients_click_a int
Recipients_click_b int
Forwards_opens_a int
Forwards_opens_b int
}
Timewarp map[string]struct {
Opens int
Last_open string
Unique_opens int
Clicks int
Last_click string
Bounces int
Total int
Sent int
}
Timeseries []struct {
Timestamp string
Emails_sent int
Unique_opens int
Recipients_click int
}
}
func (a *API) CampaignStats(parameters map[string]interface{}) (retVal *CampaignStatsResult, err error) {
retVal = new(CampaignStatsResult)
err = parseJson(a, "campaignStats", parameters, retVal)
return
}
type CampaignUnsubscribesResult struct {
Total int
Data []struct {
Email string
Reason string
Reason_text string
}
}
func (a *API) CampaignUnsubscribes(parameters map[string]interface{}) (retVal *CampaignUnsubscribesResult, err error) {
retVal = new(CampaignUnsubscribesResult)
err = parseJson(a, "campaignUnsubscribes", parameters, retVal)
return
}
type CampaignClickDetailAIMResult struct {
Total int
Data []struct {
Email string
Clicks int
}
}
func (a *API) CampaignClickDetailAIM(parameters map[string]interface{}) (retVal *CampaignClickDetailAIMResult, err error) {
retVal = new(CampaignClickDetailAIMResult)
err = parseJson(a, "campaignClickDetailAIM", parameters, retVal)
return
}
type CampaignEmailStatsAIMResult struct {
Success int
Error int
Data []struct {
Action string
Timestamp string
Url string
}
}
func (a *API) CampaignEmailStatsAIM(parameters map[string]interface{}) (retVal *CampaignEmailStatsAIMResult, err error) {
retVal = new(CampaignEmailStatsAIMResult)
err = parseJson(a, "campaignEmailStatsAIM", parameters, retVal)
return
}
type CampaignEmailStatsAIMAllResult struct {
Total int
Data map[string][]struct {
Action string
Timestamp string
Url string
}
}
func (a *API) CampaignEmailStatsAIMAll(parameters map[string]interface{}) (retVal *CampaignEmailStatsAIMAllResult, err error) {
retVal = new(CampaignEmailStatsAIMAllResult)
err = parseJson(a, "campaignEmailStatsAIMAll", parameters, retVal)
return
}
type CampaignNotOpenedAIMResult struct {
Total int
Data []string
}
func (a *API) CampaignNotOpenedAIM(parameters map[string]interface{}) (retVal *CampaignNotOpenedAIMResult, err error) {
retVal = new(CampaignNotOpenedAIMResult)
err = parseJson(a, "campaignNotOpenedAIM", parameters, retVal)
return
}
type CampaignOpenedAIMResult struct {
Total int
Data []struct {
Email string
Open_count int
}
}
func (a *API) CampaignOpenedAIM(parameters map[string]interface{}) (retVal *CampaignOpenedAIMResult, err error) {
retVal = new(CampaignOpenedAIMResult)
err = parseJson(a, "campaignOpenedAIM", parameters, retVal)
return
}
func (a *API) EcommOrderAdd(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "ecommOrderAdd", parameters))
}
func (a *API) EcommOrderDel(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "ecommOrderDelete", parameters))
}
//EcommOrdersResult tested with data; result unmarshals correctly into this struct
type EcommOrdersResult struct {
Total int
Data []struct {
Store_id string
Store_name string
Order_id string
Email string
Order_total float64
Tax_total float64
Ship_total float64
Order_date string
Lines []struct {
Line_num int
Product_id int
Product_name string
Product_sku string
Product_category_id int
Product_category_name string
Qty int
Cost float64
}
}
}
func (a *API) EcommOrders(parameters map[string]interface{}) (retVal *EcommOrdersResult, err error) {
retVal = new(EcommOrdersResult)
err = parseJson(a, "ecommOrders", parameters, retVal)
return
}
func (a *API) FolderAdd(parameters map[string]interface{}) (int, error) {
return parseInt(run(a, "folderAdd", parameters))
}
func (a *API) FolderDel(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "folderDel", parameters))
}
func (a *API) FolderUpdate(parameters map[string]interface{}) (bool, error) {
return parseBoolean(run(a, "folderUpdate", parameters))
}
type FoldersResultItem struct {
Folder_id int
Name string
Date_created string
Type string
}
func (a *API) Folders(parameters map[string]interface{}) (retVal []FoldersResultItem, err error) {
err = parseJson(a, "folders", parameters, &retVal)
return
}
type GmonkeyActivityResultItem struct {
Action string
Timestamp string
Url string
Unique_id string
Title string
List_name string
Email string
Fname string
Lname string
Member_rating int
Member_since string
Geo struct {
Latitude string
Longitude string
Gmtoff string
Dstoff string
Timezone string
Cc string
Region string
}
}
func (a *API) GmonkeyActivity(parameters map[string]interface{}) (retVal []GmonkeyActivityResultItem, err error) {
err = parseJson(a, "gmonkeyActivity", parameters, &retVal)
return
}
type GmonkeyAddResult struct {
Success int
Errors int
Data []struct {
Email_address string
Error string
}
}
func (a *API) GmonkeyAdd(parameters map[string]interface{}) (retVal *GmonkeyAddResult, err error) {
retVal = new(GmonkeyAddResult)
err = parseJson(a, "gmonkeyAdd", parameters, retVal)
return
}
type GmonkeyDelResult struct {
Success int
Errors int
Data []struct {
Email_address string
Error string
}
}
func (a *API) GmonkeyDel(parameters map[string]interface{}) (retVal *GmonkeyDelResult, err error) {
retVal = new(GmonkeyDelResult)
err = parseJson(a, "gmonkeyDel", parameters, retVal)
return
}
type GmonkeyMembersItem struct {
List_id string
List_name string
Email string
Fname string
Lname string
Member_rating int
Member_since int
}
func (a *API) GmonkeyMembers(parameters map[string]interface{}) (retVal []GmonkeyMembersItem, err error) {
err = parseJson(a, "gmonkeyMembers", parameters, &retVal)
return
}
func (a *API) CampaignsForEmail(parameters map[string]interface{}) (retVal []string, err error) {
err = parseJson(a, "campaignsForEmail", parameters, &retVal)
return
}
type ChimpChatterResultItem struct {
Message string
Type string
Url string
List_id string
Campaign_id string
Update_time string
}
func (a *API) ChimpChatter(parameters map[string]interface{}) (retVal []ChimpChatterResultItem, err error) {
err = parseJson(a, "chimpChatter", parameters, &retVal)
return
}
func (a *API) GenerateText(parameters map[string]interface{}) (string, error) {
return parseString(run(a, "generateText", parameters))
}
type GetAccountDetailsResult struct {
Username string
User_id string
Is_trial bool
Is_approved bool
Has_activated bool
Timezone string
Plan_type string
Plan_low int
Plan_high int
Plan_start_date string
Emails_left int
Pending_monthly bool
First_payment string
Last_payment string
Times_logged_in int
Last_login string
Affiliate_link string
Contact struct {
Fname string
Lname string
Email string
Company string
Address1 string
Address2 string
City string
State string
Zip string
Country string
Url string
Phone string
Fax string
}
Modules []struct {
Name string
Added string
}
Orders []struct {
Order_id int
Type string
Amount float64
Date string
Credits_used float64
}
Rewards struct {
Referrals_this_month int
Notify_on string
Notify_email string
Credits struct {
This_month int
Total_earned int
Remaining int
}
Inspections struct {
This_month int
Total_earned int
Remaining int
}
Referrals []struct {
Name string
Email string
Signup_date string
Type string
}
Applied []struct {
Value int
Date string
Order_id int
Order_desc string
}
}
}
func (a *API) GetAccountDetails(parameters map[string]interface{}) (retVal *GetAccountDetailsResult, err error) {
retVal = new(GetAccountDetailsResult)
err = parseJson(a, "getAccountDetails", parameters, retVal)
return
}
type GetVerifiedDomainsResultItem struct {
Domain string
Status string
Emails string
}
func (a *API) GetVerifiedDomains(parameters map[string]interface{}) (retVal []GetVerifiedDomainsResultItem, err error) {
err = parseJson(a, "getVerifiedDomains", parameters, &retVal)
return
}
func (a *API) InlineCss(parameters map[string]interface{}) (string, error) {
return parseString(run(a, "inlineCss", parameters))
}
func (a *API) ListsForEmail(parameters map[string]interface{}) (retVal []string, err error) {
err = parseJson(a, "listsForEmail", parameters, &retVal)
return
}
func (a *API) Ping() (string, error) {
return parseString(run(a, "ping", nil))
}
//ListAbuseReportsResponse is the type for values returned from the ListAbuseReports method
type ListAbuseReportsResponse struct {
Total int
Data []struct {
Date ChimpTime
Email string
Campaign_id string
Type string
}
}
//ListAbuseReports gets all email addresses that complained about a given campaign
func (a *API) ListAbuseReports(parameters map[string]interface{}) (retVal *ListAbuseReportsResponse, err error) {
retVal = new(ListAbuseReportsResponse)
err = parseJson(a, "listAbuseReports", parameters, retVal)
return
}
//ListActivityElement is the type of elements in the slice returned from the ListActivity method
type ListActivityElement struct {
User_id int //not documented in the api docs; not sure what it means
Day ChimpTime
Emails_sent int
Unique_opens int
Recipient_clicks int
Hard_bounce int
Soft_bounce int
Abuse_reports int
Subs int
Unsubs int
Other_adds int
Other_removes int
}
//ListActivity accesses up to the previous 180 days of daily detailed aggregated
//activity stats for a given list
func (a *API) ListActivity(parameters map[string]interface{}) (retVal []ListActivityElement, err error) {
err = parseJson(a, "listActivity", parameters, &retVal)
return
}
//ListBatchSubscribeResponse is the type for values returned from the ListBatchSubscribe method
type ListBatchSubscribeResponse struct {
Add_count int
Update_count int
Error_count int
Errors []struct {
Email string
Code int
Message string
}
}
//ListBatchSubscribe subscribes a batch of email address to a list at once.
//You should limit batches to 5k - 10k records.
//http://apidocs.mailchimp.com/api/1.3/listbatchsubscribe.func.php
func (a *API) ListBatchSubscribe(parameters map[string]interface{}) (retVal *ListBatchSubscribeResponse, err error) {
retVal = new(ListBatchSubscribeResponse)
err = parseJson(a, "listBatchSubscribe", parameters, retVal)
return
}