mc 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ desc 'Ecomm related actions'
2
+
3
+ command :ecomm do |c|
4
+ c.desc 'Import Ecommerce Order Information to be used for Segmentation'
5
+ c.command :add do |s|
6
+ s.flag :order_id
7
+ s.flag :campaign_id
8
+ s.flag :email_id
9
+ s.flag :email
10
+ s.flag :total
11
+ s.flag :order_date
12
+ s.flag :shipping
13
+ s.flag :tax
14
+ s.flag :store_id
15
+ s.flag :stoe_name
16
+
17
+ s.action do |global,options,args|
18
+ order = {}
19
+ order[:id] = options[:order_id]
20
+ order[:email_id] = options[:email_id]
21
+ order[:email] = options[:email]
22
+ order[:total] = options[:total]
23
+ order[:order_date] = options[:order_date]
24
+ order[:shipping] = options[:shipping]
25
+ order[:tax] = options[:tax]
26
+ order[:store_id] = options[:store_id]
27
+ order[:store_name] = options[:store_name]
28
+ order[:items] = [{:product_id => 500, :product_name => "Freddie Doll", :category_id => 1, :category_name => "Toys"}]
29
+
30
+ if @mailchimp.ecomm_order_add :order => order
31
+ puts "Order added!"
32
+ else
33
+ puts "Order not added. :("
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,69 @@
1
+ desc 'Export'
2
+ command :export do |c|
3
+ # list ( string apikey, string id, string status array segment, string since )
4
+ c.desc 'Exports/dumps members of a list and all of their associated details.'
5
+ c.command :list do |s|
6
+ c.desc 'List ID'
7
+ c.flag :id
8
+
9
+ c.flag :status
10
+
11
+ c.desc "Use either 'any' or 'all'"
12
+ c.flag :match, :default_value => 'all'
13
+
14
+ c.desc 'Condition in the format field,op,value'
15
+ c.flag :condition
16
+
17
+ s.action do |global,options,args|
18
+ id = get_required_argument(:id, options[:id], global[:default_list])
19
+
20
+ if options[:condition]
21
+ segment = {}
22
+ segment['match'] = options[:match]
23
+ field, op, value = options[:condition].split(',')
24
+ segment['conditions'] = [{:field => field, :op => op, :value => value}]
25
+ end
26
+
27
+ status = options[:status]
28
+
29
+ # segment = {}
30
+ # segment["match"] = "all"
31
+ # segment["conditions"] = [{:field => 'aim', :op => 'open', :value => 'b55303410e'}]
32
+
33
+ @mailchimp.export_list(:id => id, :status => status, :segment => segment).each do |subscriber|
34
+ puts subscriber
35
+ end
36
+ end
37
+ end
38
+
39
+ # ecommOrders ( string since )
40
+ c.desc 'Dumps all Ecommerce Orders for an account'
41
+ c.command :ecommm do |s|
42
+ c.desc 'Ecomm orders since a specific date'
43
+ c.flag :since
44
+
45
+ s.action do |global,options,args|
46
+ @mailchimp.export_ecomm_orders.each do |order|
47
+ puts order
48
+ end
49
+ end
50
+ end
51
+
52
+ # campaignSubscriberActivity ( string apikey, string id, boolean include_empty, string since )
53
+ c.command :activity do |s|
54
+ c.desc 'Campaign ID'
55
+ c.flag :cid
56
+
57
+ c.desc 'Export all subscribers even if they have no activity'
58
+ c.switch :include_empty, :negatable => false
59
+
60
+ s.action do |global,options,args|
61
+ cid = options[:cid] || get_last_campaign_id
62
+
63
+ @mailchimp.export_campaign_subscriber_activity(:id => cid).each do |activity|
64
+ puts activity
65
+ end
66
+ end
67
+ end
68
+ end
69
+
@@ -0,0 +1,11 @@
1
+ desc 'Manage images and documents that are in your account'
2
+
3
+ command :gallery do |c|
4
+ # list(string apikey, struct opts)
5
+ c.desc 'Return a section of the image gallery'
6
+ c.command :list do |s|
7
+ s.action do |global,options,args|
8
+ @output.standard @mailchimp_cached.gallery_list['data'], :fields => [{"full path" => {:display_method => :full, :width => 100}}]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,63 @@
1
+ desc 'Basic admin funtions'
2
+ command :helper do |c|
3
+ c.desc 'View API key currently configured'
4
+ c.command :apikey do |apikey|
5
+ apikey.action do |global,options,args|
6
+ puts global[:apikey]
7
+ end
8
+ end
9
+
10
+ # === Actual MailChimp API Calls below ===
11
+
12
+ # helper/account-details (string apikey, array exclude)
13
+ c.desc 'Retrieve lots of account information'
14
+ c.command :account do |s|
15
+ s.action do |global,options,args|
16
+ @output.as_hash @mailchimp_cached.helper_account_details
17
+ end
18
+ end
19
+
20
+ # helper/campaigns-for-email (string apikey, struct email, struct options)
21
+ c.desc 'Retrieve minimal data for all Campaigns a member was sent'
22
+ c.command 'campaigns-for-email' do |s|
23
+ s.action do |global,options,args|
24
+ emails = create_email_struct(required_argument("Need to provide an email address.", args))
25
+ @output.standard @mailchimp_cached.helper_campaigns_for_email(:email => emails.first), :fields => [:id, {:title => {:width => 50}}, :send_time]
26
+ end
27
+ end
28
+
29
+ # helper/chimp-chatter (string apikey)
30
+ c.desc 'See the current Chimp Chatter messages.'
31
+ c.command :chatter do |s|
32
+ s.action do |global,options,args|
33
+ # get rid of all the crap in the chatter msgs so they are useful
34
+ message = lambda{|m| m['message'].gsub(/ - Nice!.*few/, '').gsub(/ - Bummer.*:/, ':').gsub(/ - People.*:/, ':').gsub(/"/, '')}
35
+
36
+ @output.standard @mailchimp_cached.helper_chimp_chatter.reverse, :fields => [:update_time, {:message => {:width => 100, :display_method => message}}]
37
+ end
38
+ end
39
+
40
+ # helper/lists-for-email (string apikey, struct email)
41
+ c.desc 'Retrieve minimal List data for all lists a member is subscribed to.'
42
+ c.command 'lists-for-email' do |s|
43
+ s.action do |global,options,args|
44
+ emails = create_email_struct(required_argument("Need to provide an email address.", args))
45
+ @output.standard @mailchimp_cached.helper_lists_for_email :email => emails.first
46
+ end
47
+ end
48
+
49
+ c.desc 'Ping MailChimp to make sure all is okay.'
50
+ c.command :ping do |s|
51
+ s.action do |global,options,args|
52
+ puts @mailchimp.helper_ping['msg']
53
+ end
54
+ end
55
+
56
+ # helper/verified-domains (string apikey)
57
+ c.desc 'Retrieve all domain verification records for an account'
58
+ c.command :verified do |s|
59
+ s.action do |global,options,args|
60
+ @output.standard @mailchimp_cached.helper_verified_domains
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,94 @@
1
+ desc 'View information about lists and subscribers'
2
+ arg_name 'Describe arguments to lists here'
3
+
4
+ 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
13
+
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
+ s.action do |global,options,args|
25
+ id = required_argument(:id, options[:id], global[:list])
26
+ @output.standard @mailchimp_cached.lists_activity(:id => id)
27
+ end
28
+ end
29
+
30
+ c.desc "Retrieve the clients that the list's subscribers have been tagged as being used based on user agents seen."
31
+ c.command :clients do |s|
32
+ s.action do |global,options,args|
33
+ id = get_required_argument(:id, options[:id], global[:list])
34
+
35
+ results = @mailchimp_cached.lists_clients(:id => id)
36
+ if global[:output]
37
+ @output.as_hash results
38
+ else
39
+ percent = lambda{|i| i['percent'].round(2)}
40
+ puts "#{'='*14} DESKTOP #{'='*14}"
41
+ @output.standard results['desktop']['clients'], :fields => [:members, :client, {:percent => {:display_method => percent}}]
42
+ puts "\n#{'='*14} MOBILE #{'='*14}"
43
+ @output.standard results['mobile']['clients'], :fields => [:members, :client, {:percent => {:display_method => percent}}]
44
+ end
45
+ end
46
+ end
47
+
48
+ c.desc 'Get all of the merge variables for a list.'
49
+ c.command 'merge-vars' do |s|
50
+ 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
+ end
54
+ end
55
+
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
59
+
60
+ 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]
63
+ end
64
+ end
65
+
66
+ c.desc 'Get information about one particular member.'
67
+ c.command 'member-info' do |s|
68
+ s.action do |global,options,args|
69
+ id = get_required_argument(:id, options[:id], global[:list])
70
+ emails = create_email_struct(required_argument("Need to provide one or more email addresses.", args))
71
+
72
+ @output.as_hash @mailchimp_cached.lists_member_info(:id => id, :emails => emails)
73
+ end
74
+ end
75
+
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
79
+
80
+ 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]
83
+ end
84
+ end
85
+
86
+ c.desc 'Access the Growth History by Month for a given list.'
87
+ c.command :growth do |s|
88
+ 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)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,183 @@
1
+ desc 'Reports'
2
+ command :reports do |c|
3
+
4
+ # reports/abuse (string apikey, string cid, struct opts)
5
+ c.desc 'Get all email addresses that complained about a given campaign'
6
+ c.command :abuse do |s|
7
+ s.action do |global,options,args|
8
+ not_implemented
9
+ end
10
+ end
11
+
12
+ # reports/advice (string apikey, string cid)
13
+ c.desc 'Retrieve the text presented in our app for how a campaign performed and any advice we may have for you'
14
+ c.command :advice do |s|
15
+ s.action do |global,options,args|
16
+ cid = options[:cid] || get_last_campaign_id
17
+ #cid = @mailchimp.campaigns_list(:limit => 1, :sort_field => "send_time")["data"].first["id"]
18
+ @output.as_hash @mailchimp_cached.reports_advice :cid => cid
19
+ end
20
+ end
21
+
22
+ # reports/bounce-message (string apikey, string cid, struct email)
23
+ 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
+ c.command :bounce do |s|
25
+ s.action do |global,options,args|
26
+ not_implemented
27
+ end
28
+ end
29
+
30
+ # 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'
32
+ c.command :bounces do |s|
33
+ s.action do |global,options,args|
34
+ cid = options[:cid] || get_last_campaign_id
35
+
36
+ results = @mailchimp_cached.reports_bounce_messages(:cid => cid)
37
+ if global[:output]
38
+ @output.standard results
39
+ else
40
+ if results['total'].to_i > 0
41
+ puts "BOUNCE MSGS FOR LAST/SELECTED CAMPAIGN (#{results['total']})"
42
+ results['data'].each do |bounce|
43
+ puts "#{'='*50}".red
44
+ puts "Subscriber: #{bounce['member']['email']}"
45
+ puts "Date: #{bounce['date']}\n\n"
46
+ puts bounce['message'].green
47
+ puts "\n"
48
+ end
49
+ else
50
+ puts "No bounce messages for the last/selected campaign."
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ # reports/click-detail (string apikey, string cid, int tid, struct opts)
57
+ 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|
59
+ s.action do |global,options,args|
60
+ not_implemented
61
+ end
62
+ end
63
+
64
+ # reports/clicks (string apikey, string cid)
65
+ c.desc 'The urls tracked and their click counts for a given campaign.'
66
+ c.command :clicks do |s|
67
+ s.action do |global,options,args|
68
+ cid = options[:cid] || get_last_campaign_id
69
+ @output.standard @mailchimp_cached.reports_clicks(:cid => cid)['total'], :fields => [{:url => {:width => 80}}, :clicks, :unique]
70
+ end
71
+ end
72
+
73
+ # reports/domain-performance (string apikey, string cid)
74
+ c.desc 'Get the top 5 performing email domains for this campaign.'
75
+ c.command :domains do |s|
76
+ s.action do |global,options,args|
77
+ cid = options[:cid] || get_last_campaign_id
78
+ @output.standard @mailchimp_cached.reports_domain_performance :cid => cid
79
+ end
80
+ end
81
+
82
+ # reports/ecomm-orders (string apikey, string cid, struct opts)
83
+ c.desc 'Retrieve the Ecommerce Orders tracked by campaignEcommOrderAdd()'
84
+ c.command :ecomm do |s|
85
+ s.action do |global,options,args|
86
+ not_implemented
87
+ end
88
+ end
89
+
90
+ # reports/eepurl (string apikey, string cid)
91
+ c.desc 'Retrieve the eepurl stats from the web/Twitter mentions for this campaign'
92
+ c.command :eepurl do |s|
93
+ s.action do |global,options,args|
94
+ cid = options[:cid] || get_last_campaign_id
95
+ @output.standard @mailchimp_cached.reports_eepurl :cid => cid
96
+ end
97
+ end
98
+
99
+ # reports/geo-opens (string apikey, string cid)
100
+ c.desc 'Retrieve the countries/regions and number of opens tracked for each. Email address are not returned.'
101
+ c.command :geo do |s|
102
+ s.action do |global,options,args|
103
+ cid = options[:cid] || get_last_campaign_id
104
+ @output.standard @mailchimp_cached.reports_geo_opens :cid => cid
105
+ end
106
+ end
107
+
108
+ # reports/google-analytics (string apikey, string cid)
109
+ c.desc 'Retrieve the Google Analytics data we have collected for this campaign.'
110
+ c.command :ga do |s|
111
+ s.action do |global,options,args|
112
+ cid = options[:cid] || get_last_campaign_id
113
+ @output.standard @mailchimp_cached.reports_google_analytics :cid => cid
114
+ end
115
+ end
116
+
117
+ # reports/member-activity (string apikey, string cid, array emails)
118
+ 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|
120
+ s.action do |global,options,args|
121
+ not_implemented
122
+ end
123
+ end
124
+
125
+ # reports/not-opened (string apikey, string cid, struct opts)
126
+ c.desc 'Retrieve the list of email addresses that did not open a given campaign'
127
+ c.command :not_opened do |s|
128
+ s.action do |global,options,args|
129
+ not_implemented
130
+ end
131
+ end
132
+
133
+ # reports/opened (string apikey, string cid, struct opts)
134
+ c.desc 'Retrieve the list of email addresses that opened a given campaign with how many times they opened'
135
+ c.command :opened do |s|
136
+ s.action do |global,options,args|
137
+ not_implemented
138
+ end
139
+ end
140
+
141
+ # reports/sent-to (string apikey, string cid, struct opts)
142
+ c.desc 'Get email addresses the campaign was sent to'
143
+ c.command :sent_to do |s|
144
+ s.action do |global,options,args|
145
+ not_implemented
146
+ end
147
+ end
148
+
149
+ # reports/share (string apikey, string cid, array opts)
150
+ 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
+ c.command :share do |s|
152
+ s.action do |global,options,args|
153
+ cid = options[:cid] || get_last_campaign_id
154
+
155
+ results = @mailchimp_cached.reports_share(:cid => cid)
156
+ if global[:output]
157
+ @output.standard results
158
+ else
159
+ puts results['title']
160
+ puts "#{'='*results['title'].size}"
161
+ puts "URL: #{results['url']}"
162
+ puts "PASSWORD: #{results['password']}"
163
+ puts "SECURE URL: #{results['secure_url']}"
164
+ end
165
+ end
166
+ end
167
+
168
+ # reports/summary (string apikey, string cid)
169
+ c.desc 'Retrieve relevant aggregate campaign statistics (opens, bounces, clicks, etc.)'
170
+ c.command :summary do |s|
171
+ s.action do |global,options,args|
172
+ not_implemented
173
+ end
174
+ end
175
+
176
+ # reports/unsubscribes (string apikey, string cid, struct opts)
177
+ c.desc 'Get all unsubscribed email addresses for a given campaign'
178
+ c.command :unsubscribes do |s|
179
+ s.action do |global,options,args|
180
+ not_implemented
181
+ end
182
+ end
183
+ end