mc 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bd1c554cd8c091423285cbf144266f33c0a7de0
4
- data.tar.gz: 0286850e7e743ad88f8110826db32c6afc409e2d
3
+ metadata.gz: 1d79a45dcaa36faa47ceedc159a03ae01730318f
4
+ data.tar.gz: 99326eed6d7cc453b5d83e7b828ff6a7baab9b1a
5
5
  SHA512:
6
- metadata.gz: 67d67a25c42f884348459c71137266625e8391d1ccec6c1a8e20fb94c3e198850cf225b1ba5d8ed00f616e970806ce36d36b2260655b5c825fce00a3a5b9ba5f
7
- data.tar.gz: 61e68457d561413a6d54d73569840c17908ba7993ef02d46c814a3b0e9e431f3825c7b3797a2e5ca889e398f6746eb164ebf67157b2d0d852c9635be7d36527b
6
+ metadata.gz: 5dc376cf666cf740fa86a19001fe17bb682b5a2d866825b0db37a3dd871682b8d1aad4ebee53ba5b3210b0032cafe551593435dc83d56bc397fcc3b4f9612734
7
+ data.tar.gz: 6bcd1ca4fdd3587c552ca0dc609a81129f8cdcc6dd4b9eea9aa81614edb3185bc3bf08daf24d986eb2e98069fdc859a98bfecd3dcd20fe5f5c7e6f9be78bffbb
@@ -6,6 +6,7 @@ program_desc 'Command line interface to MailChimp. Eep eep!'
6
6
  version MC::VERSION
7
7
 
8
8
  config_file '.mailchimp'
9
+ subcommand_option_handling :normal
9
10
 
10
11
  desc 'Turn on debugging'
11
12
  switch [:debug], :negatable => false
@@ -21,7 +22,7 @@ desc 'List to use'
21
22
  arg_name 'listID'
22
23
  flag [:list]
23
24
 
24
- desc 'formatted, raw, or awesome'
25
+ desc 'table, formatted, raw, or hash'
25
26
  arg_name 'format'
26
27
  flag [:output,:o]
27
28
 
@@ -82,7 +82,7 @@ command :campaigns do |c|
82
82
  type = options[:type]
83
83
 
84
84
  standard_opts = {
85
- :list_id => options[:id],
85
+ :list_id => required_option(:id, options[:id], global[:list]),
86
86
  :subject => required_option(:subject, options[:subject]),
87
87
  :from_email => required_option('from-email', options['from-email']),
88
88
  :from_name => required_option('from-name', options['from-name']),
@@ -124,14 +124,21 @@ command :campaigns do |c|
124
124
 
125
125
  c.desc 'Send Campaign Now'
126
126
  c.command :send do |s|
127
+ s.desc 'Campaign ID'
128
+ s.flag :cid
129
+
127
130
  s.action do |global,options,args|
128
- campaign_id = required_argument("Need to supply a campaign id", args.first)
129
- puts @mailchimp.campaigns_send :cid => campaign_id
131
+ cid = required_argument("Need to supply a campaign id", options[:cid])
132
+ print "Sending campaign #{cid}... "
133
+ @mailchimp.campaigns_send(:cid => cid)["complete"] ? puts("done!") : puts("ut oh, no can do!")
130
134
  end
131
135
  end
132
136
 
133
137
  c.desc 'Schedule Campaign'
134
138
  c.command :schedule do |s|
139
+ s.desc 'Campaign ID'
140
+ s.flag :cid
141
+
135
142
  s.desc 'Date to schedule campaign in YYYY-MM-DD format'
136
143
  s.flag :date, :default_value => (Time.now + 86400).strftime("%Y-%m-%d")
137
144
 
@@ -139,29 +146,34 @@ command :campaigns do |c|
139
146
  s.flag :time, :default_value => '08:00:00'
140
147
 
141
148
  s.action do |global,options,args|
142
- campaign_id = options[:cid]
143
- puts @mailchimp.campaigns_schedule(:cid => campaign_id, :schedule_time => options[:date] + ' ' + options[:time])
149
+ cid = required_argument("Need to supply a campaign id", options[:cid])
150
+ puts @mailchimp.campaigns_schedule(:cid => cid, :schedule_time => options[:date] + ' ' + options[:time])
144
151
  end
145
152
  end
146
153
 
147
154
  c.desc 'Send Test Campaign'
148
- c.command :sendtest do |s|
155
+ c.command 'send-test' do |s|
156
+ s.desc 'Campaign ID'
157
+ s.flag :cid
158
+
149
159
  s.action do |global,options,args|
150
- campaign_id = required_argument("Need to supply a campaign id", args.first)
160
+ cid = required_argument("Need to supply a campaign id", options[:cid])
161
+ emails = required_argument("Need to supply at least one email to send test campaign to.", args)
151
162
 
152
- puts "Sending test for campaign #{campaign_id}..."
153
- puts @mailchimp.campaign_send_test(:cid=> campaign_id, :test_emails => ["kale.davis@gmail.com", "kale@simplerise.com"])
163
+ print "Sending test for campaign #{cid}... "
164
+ @mailchimp.campaigns_send_test(:cid=> cid, :test_emails => emails)["complete"] ? puts("done!") : puts("ut oh, no can do!")
154
165
  end
155
166
  end
156
167
 
157
168
  c.desc 'Delete Campaign'
158
169
  c.command :delete do |s|
159
- s.action do |global,options,args|
160
- campaign_id = options[:cid] || @mailchimp.cache.get(:campaign_id)
161
- throw "Need a valid Campaign ID." if campaign_id.nil?
170
+ s.desc 'Campaign ID'
171
+ s.flag :cid
162
172
 
163
- campaign_delete(:cid=> campaign_id)
164
- puts "Deleted campaign #{campaign_id}."
173
+ s.action do |global,options,args|
174
+ cid = required_argument("Need to supply a campaign id", options[:cid])
175
+ print "Deleting campaign #{cid}... "
176
+ @mailchimp.campaigns_send_test(:cid=> cid)["complete"] ? puts("done!") : puts("ut oh, no can do!")
165
177
  end
166
178
  end
167
179
 
@@ -179,25 +191,33 @@ command :campaigns do |c|
179
191
 
180
192
  c.desc 'Check to see if campaign is ready to send'
181
193
  c.command :ready do |s|
194
+ s.desc 'Campaign ID'
195
+ s.flag :cid
196
+
182
197
  s.action do |global,options,args|
183
198
  cid = options[:cid] || get_last_campaign_id
184
199
 
185
- puts cid
186
200
  @output.standard @mailchimp_cached.campaigns_ready(:cid=> cid)
187
201
  end
188
202
  end
189
203
 
190
204
  c.command "segment-test" do |s|
205
+ s.desc 'List ID'
206
+ s.flag :id
207
+
191
208
  s.desc "Use either 'any' or 'all'"
192
209
  s.flag :match, :default_value => 'all'
193
210
 
194
211
  s.desc 'Condition in the format field,op,value'
195
212
  s.flag :condition
213
+
196
214
  s.action do |global,options,args|
197
- id = get_required_argument(:id, options[:id], global[:default_list])
215
+ id = required_option(:id, options[:id], global[:list])
216
+ match = required_option(:match, options[:match])
217
+ condition = required_option(:condition, options[:condition])
198
218
 
199
219
  segment = {}
200
- segment['match'] = options[:match]
220
+ segment['match'] = match
201
221
  field, op, value = options[:condition].split(',')
202
222
  segment['conditions'] = [{:field => field, :op => op, :value => value}]
203
223
 
@@ -16,14 +16,15 @@ command :ecomm do |c|
16
16
 
17
17
  s.action do |global,options,args|
18
18
  order = {}
19
- order[:id] = options[:order_id]
19
+ order[:id] = required_option(:order_id, options[:order_id])
20
+ order[:campaign_id] = options[:campaign_id]
20
21
  order[:email_id] = options[:email_id]
21
22
  order[:email] = options[:email]
22
23
  order[:total] = options[:total]
23
24
  order[:order_date] = options[:order_date]
24
25
  order[:shipping] = options[:shipping]
25
26
  order[:tax] = options[:tax]
26
- order[:store_id] = options[:store_id]
27
+ order[:store_id] = required_option(:store_id, options[:store_id])
27
28
  order[:store_name] = options[:store_name]
28
29
  order[:items] = [{:product_id => 500, :product_name => "Freddie Doll", :category_id => 1, :category_name => "Toys"}]
29
30
 
@@ -34,4 +35,25 @@ command :ecomm do |c|
34
35
  end
35
36
  end
36
37
  end
38
+
39
+ c.desc 'Delete Ecommerce Order Information used for segmentation'
40
+ c.command :delete do |s|
41
+ s.flag :store_id
42
+ s.flag :order_id
43
+
44
+ s.action do |global,options,args|
45
+ if @mailchimp.ecomm_order_del(:store_id => required_option(:store_id, options[:store_id]), :order_id => required_option(:order_id, options[:order_id]))
46
+ puts "Order deleted!"
47
+ else
48
+ puts "Order not deleted. :("
49
+ end
50
+ end
51
+ end
52
+
53
+ c.desc 'Retrieve the Ecommerce Orders for an account'
54
+ c.command :orders do |s|
55
+ s.action do |global,options,args|
56
+ @output.standard @mailchimp_cached.ecomm_orders['data'], :fields => [:store_id, :store_name, :order_id, :campaign_id, :email, :order_total, :order_date]
57
+ end
58
+ end
37
59
  end
@@ -15,7 +15,7 @@ command :export do |c|
15
15
  c.flag :condition
16
16
 
17
17
  s.action do |global,options,args|
18
- id = get_required_argument(:id, options[:id], global[:default_list])
18
+ id = required_option(:id, options[:id], global[:list])
19
19
 
20
20
  if options[:condition]
21
21
  segment = {}
@@ -26,10 +26,6 @@ command :export do |c|
26
26
 
27
27
  status = options[:status]
28
28
 
29
- # segment = {}
30
- # segment["match"] = "all"
31
- # segment["conditions"] = [{:field => 'aim', :op => 'open', :value => 'b55303410e'}]
32
-
33
29
  @mailchimp.export_list(:id => id, :status => status, :segment => segment).each do |subscriber|
34
30
  puts subscriber
35
31
  end
@@ -66,4 +62,3 @@ command :export do |c|
66
62
  end
67
63
  end
68
64
  end
69
-
@@ -1,12 +1,34 @@
1
1
  desc 'Basic admin funtions'
2
2
  command :helper do |c|
3
3
  c.desc 'View API key currently configured'
4
- c.command :apikey do |apikey|
5
- apikey.action do |global,options,args|
4
+ c.command :apikey do |s|
5
+ s.action do |global,options,args|
6
6
  puts global[:apikey]
7
7
  end
8
8
  end
9
9
 
10
+ c.desc 'View user_id of account'
11
+ c.command :userid do |s|
12
+ s.action do |global,options,args|
13
+ puts @mailchimp_cached.helper_account_details['user_id']
14
+ end
15
+ end
16
+
17
+ c.desc 'View default list if set in config file'
18
+ c.command 'default-list' do |s|
19
+ s.action do |global,options,args|
20
+ global[:list].nil? ? puts('No default list set.') : puts(global[:list])
21
+ end
22
+ end
23
+
24
+ c.desc 'Quickly see the last campaign sent'
25
+ c.command 'last-campaign' do |s|
26
+ s.action do |global,options,args|
27
+ result = @mailchimp.campaigns_list(:limit => 1)['data'].first
28
+ puts "#{result['id']}: #{result['title']}"
29
+ end
30
+ end
31
+
10
32
  # === Actual MailChimp API Calls below ===
11
33
 
12
34
  # helper/account-details (string apikey, array exclude)
@@ -0,0 +1,105 @@
1
+ command :lists do |lists|
2
+ lists.desc 'Manage groups'
3
+ lists.command :group do |c|
4
+ # lists/interest-group-add (string apikey, string id, string group_name, int grouping_id)
5
+ c.desc 'Add a single Interest Group'
6
+ c.command :add do |s|
7
+ s.desc 'list id'
8
+ s.flag :id
9
+ s.flag 'grouping-id'
10
+
11
+ s.action do |global,options,args|
12
+ id = required_argument(:id, options[:id], global[:list])
13
+ group_name = required_argument("Need to provide a group name.", args).first
14
+
15
+ @output.standard @mailchimp.lists_interest_group_add(:id => id, :group_name => group_name, :grouping_id => options['grouping-id'])
16
+ end
17
+ end
18
+
19
+ # lists/interest-group-del (string apikey, string id, string group_name, int grouping_id)
20
+ c.desc 'Delete a single Interest Group'
21
+ c.command :delete do |s|
22
+ s.desc 'list id'
23
+ s.flag :id
24
+ s.flag 'grouping-id'
25
+
26
+ s.action do |global,options,args|
27
+ id = required_argument(:id, options[:id], global[:list])
28
+ group_name = required_argument("Need to provide a group name.", args).first
29
+ @output.standard @mailchimp.lists_interest_group_delete(:id => id, :group_name => group_name, :grouping_id => options['grouping-id'])
30
+ end
31
+ end
32
+
33
+ # lists/interest-group-update (string apikey, string id, string old_name, string new_name, int grouping_id)
34
+ c.desc 'Change the name of an Interest Group'
35
+ c.command :update do |s|
36
+ s.desc 'list id'
37
+ s.flag :id
38
+ s.flag :old
39
+ s.flag :new
40
+ s.flag 'grouping-id'
41
+
42
+ s.action do |global,options,args|
43
+ id = required_argument(:id, options[:id], global[:list])
44
+ @output.standard @mailchimp.lists_interest_group_delete(:id => id, :old_name => options[:old], :new_name => options[:new], :grouping_id => options['grouping-id'])
45
+ end
46
+ end
47
+ end
48
+
49
+ lists.desc 'Manage groupings'
50
+ lists.command :grouping do |c|
51
+ # lists/interest-grouping-add (string apikey, string id, string name, string type, array groups)
52
+ c.desc 'Add a new Interest Grouping'
53
+ c.arg_name 'groups'
54
+ c.command :add do |s|
55
+ s.desc 'list id'
56
+ s.flag :id
57
+
58
+ s.action do |global,options,args|
59
+ id = required_argument(:id, options[:id], global[:list])
60
+ @output.standard @mailchimp_cached.lists_grouping_add(:id => id, :name => options[:name], :type => options[:type])
61
+ end
62
+ end
63
+
64
+ # lists/interest-grouping-del (string apikey, int grouping_id)
65
+ c.desc 'Delete an existing Interest Grouping'
66
+ c.command :delete do |s|
67
+ s.desc 'list id'
68
+ s.flag :id
69
+
70
+ s.action do |global,options,args|
71
+ id = required_argument(:id, options[:id], global[:list])
72
+ emails = create_email_struct(required_argument("Need to provide one or more email addresses.", args))
73
+ @output.standard @mailchimp_cached.lists_
74
+ end
75
+ end
76
+
77
+ # lists/interest-grouping-update (string apikey, int grouping_id, string name, string value)
78
+ c.desc 'Update an existing Interest Grouping'
79
+ c.command :update do |s|
80
+ s.flag :grouping_id
81
+ s.flag :name
82
+ s.flag :value
83
+
84
+ s.action do |global,options,args|
85
+ id = required_argument(:id, options[:id], global[:list])
86
+ @output.standard @mailchimp_cached.lists_interest_grouping_update(:grouping_id => options[:grouping_id], :name => options[:name], :value => options[:value])
87
+ end
88
+ end
89
+
90
+ # lists/interest-groupings (string apikey, string id, bool counts)
91
+ c.desc 'Get the list of interest groupings for a given list, including the label, form information, and included groups for each'
92
+ c.command :list do |s|
93
+ s.desc 'list id'
94
+ s.flag :id
95
+ s.switch :counts, :default_value => false
96
+
97
+ s.action do |global,options,args|
98
+ id = required_argument(:id, options[:id], global[:list])
99
+ @output.standard @mailchimp_cached.lists_interest_groupings(:id => id, :counts => options[:counts])
100
+ end
101
+ end
102
+
103
+ c.default_command :list
104
+ end
105
+ end
@@ -0,0 +1,56 @@
1
+ command :lists do |lists|
2
+ lists.desc 'Manage merge tags'
3
+ lists.command 'merge-vars' do |c|
4
+ # # lists/merge-var-add (string apikey, string id, string tag, string name, struct options)
5
+ # c.desc 'Add a new merge tag to a given list'
6
+ # c.command :add do |s|
7
+ # s.action do |global,options,args|
8
+ # end
9
+ # end
10
+
11
+ # # lists/merge-var-del (string apikey, string id, string tag)
12
+ # c.desc 'Delete a merge tag from a given list and all its members'
13
+ # c.long_desc <<EOS
14
+ # Seriously - the data is removed from all members as well! Note that on large lists this method may seem a bit slower than calls you typically make.
15
+ # EOS
16
+ # c.command :delete do |s|
17
+ # s.action do |global,options,args|
18
+ # end
19
+ # end
20
+
21
+ # # lists/merge-var-reset (string apikey, string id, string tag)
22
+ # c.desc 'Completely resets all data stored in a merge var on a list.'
23
+ # c.command :reset do |s|
24
+ # s.action do |global,options,args|
25
+ # end
26
+ # end
27
+
28
+ # # lists/merge-var-set (string apikey, string id, string tag, string value)
29
+ # c.desc 'Completely resets all data stored in a merge var on a list.'
30
+ # c.command :reset do |s|
31
+ # s.action do |global,options,args|
32
+ # end
33
+ # end
34
+
35
+ # # lists/merge-var-update (string apikey, string id, string tag, struct options)
36
+ # c.desc 'Completely resets all data stored in a merge var on a list.'
37
+ # c.command :reset do |s|
38
+ # s.action do |global,options,args|
39
+ # end
40
+ # end
41
+
42
+ # lists/merge-vars (string apikey, array id)
43
+ c.desc 'Get the list of merge tags for a given list, including their name, tag, and required setting'
44
+ c.command :list do |s|
45
+ s.desc 'List ID'
46
+ s.flag :id
47
+
48
+ s.action do |global,options,args|
49
+ id = required_option(:id, options[:id], global[:list])
50
+ @output.standard @mailchimp_cached.lists_merge_vars(:id => [id])['data'].first['merge_vars']
51
+ end
52
+ end
53
+
54
+ c.default_command :list
55
+ end
56
+ end
@@ -0,0 +1,44 @@
1
+ command :lists do |lists|
2
+ lists.desc 'Manage webhooks for a given lists'
3
+ lists.command :webhook do |c|
4
+ #lists/webhook-add (string apikey, string id, string url, struct actions, struct sources)
5
+ c.desc 'Add a new Webhook URL for the given list'
6
+ c.command :add do |s|
7
+ s.desc 'list id'
8
+ s.flag :id
9
+
10
+ s.action do |global,options,args|
11
+ s.flag :url
12
+ id = required_argument(:id, options[:id], global[:list])
13
+ @output.standard @mailchimp.lists_webhook_add(:id => id, :url => options[:url])
14
+ end
15
+ end
16
+
17
+ #lists/webhook-del (string apikey, string id, string url)
18
+ c.desc 'Delete an existing Webhook URL from a given list'
19
+ c.command :delete do |s|
20
+ s.desc 'list id'
21
+ s.flag :id
22
+
23
+ s.action do |global,options,args|
24
+ s.flag :url
25
+ id = required_argument(:id, options[:id], global[:list])
26
+ @output.standard @mailchimp.lists_webhook_del(:id => id, :url => options[:url])
27
+ end
28
+ end
29
+
30
+ #lists/webhooks (string apikey, string id)
31
+ c.desc 'Return the Webhooks configured for the given list'
32
+ c.command :list do |s|
33
+ s.desc 'list id'
34
+ s.flag :id
35
+
36
+ s.action do |global,options,args|
37
+ id = required_argument(:id, options[:id], global[:list])
38
+ @output.standard @mailchimp_cached.lists_webhooks(:id => id)
39
+ end
40
+ end
41
+
42
+ c.default_command :list
43
+ end
44
+ end
@@ -1,36 +1,35 @@
1
1
  desc 'View information about lists and subscribers'
2
- arg_name 'Describe arguments to lists here'
3
-
4
2
  command :lists do |c|
5
- c.desc 'List ID'
6
- c.flag :id
7
-
8
- c.desc 'Email Adress'
9
- c.flag :email
10
-
11
- c.desc 'Page number to start at'
12
- c.flag :start, :default_value => 0
3
+ c.desc 'Get all email addresses that complained about a campaign sent to a list'
4
+ c.command 'abuse-reports' do |s|
5
+ s.desc 'list id'
6
+ s.flag :id
13
7
 
14
- c.desc 'Retrieve all of the lists defined for your user account.'
15
- c.command :list do |s|
16
- s.action do |global,options,args|
17
- stats_column = lambda{|l| "#{l['stats']['member_count']} / #{na(l['stats']['open_rate'])} / #{na(l['stats']['click_rate'])}"}
18
- @output.standard @mailchimp_cached.lists_list['data'], :fields => [:id, :name, {"count / open % / click %" => stats_column}]
19
- end
20
- end
21
-
22
- c.desc 'Access up to the previous 180 days of daily detailed aggregated activity stats for a given list.'
23
- c.command :activity do |s|
24
8
  s.action do |global,options,args|
25
9
  id = required_argument(:id, options[:id], global[:list])
26
10
  @output.standard @mailchimp_cached.lists_activity(:id => id)
27
11
  end
28
12
  end
29
13
 
14
+ # c.desc 'Subscribe a batch of email addresses to a list at once.'
15
+ # c.command 'batch-subscribe' do |s|
16
+ # s.action do |global,options,args|
17
+ # end
18
+ # end
19
+
20
+ # c.desc 'Unsubscribe a batch of email addresses from a list.'
21
+ # c.command 'batch-unsubscribe' do |s|
22
+ # s.action do |global,options,args|
23
+ # end
24
+ # end
25
+
30
26
  c.desc "Retrieve the clients that the list's subscribers have been tagged as being used based on user agents seen."
31
27
  c.command :clients do |s|
28
+ s.desc 'list id'
29
+ s.flag :id
30
+
32
31
  s.action do |global,options,args|
33
- id = get_required_argument(:id, options[:id], global[:list])
32
+ id = required_option(:id, options[:id], global[:list])
34
33
 
35
34
  results = @mailchimp_cached.lists_clients(:id => id)
36
35
  if global[:output]
@@ -45,50 +44,128 @@ command :lists do |c|
45
44
  end
46
45
  end
47
46
 
48
- c.desc 'Get all of the merge variables for a list.'
49
- c.command 'merge-vars' do |s|
47
+ c.desc 'Access the Growth History by Month for a given list.'
48
+ c.command :growth do |s|
49
+ s.desc 'list id'
50
+ s.flag :id
51
+
50
52
  s.action do |global,options,args|
51
- id = get_required_argument(:id, options[:id], global[:list])
52
- @output.standard @mailchimp_cached.lists_merge_vars(:id => [id])['data'].first['merge_vars']
53
+ id = required_option(:id, options[:id], global[:list])
54
+ @output.standard @mailchimp_cached.lists_growth_history(:id => id)
53
55
  end
54
56
  end
55
57
 
56
- c.desc 'Get all of the list members for a list that are of a particular status.'
57
- c.command :members do |s|
58
- s.flag :limit, :default_value => 25
58
+ c.desc 'Retrieve all of the lists defined for your user account.'
59
+ c.command :list do |s|
60
+ s.action do |global,options,args|
61
+ stats_column = lambda{|l| "#{l['stats']['member_count']} / #{na(l['stats']['open_rate'])} / #{na(l['stats']['click_rate'])}"}
62
+ @output.standard @mailchimp_cached.lists_list['data'], :fields => [:id, :name, {"count / open % / click %" => stats_column}]
63
+ end
64
+ end
65
+
66
+ c.desc 'Retrieve the locations (countries) that the list\'s subscribers have been tagged to based on geocoding their IP address.'
67
+ c.command :locations do |s|
68
+ s.desc 'list id'
69
+ s.flag :id
70
+ s.flag :num, :default_value => 25
71
+
72
+ s.action do |global,options,args|
73
+ id = required_option(:id, options[:id], global[:list])
74
+ @output.standard @mailchimp_cached.lists_locations(:id => id)[0..options[:num].to_i]
75
+ end
76
+ end
77
+
78
+ c.desc 'Get the most recent 100 activities for particular list members.'
79
+ c.arg_name 'emails'
80
+ c.command 'member-activity' do |s|
81
+ s.desc 'list id'
82
+ s.flag :id
59
83
 
60
84
  s.action do |global,options,args|
61
- id = get_required_argument(:id, options[:id], global[:list])
62
- @output.standard @mailchimp_cached.lists_members(:id => id, :limit => limit)['data'], :fields => [:email, :member_rating, :status, :is_gmonkey]
85
+ id = required_option(:id, options[:id], global[:list])
86
+ emails = create_email_struct(required_argument("Need to provide one or more email addresses.", args))
87
+
88
+ @output.standard @mailchimp_cached.lists_member_activity(:id => id, :emails => emails)['data'].first['activity'], :fields => [:action, :timestamp, :title, :url]
63
89
  end
64
90
  end
65
91
 
66
92
  c.desc 'Get information about one particular member.'
93
+ c.arg_name 'emails'
67
94
  c.command 'member-info' do |s|
95
+ s.desc 'list id'
96
+ s.flag :id
97
+
68
98
  s.action do |global,options,args|
69
- id = get_required_argument(:id, options[:id], global[:list])
99
+ id = required_option(:id, options[:id], global[:list])
70
100
  emails = create_email_struct(required_argument("Need to provide one or more email addresses.", args))
71
101
 
72
102
  @output.as_hash @mailchimp_cached.lists_member_info(:id => id, :emails => emails)
73
103
  end
74
104
  end
75
105
 
76
- c.desc 'Retrieve the locations (countries) that the list\'s subscribers have been tagged to based on geocoding their IP address.'
77
- c.command :locations do |s|
78
- s.flag :num, :default_value => 25
106
+ c.desc 'Get all of the list members for a list that are of a particular status.'
107
+ c.command :members do |s|
108
+ s.desc 'list id'
109
+ s.flag :id
110
+ s.flag :limit, :default_value => 25
79
111
 
80
112
  s.action do |global,options,args|
81
- id = get_required_argument(:id, options[:id], global[:list])
82
- @output.standard @mailchimp_cached.lists_locations(:id => id)[0..options[:num].to_i]
113
+ id = required_option(:id, options[:id], global[:list])
114
+ @output.standard @mailchimp_cached.lists_members(:id => id, :limit => options[:limit])['data'], :fields => [:email, :member_rating, :status, :is_gmonkey]
83
115
  end
84
116
  end
85
117
 
86
- c.desc 'Access the Growth History by Month for a given list.'
87
- c.command :growth do |s|
118
+ c.desc 'Subscribe the provided email to a list. By default this sends a confirmation email.'
119
+ c.arg_name 'emails'
120
+ c.command :subscribe do |s|
121
+ s.desc 'list id'
122
+ s.flag :id
123
+
88
124
  s.action do |global,options,args|
89
- id = get_required_argument(:id, options[:id], global[:list])
90
- # @output.standard @mailchimp_cached.lists_growth_history(:id => id), :fields => [:month, :existing, :optins]
91
- @output.standard @mailchimp_cached.lists_growth_history(:id => id)
125
+ #TODO: add support for merge fields
126
+ #TODO: add support for location
127
+ s.flag 'new-email'
128
+ s.flag 'group-id'
129
+ s.flag 'group-name'
130
+ s.flag :groups
131
+ s.flag 'optin-ip'
132
+ s.flag 'optin-time'
133
+ s.flag :language
134
+ s.flag :note
135
+ s.flag 'note-id'
136
+ s.flag 'note-action'
137
+
138
+ s.flag 'email-type'
139
+ s.switch 'double-optin'
140
+ s.switch 'update-existing'
141
+ s.switch 'replace-interests'
142
+ s.switch 'send-welcome'
143
+
144
+ id = required_argument(:id, options[:id], global[:list])
145
+ emails = create_email_struct(required_argument("Need to provide one or more email addresses.", args))
146
+ @output.as_hash @mailchimp.lists_subscribe(:id => id, :email => emails.first, :merge_vars => {:groupings => [{:id => 4493, :groups => ['Group1']}]})
147
+ end
148
+ end
149
+
150
+ c.desc 'Retrieve all of the Static Segments for a list.'
151
+ c.command 'static-segments' do |s|
152
+ s.desc 'list id'
153
+ s.flag :id
154
+
155
+ s.action do |global,options,args|
156
+ id = required_option(:id, options[:id], global[:list])
157
+ @output.as_hash @mailchimp_cached.lists_static_segments(:id => id)
158
+ end
159
+ end
160
+
161
+ c.desc 'Retrieve all of the Static Segments for a list.'
162
+ c.command 'segments' do |s|
163
+ s.desc 'list id'
164
+ s.flag :id
165
+
166
+ s.action do |global,options,args|
167
+ id = required_option(:id, options[:id], global[:list])
168
+ @output.as_hash @mailchimp_cached.lists_segments(:id => id)
92
169
  end
93
170
  end
94
171
  end
@@ -1,20 +1,26 @@
1
1
  desc 'Reports'
2
2
  command :reports do |c|
3
-
4
3
  # reports/abuse (string apikey, string cid, struct opts)
5
4
  c.desc 'Get all email addresses that complained about a given campaign'
6
5
  c.command :abuse do |s|
6
+ s.arg_name 'campaign id'
7
+ s.flag :cid
8
+
7
9
  s.action do |global,options,args|
8
- not_implemented
10
+ cid = options[:cid] || get_last_campaign_id
11
+ member_column = lambda{|l| "#{l['member']['email']}"}
12
+ @output.standard @mailchimp_cached.reports_abuse(:cid => cid)['data'], :fields => [:member => {:display_method => member_column}]
9
13
  end
10
14
  end
11
15
 
12
16
  # reports/advice (string apikey, string cid)
13
17
  c.desc 'Retrieve the text presented in our app for how a campaign performed and any advice we may have for you'
14
18
  c.command :advice do |s|
19
+ s.arg_name 'campaign id'
20
+ s.flag :cid
21
+
15
22
  s.action do |global,options,args|
16
23
  cid = options[:cid] || get_last_campaign_id
17
- #cid = @mailchimp.campaigns_list(:limit => 1, :sort_field => "send_time")["data"].first["id"]
18
24
  @output.as_hash @mailchimp_cached.reports_advice :cid => cid
19
25
  end
20
26
  end
@@ -22,14 +28,22 @@ command :reports do |c|
22
28
  # reports/bounce-message (string apikey, string cid, struct email)
23
29
  c.desc 'Retrieve the most recent full bounce message for a specific email address on the given campaign. Messages over 30 days old are subject to being removed'
24
30
  c.command :bounce do |s|
31
+ s.arg_name 'campaign id'
32
+ s.flag :cid
33
+
25
34
  s.action do |global,options,args|
26
- not_implemented
35
+ cid = options[:cid] || get_last_campaign_id
36
+ email = create_email_struct(required_argument("Need to provide an email address.", args))
37
+ puts @mailchimp_cached.reports_bounce_message(:cid => cid, :email => email.first)['message']
27
38
  end
28
39
  end
29
40
 
30
41
  # reports/bounce-messages (string apikey, string cid, struct opts)
31
- c.desc 'Retrieve the full bounce messages for the given campaign. Note that this can return very large amounts of data depending on how large the campaign was and how much cruft the bounce provider returned. Also, messages over 30 days old are subject to being removed'
42
+ c.desc 'Retrieve the full bounce messages for the given campaign. Messages over 30 days old are subject to being removed'
32
43
  c.command :bounces do |s|
44
+ s.arg_name 'campaign id'
45
+ s.flag :cid
46
+
33
47
  s.action do |global,options,args|
34
48
  cid = options[:cid] || get_last_campaign_id
35
49
 
@@ -55,24 +69,37 @@ command :reports do |c|
55
69
 
56
70
  # reports/click-detail (string apikey, string cid, int tid, struct opts)
57
71
  c.desc 'Return the list of email addresses that clicked on a given url, and how many times they clicked'
58
- c.command :clicked do |s|
72
+ c.command 'clicked-url' do |s|
73
+ s.arg_name 'campaign id'
74
+ s.flag :cid
75
+ s.flag :tid
76
+
59
77
  s.action do |global,options,args|
60
- not_implemented
78
+ cid = options[:cid] || get_last_campaign_id
79
+ tid = options[:tid]
80
+ member_column = lambda{|l| "#{l['member']['email']}"}
81
+ @output.standard @mailchimp_cached.reports_click_detail(:cid => cid, :tid => tid)['data'], :fields => [:clicks, {:member => {:display_method => member_column}}]
61
82
  end
62
83
  end
63
84
 
64
85
  # reports/clicks (string apikey, string cid)
65
86
  c.desc 'The urls tracked and their click counts for a given campaign.'
66
87
  c.command :clicks do |s|
88
+ s.arg_name 'campaign id'
89
+ s.flag :cid
90
+
67
91
  s.action do |global,options,args|
68
92
  cid = options[:cid] || get_last_campaign_id
69
- @output.standard @mailchimp_cached.reports_clicks(:cid => cid)['total'], :fields => [{:url => {:width => 80}}, :clicks, :unique]
93
+ @output.standard @mailchimp_cached.reports_clicks(:cid => cid)['total'], :fields => [:tid, {:url => {:width => 80}}, :clicks, :unique]
70
94
  end
71
95
  end
72
96
 
73
97
  # reports/domain-performance (string apikey, string cid)
74
98
  c.desc 'Get the top 5 performing email domains for this campaign.'
75
99
  c.command :domains do |s|
100
+ s.arg_name 'campaign id'
101
+ s.flag :cid
102
+
76
103
  s.action do |global,options,args|
77
104
  cid = options[:cid] || get_last_campaign_id
78
105
  @output.standard @mailchimp_cached.reports_domain_performance :cid => cid
@@ -82,32 +109,45 @@ command :reports do |c|
82
109
  # reports/ecomm-orders (string apikey, string cid, struct opts)
83
110
  c.desc 'Retrieve the Ecommerce Orders tracked by campaignEcommOrderAdd()'
84
111
  c.command :ecomm do |s|
112
+ s.arg_name 'campaign id'
113
+ s.flag :cid
114
+
85
115
  s.action do |global,options,args|
86
- not_implemented
116
+ cid = options[:cid] || get_last_campaign_id
117
+ @output.standard @mailchimp_cached.reports_ecomm_orders(:cid => cid)['data']
87
118
  end
88
119
  end
89
120
 
90
121
  # reports/eepurl (string apikey, string cid)
91
122
  c.desc 'Retrieve the eepurl stats from the web/Twitter mentions for this campaign'
92
123
  c.command :eepurl do |s|
124
+ s.arg_name 'campaign id'
125
+ s.flag :cid
126
+
93
127
  s.action do |global,options,args|
94
128
  cid = options[:cid] || get_last_campaign_id
95
- @output.standard @mailchimp_cached.reports_eepurl :cid => cid
129
+ @output.as_hash @mailchimp_cached.reports_eepurl(:cid => cid)
96
130
  end
97
131
  end
98
132
 
99
133
  # reports/geo-opens (string apikey, string cid)
100
134
  c.desc 'Retrieve the countries/regions and number of opens tracked for each. Email address are not returned.'
101
135
  c.command :geo do |s|
136
+ s.arg_name 'campaign id'
137
+ s.flag :cid
138
+
102
139
  s.action do |global,options,args|
103
140
  cid = options[:cid] || get_last_campaign_id
104
- @output.standard @mailchimp_cached.reports_geo_opens :cid => cid
141
+ @output.standard @mailchimp_cached.reports_geo_opens(:cid => cid), :fields => [:code, :name, :opens]
105
142
  end
106
143
  end
107
144
 
108
145
  # reports/google-analytics (string apikey, string cid)
109
146
  c.desc 'Retrieve the Google Analytics data we have collected for this campaign.'
110
147
  c.command :ga do |s|
148
+ s.arg_name 'campaign id'
149
+ s.flag :cid
150
+
111
151
  s.action do |global,options,args|
112
152
  cid = options[:cid] || get_last_campaign_id
113
153
  @output.standard @mailchimp_cached.reports_google_analytics :cid => cid
@@ -116,39 +156,81 @@ command :reports do |c|
116
156
 
117
157
  # reports/member-activity (string apikey, string cid, array emails)
118
158
  c.desc 'Given a campaign and email address, return the entire click and open history with timestamps, ordered by time.'
119
- c.command :member_activity do |s|
159
+ c.command 'member-activity' do |s|
160
+ s.arg_name 'campaign id'
161
+ s.flag :cid
162
+
120
163
  s.action do |global,options,args|
121
- not_implemented
164
+ cid = options[:cid] || get_last_campaign_id
165
+ email = create_email_struct(required_argument("Need to provide an email address.", args))
166
+ results = @mailchimp_cached.reports_member_activity(:cid => cid, :emails => email)['data']
167
+
168
+ results.each do |result|
169
+ puts result['email']['email']
170
+ puts "#{'='*result['email']['email'].size}"
171
+ @output.as_table result['activity']
172
+ puts "\n"
173
+ end
122
174
  end
123
175
  end
124
176
 
125
177
  # reports/not-opened (string apikey, string cid, struct opts)
126
178
  c.desc 'Retrieve the list of email addresses that did not open a given campaign'
127
- c.command :not_opened do |s|
179
+ c.command 'not-opened' do |s|
180
+ s.arg_name 'campaign id'
181
+ s.flag :cid
182
+ s.flag :start, :default_value => 0
183
+ s.flag :limit, :default_value => 50
184
+
128
185
  s.action do |global,options,args|
129
- not_implemented
186
+ cid = options[:cid] || get_last_campaign_id
187
+ opts = {:start => options['start'], :limit => options['limit']}
188
+ @output.standard @mailchimp_cached.reports_not_opened(:cid => cid, :opts => opts)['data'], :fields => [:email]
130
189
  end
131
190
  end
132
191
 
133
192
  # reports/opened (string apikey, string cid, struct opts)
134
193
  c.desc 'Retrieve the list of email addresses that opened a given campaign with how many times they opened'
135
194
  c.command :opened do |s|
195
+ s.arg_name 'campaign id'
196
+ s.flag :cid
197
+ s.flag :start, :default_value => 0
198
+ s.flag :limit, :default_value => 50
199
+ s.flag 'sort-field', :default_value => "opened"
200
+ s.flag 'sort-dir', :default_value => "asc"
201
+
136
202
  s.action do |global,options,args|
137
- not_implemented
203
+ cid = options[:cid] || get_last_campaign_id
204
+ opts = {:start => options['start'], :limit => options['limit'], :sort_field => options['sort-field'], :sort_dir => options['sort-dir']}
205
+ member_column = lambda{|l| "#{l['member']['email']}"}
206
+
207
+ @output.standard @mailchimp_cached.reports_opened(:cid => cid, :opts => opts)['data'], :fields => [:opens, {:member => {:display_method => member_column}}]
138
208
  end
139
209
  end
140
210
 
141
211
  # reports/sent-to (string apikey, string cid, struct opts)
142
212
  c.desc 'Get email addresses the campaign was sent to'
143
- c.command :sent_to do |s|
213
+ c.command 'sent-to' do |s|
214
+ s.arg_name 'campaign id'
215
+ s.flag :cid
216
+ s.flag :status
217
+ s.flag :start, :default_value => 0
218
+ s.flag :limit, :default_value => 50
219
+
144
220
  s.action do |global,options,args|
145
- not_implemented
221
+ cid = options[:cid] || get_last_campaign_id
222
+ opts = {:status => options['status'], :start => options['start'], :limit => options['limit']}
223
+ member_column = lambda{|l| "#{l['member']['email']}"}
224
+ @output.standard @mailchimp_cached.reports_sent_to(:cid => cid, :opts => opts)['data'], :fields => [:member => {:display_method => member_column}]
146
225
  end
147
226
  end
148
227
 
149
228
  # reports/share (string apikey, string cid, array opts)
150
229
  c.desc 'Get the URL to a customized VIP Report for the specified campaign and optionally send an email to someone with links to it.'
151
230
  c.command :share do |s|
231
+ s.arg_name 'campaign id'
232
+ s.flag :cid
233
+
152
234
  s.action do |global,options,args|
153
235
  cid = options[:cid] || get_last_campaign_id
154
236
 
@@ -168,16 +250,28 @@ command :reports do |c|
168
250
  # reports/summary (string apikey, string cid)
169
251
  c.desc 'Retrieve relevant aggregate campaign statistics (opens, bounces, clicks, etc.)'
170
252
  c.command :summary do |s|
253
+ s.desc 'Campaign ID'
254
+ s.flag :cid
255
+
171
256
  s.action do |global,options,args|
172
- not_implemented
257
+ ap options
258
+ cid = options[:cid] || get_last_campaign_id
259
+ @output.as_hash @mailchimp_cached.reports_summary(:cid => cid)
173
260
  end
174
261
  end
175
262
 
176
263
  # reports/unsubscribes (string apikey, string cid, struct opts)
177
264
  c.desc 'Get all unsubscribed email addresses for a given campaign'
178
265
  c.command :unsubscribes do |s|
266
+ s.arg_name 'campaign id'
267
+ s.flag :cid
268
+ s.flag :start, :default_value => 0
269
+ s.flag :limit, :default_value => 50
270
+
179
271
  s.action do |global,options,args|
180
- not_implemented
272
+ cid = options[:cid] || get_last_campaign_id
273
+ opts = {:start => options['start'], :limit => options['limit']}
274
+ @output.standard @mailchimp_cached.reports_unsubscribes(:cid => cid, :opts => opts)['data'], :fields => [:email]
181
275
  end
182
276
  end
183
277
  end
@@ -4,8 +4,8 @@ command :search do |c|
4
4
  c.desc 'Search all campaigns for the specified query terms'
5
5
  c.command :campaigns do |s|
6
6
  s.action do |global,options,args|
7
- campaigns = required_argument("You need to include a search argument: mc search campaigns <query terms>", args.join(' '))
8
- @output.search @mailchimp_cached.helper_search_members(:query => query)
7
+ query = required_argument("You need to include a search argument: mc search campaigns <query terms>", args.join(' '))
8
+ @output.campaign_search @mailchimp_cached.helper_search_campaigns(:query => query)
9
9
  end
10
10
  end
11
11
 
@@ -14,7 +14,7 @@ command :search do |c|
14
14
  c.command :members do |s|
15
15
  s.action do |global,options,args|
16
16
  query = required_argument("You need to include a search argument: mc search members <query terms>", args.join(' '))
17
- @output.search @mailchimp_cached.helper_search_members(:query => query)
17
+ @output.member_search @mailchimp_cached.helper_search_members(:query => query)
18
18
  end
19
19
  end
20
20
  end
@@ -3,19 +3,66 @@ command :users do |c|
3
3
  # users/invite (string apikey, string email, string role, string msg)
4
4
  c.desc 'Invite a user to your account'
5
5
  c.command :invite do |s|
6
+ s.flag :role
7
+ s.flag :msg
8
+
9
+ s.action do |global,options,args|
10
+ email = required_argument("Need to provide an email address.", args)
11
+ role = options[:role]
12
+ msg = options[:msg]
13
+
14
+ @output.standard @mailchimp.users_invites(:email => email, :role => role, :msg => msg)
15
+ end
16
+ end
17
+
18
+ # users/invite-resend (string apikey, string email)
19
+ c.desc 'Resend an invite a user to your account.'
20
+ c.command 'invite-revoke' do |s|
6
21
  s.action do |global,options,args|
7
- emails = create_email_struct(options[:email])
22
+ email = required_argument("Need to provide email address.", args)
23
+ @output.standard @mailchimp.users_login_revoke(:email => email)
24
+ end
25
+ end
8
26
 
9
- status = @mailchimp.vip_add(:id => id, :emails => emails)
10
- puts status
27
+ # users/invite-revoke (string apikey, string email)
28
+ c.desc 'Revoke an invitation sent to a user to your account.'
29
+ c.command 'invite-revoke' do |s|
30
+ s.action do |global,options,args|
31
+ email = required_argument("Need to provide email address.", args)
32
+ @output.standard @mailchimp.users_login_revoke(:email => email)
11
33
  end
12
34
  end
13
35
 
14
- # useres/logins (string apikey)
36
+ # users/invites (string apikey)
37
+ c.desc 'Retrieve the list of pending users invitations have been sent for.'
38
+ c.command :invites do |s|
39
+ s.action do
40
+ @output.standard @mailchimp_cached.users_invites
41
+ end
42
+ end
43
+
44
+ # users/login-revoke (string apikey, string username)
45
+ c.desc 'Revoke access for a specified login.'
46
+ c.command 'login-revoke' do |s|
47
+ s.action do |global,options,args|
48
+ username = required_argument("Need to provide login username.", args)
49
+ @output.standard @mailchimp.users_login_revoke(:username => username)
50
+ end
51
+ end
52
+
53
+ # users/logins (string apikey)
15
54
  c.desc 'Retrieve the list of active logins.'
16
55
  c.command :logins do |s|
17
- s.action do
18
- puts @mailchimp_cached.users_logins
56
+ s.action do |global,options,args|
57
+ @output.standard @mailchimp_cached.users_logins
58
+ end
59
+ end
60
+
61
+ # users/profile (string apikey)
62
+ c.desc 'Retrieve the profile for the login owning the provided API Key.'
63
+ c.command :profile do |s|
64
+ s.action do |global,options,args|
65
+ @output.standard @mailchimp_cached.users_profile
19
66
  end
20
67
  end
21
68
  end
@@ -1,8 +1,5 @@
1
1
  desc 'VIPs'
2
2
  command :vip do |c|
3
- c.desc 'List ID'
4
- c.flag :id
5
-
6
3
  # vip/activity (string apikey)
7
4
  c.desc 'Show all Activity (opens/clicks) for VIPs over the past 10 days'
8
5
  c.command :activity do |s|
@@ -14,16 +11,17 @@ command :vip do |c|
14
11
  # vip/add (string apikey, string id, array emails)
15
12
  c.desc 'Add VIP(s)'
16
13
  c.command :add do |s|
14
+ s.desc 'List ID'
15
+ s.flag :id
16
+
17
17
  s.action do |global,options,args|
18
- id = get_required_argument(:id, options[:id], global[:default_list])
18
+ id = required_option(:id, options[:id], global[:list])
19
19
  emails = create_email_struct(required_argument("Need to provide an email address.", args))
20
20
 
21
21
  status = @mailchimp.vip_add(:id => id, :emails => emails)
22
- if emails.count == status['success_count']
23
- puts "Successfully added email(s)!"
24
- else
25
- @output.errors status
26
- end
22
+
23
+ puts "Added #{status['success_count']} subscriber(s) as VIPs." if successful? status
24
+ show_errors status
27
25
  end
28
26
  end
29
27
 
@@ -31,13 +29,13 @@ command :vip do |c|
31
29
  c.desc 'Remove VIP(s)'
32
30
  c.command :remove do |s|
33
31
  s.action do |global,options,args|
34
- id = get_required_argument(:id, options[:id], global[:default_list])
32
+ id = required_option(:id, options[:id], global[:list])
35
33
  emails = create_email_struct(required_argument("Need to provide an email address.", args))
36
34
 
37
35
  status = @mailchimp.vip_del(:id => id, :emails => emails)
38
- #TODO: create helper method to display success
39
- puts status
40
- #status["success"] > 0 ? "#{options[:email]} removed!" : "Oops!"
36
+
37
+ puts "Removed #{status['success_count']} subscriber(s) as VIPs." if successful? status
38
+ show_errors status
41
39
  end
42
40
  end
43
41
 
@@ -9,12 +9,6 @@ module Helper
9
9
  end
10
10
  end
11
11
 
12
- def get_required_argument(name, option, global)
13
- return option unless option.nil?
14
- return global unless global.nil?
15
- help_now!("--#{name.to_s} is required")
16
- end
17
-
18
12
  def required_option(name, *options)
19
13
  options.each {|o| return o unless o.nil? or o.empty?}
20
14
  exit_now!("Error: --#{name.to_s} is required")
@@ -51,6 +45,20 @@ module Helper
51
45
  end
52
46
  end
53
47
 
48
+ def successful? status
49
+ status['success_count'] > 0
50
+ end
51
+
52
+ def show_errors status
53
+ if status['error_count'] > 0
54
+ puts "Oops, had #{status['error_count']} error(s):"
55
+ status['errors'].each do |error|
56
+ # remove periods just to make the error look nicer
57
+ puts " #{error['error'].gsub('.','')} - #{error['email']['email']}"
58
+ end
59
+ end
60
+ end
61
+
54
62
  private
55
63
 
56
64
  def pad(num, total)
@@ -15,7 +15,7 @@ class MailChimp
15
15
  category = method_name.to_s.split('_').first
16
16
  method = method_name.to_s.split('_')[1..-1].join('_')
17
17
  if category == "export"
18
- @exporter.send(method, *args)
18
+ @exporter.__send__(method, *args)
19
19
  else
20
20
  if method == 'send'
21
21
  # handle wonk case of 'send' method
@@ -33,7 +33,8 @@ class MailChimpCached < MailChimp
33
33
  category = method_name.to_s.split('_').first
34
34
  method = method_name.to_s.split('_')[1..-1].join('_')
35
35
 
36
- throw "error: don't support caching send" if method == 'send'
36
+ throw "error: don't support caching export" if category == "export"
37
+ throw "error: don't support caching send" if method == "send"
37
38
 
38
39
  result = @api.send(category).method_missing(method, *args)
39
40
  @cache.set(cache_key, result)
@@ -1,4 +1,4 @@
1
1
  module MC
2
2
  # have to check const defined for 1.8.7 to avoid warnings
3
- VERSION = '0.0.4' unless const_defined?(:VERSION)
3
+ VERSION = '0.0.5' unless const_defined?(:VERSION)
4
4
  end
@@ -29,6 +29,10 @@ class ConsoleWriter
29
29
  tp results, options[:fields]
30
30
  end
31
31
 
32
+ def as_raw(results)
33
+ puts results
34
+ end
35
+
32
36
  def errors(results)
33
37
  puts "Error count: #{results['error_count']}"
34
38
  results['errors'].each do |error|
@@ -113,30 +117,42 @@ class ConsoleWriter
113
117
  end
114
118
  end
115
119
 
116
- def search(results)
120
+ def campaign_search(results)
121
+ if results['total'].to_i == 0
122
+ exit_now!("No matches found.")
123
+ end
124
+
125
+ results['results'].each_with_index do |result, index|
126
+ puts "#{'-'*15} [#{index+1}] #{'-'*15}"
127
+ puts result['snippet'].strip.gsub(/\n/, ' ')
128
+ puts "From campaign \"#{result['campaign']['title']}\" (#{result['campaign']['id']}) that was sent on #{result['campaign']['send_time'].split.first}"
129
+ puts "\n"
130
+ end
131
+ end
132
+
133
+ def member_search(results)
117
134
  redirect_output?(results)
118
135
 
119
- i = results
120
- if i['exact_matches']['total'].to_i == 0 and i['full_search']['total'].to_i == 0
136
+ if results['exact_matches']['total'].to_i == 0 and results['full_search']['total'].to_i == 0
121
137
  exit_now!("No matches found.")
122
138
  end
123
139
 
124
140
  members = []
125
141
 
126
- if i['exact_matches']['total'].to_i > 0
127
- puts "#{'='*20} Exact Matches (#{i['exact_matches']['total']}) #{'='*20}"
142
+ if results['exact_matches']['total'].to_i > 0
143
+ puts "#{'='*20} Exact Matches (#{results['exact_matches']['total']}) #{'='*20}"
128
144
 
129
- i['exact_matches']['members'].each do |member|
145
+ results['exact_matches']['members'].each do |member|
130
146
  members << member
131
147
  end
132
- elsif i['full_search']['total'].to_i > 0
133
- puts "#{'='*26} Matches (#{i['full_search']['total']}) #{'='*26}"
134
- i['full_search']['members'].each do |member|
148
+ elsif results['full_search']['total'].to_i > 0
149
+ puts "#{'='*26} Matches (#{results['full_search']['total']}) #{'='*26}"
150
+ results['full_search']['members'].each do |member|
135
151
  members << member
136
152
  end
137
153
  end
138
154
 
139
- tp members, :email, :id, :member_rating, :status, "VIP?" => {:display_method => :is_gmonkey}
155
+ tp members, :email, :id, :list_name, :member_rating, :status, "VIP?" => {:display_method => :is_gmonkey}
140
156
  end
141
157
 
142
158
  private
@@ -163,7 +179,7 @@ class ConsoleWriter
163
179
  as_formatted results, options
164
180
  exit_now!('')
165
181
  when :raw
166
- puts results
182
+ as_raw results
167
183
  exit_now!('')
168
184
  when :awesome, :hash
169
185
  ap results
@@ -11,11 +11,11 @@ describe "MailChimp" do
11
11
  end
12
12
 
13
13
  it "should be able to ping MailChimp" do
14
- @mailchimp.ping.must_equal "Everything's Chimpy!"
14
+ @mailchimp.helper_ping['msg'].must_equal "Everything's Chimpy!"
15
15
  end
16
16
 
17
17
  it "should pass to method_missing" do
18
- @mailchimp.lists_list.count.must_be :>, 0
18
+ @mailchimp.lists_list.count.must_be :>, 0
19
19
  end
20
20
 
21
21
  it "should see updated results" do
@@ -73,7 +73,7 @@ describe "MailChimpCached" do
73
73
  @mailchimp_cached.lists_subscribe(:id => @test_list_id, :email => {:email => email}, :double_optin => false)
74
74
  new_count = @mailchimp_cached.lists_members(:id => @test_list_id)["total"].to_i
75
75
  new_count.must_equal count
76
-
76
+
77
77
  clear_cached_dir
78
78
 
79
79
  new_count = @mailchimp_cached.lists_members(:id => @test_list_id)["total"].to_i
@@ -2,10 +2,9 @@ def config
2
2
  config_file = ENV['HOME']+'/.mailchimp'
3
3
  raise "Need config file to pull API key from." unless File.exists?(config_file)
4
4
  config_hash = YAML.load(File.open(config_file))
5
- config_hash[:test_list_id] = "ef4227fc80"
6
5
 
7
- raise "Need API key for testing." unless config_hash.has_key? :apikey
8
- raise "Need to define test list in test_helper.rb" unless config_hash.has_key? :test_list_id
6
+ raise "Need to set :test_api_key in config file" unless config_hash.has_key? :test_api_key
7
+ raise "Need to set :test_list_id in config file" unless config_hash.has_key? :test_list_id
9
8
 
10
9
  return config_hash
11
10
  end
@@ -20,5 +19,5 @@ def clear_cached_dir
20
19
  end
21
20
 
22
21
  def get_random_email_address
23
- "test+#{rand(1000..9999)}@kaledavis.com"
22
+ "test+#{rand(1000..9999)}@gmail.com"
24
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kale Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-02 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -145,6 +145,9 @@ files:
145
145
  - lib/mc/commands/export.rb
146
146
  - lib/mc/commands/gallery.rb
147
147
  - lib/mc/commands/helper.rb
148
+ - lib/mc/commands/lists-group.rb
149
+ - lib/mc/commands/lists-merge-var.rb
150
+ - lib/mc/commands/lists-webhook.rb
148
151
  - lib/mc/commands/lists.rb
149
152
  - lib/mc/commands/reports.rb
150
153
  - lib/mc/commands/search.rb