monkey_party 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +16 -2
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +9 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE +4 -2
  8. data/README.md +44 -0
  9. data/Rakefile +7 -56
  10. data/lib/monkey_party/base.rb +8 -4
  11. data/lib/monkey_party/error.rb +1 -0
  12. data/lib/monkey_party/list.rb +6 -5
  13. data/lib/monkey_party/subscriber.rb +1 -0
  14. data/lib/monkey_party/version.rb +4 -0
  15. data/lib/monkey_party.rb +26 -7
  16. data/monkey_party.gemspec +20 -80
  17. data/spec/cassettes/MonkeyParty_List/subscribing/handles_errors_gracefully.yml +135 -0
  18. data/spec/cassettes/MonkeyParty_List/subscribing/subscribes_someone_successfully.yml +205 -0
  19. data/spec/cassettes/MonkeyParty_List/unsubscribing/should_have_valid_subscribers.yml +205 -0
  20. data/spec/monkey_party/list_spec.rb +43 -0
  21. data/spec/monkey_party/subscriber_spec.rb +12 -0
  22. data/spec/spec_helper.rb +14 -0
  23. data/spec/support/credentials.rb.example +3 -0
  24. data/spec/support/vcr.rb +28 -0
  25. metadata +124 -117
  26. data/README.rdoc +0 -26
  27. data/VERSION.yml +0 -5
  28. data/features/create_and_add_api_key.feature +0 -21
  29. data/features/list_subscribe.feature +0 -13
  30. data/features/list_unsubscribe.feature +0 -14
  31. data/features/step_definitions/create_and_add_api_key_steps.rb +0 -45
  32. data/features/step_definitions/list_steps.rb +0 -17
  33. data/features/step_definitions/list_unsubscribe_steps.rb +0 -17
  34. data/features/support/env.rb +0 -4
  35. data/features/support/mailchimp/account.rb +0 -8
  36. data/features/support/mailchimp/account.yml.example +0 -2
  37. data/features/support/mailchimp/cleaner.rb +0 -3
  38. data/lib/monkey_party/account.rb +0 -48
  39. data/test/fixtures/batch_subscribe_failed.xml +0 -28
  40. data/test/fixtures/batch_subscribe_successful.xml +0 -12
  41. data/test/fixtures/batch_unsubscribe_failed.xml +0 -19
  42. data/test/fixtures/batch_unsubscribe_successful.xml +0 -12
  43. data/test/fixtures/lists_failed.xml +0 -11
  44. data/test/fixtures/lists_successful.xml +0 -16
  45. data/test/fixtures/login_failed.xml +0 -11
  46. data/test/fixtures/login_successful.xml +0 -8
  47. data/test/monkey_party/account_test.rb +0 -91
  48. data/test/monkey_party/error_test.rb +0 -18
  49. data/test/monkey_party/list_test.rb +0 -173
  50. data/test/monkey_party/subscriber_test.rb +0 -44
  51. data/test/test_helper.rb +0 -31
@@ -0,0 +1,205 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&method=lists
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 11 Mar 2012 03:00:54 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '938'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <struct key="0" type="array">
38
+
39
+ <id type="string">6ed27effda</id>
40
+
41
+ <web_id type="integer">47457</web_id>
42
+
43
+ <name type="string">Testing</name>
44
+
45
+ <date_created type="string">2012-03-11 03:00:40</date_created>
46
+
47
+ <member_count type="double">0</member_count>
48
+
49
+ <unsubscribe_count type="double">0</unsubscribe_count>
50
+
51
+ <cleaned_count type="double">0</cleaned_count>
52
+
53
+ <email_type_option type="boolean" />
54
+
55
+ <default_from_name type="string">Launchware</default_from_name>
56
+
57
+ <default_from_email type="string">dan.pickett+test@launchware.com</default_from_email>
58
+
59
+ <default_subject type="string">test</default_subject>
60
+
61
+ <default_language type="string">en</default_language>
62
+
63
+ <list_rating type="double">0</list_rating>
64
+
65
+ <member_count_since_send type="double">0</member_count_since_send>
66
+
67
+ <unsubscribe_count_since_send type="double">0</unsubscribe_count_since_send>
68
+
69
+ <cleaned_count_since_send type="double">0</cleaned_count_since_send>
70
+
71
+ </struct>
72
+
73
+ </MCAPI>'
74
+ http_version: '1.1'
75
+ recorded_at: Sun, 11 Mar 2012 03:00:54 GMT
76
+ - request:
77
+ method: get
78
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=true&update_existing=false&replace_interests=true&batch[0][EMAIL]=auser%40launchware.com
79
+ body:
80
+ encoding: US-ASCII
81
+ string: ''
82
+ headers:
83
+ connection:
84
+ - close
85
+ response:
86
+ status:
87
+ code: 200
88
+ message: OK
89
+ headers:
90
+ server:
91
+ - nginx/0.7.65
92
+ date:
93
+ - Sun, 11 Mar 2012 03:00:55 GMT
94
+ content-type:
95
+ - application/xml
96
+ connection:
97
+ - close
98
+ vary:
99
+ - Accept-Encoding
100
+ x-powered-by:
101
+ - PHP/5.3.2
102
+ set-cookie:
103
+ - _AVESTA_ENVIRONMENT=prod; path=/
104
+ content-length:
105
+ - '145'
106
+ body:
107
+ encoding: US-ASCII
108
+ string: ! '<MCAPI type="array">
109
+
110
+ <success_count type="integer">1</success_count>
111
+
112
+ <error_count type="integer">0</error_count>
113
+
114
+ <errors type="array" />
115
+
116
+ </MCAPI>'
117
+ http_version: '1.1'
118
+ recorded_at: Sun, 11 Mar 2012 03:00:55 GMT
119
+ - request:
120
+ method: get
121
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchUnsubscribe&delete_member=true&send_goodbye=true&send_notify=false&emails[0]=auser%40launchware.com
122
+ body:
123
+ encoding: US-ASCII
124
+ string: ''
125
+ headers:
126
+ connection:
127
+ - close
128
+ response:
129
+ status:
130
+ code: 200
131
+ message: OK
132
+ headers:
133
+ server:
134
+ - nginx/0.7.65
135
+ date:
136
+ - Sun, 11 Mar 2012 03:00:55 GMT
137
+ content-type:
138
+ - application/xml
139
+ connection:
140
+ - close
141
+ vary:
142
+ - Accept-Encoding
143
+ x-powered-by:
144
+ - PHP/5.3.2
145
+ set-cookie:
146
+ - _AVESTA_ENVIRONMENT=prod; path=/
147
+ content-length:
148
+ - '145'
149
+ body:
150
+ encoding: US-ASCII
151
+ string: ! '<MCAPI type="array">
152
+
153
+ <success_count type="integer">1</success_count>
154
+
155
+ <error_count type="integer">0</error_count>
156
+
157
+ <errors type="array" />
158
+
159
+ </MCAPI>'
160
+ http_version: '1.1'
161
+ recorded_at: Sun, 11 Mar 2012 03:00:55 GMT
162
+ - request:
163
+ method: get
164
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=false&update_existing=false&replace_interests=true&batch[0][EMAIL]=auser%40launchware.com
165
+ body:
166
+ encoding: US-ASCII
167
+ string: ''
168
+ headers:
169
+ connection:
170
+ - close
171
+ response:
172
+ status:
173
+ code: 200
174
+ message: OK
175
+ headers:
176
+ server:
177
+ - nginx/0.7.65
178
+ date:
179
+ - Sun, 11 Mar 2012 03:02:00 GMT
180
+ content-type:
181
+ - application/xml
182
+ connection:
183
+ - close
184
+ vary:
185
+ - Accept-Encoding
186
+ x-powered-by:
187
+ - PHP/5.3.2
188
+ set-cookie:
189
+ - _AVESTA_ENVIRONMENT=prod; path=/
190
+ content-length:
191
+ - '145'
192
+ body:
193
+ encoding: US-ASCII
194
+ string: ! '<MCAPI type="array">
195
+
196
+ <success_count type="integer">1</success_count>
197
+
198
+ <error_count type="integer">0</error_count>
199
+
200
+ <errors type="array" />
201
+
202
+ </MCAPI>'
203
+ http_version: '1.1'
204
+ recorded_at: Sun, 11 Mar 2012 03:02:00 GMT
205
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,205 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&method=lists
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ connection:
11
+ - close
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ server:
18
+ - nginx/0.7.65
19
+ date:
20
+ - Sun, 11 Mar 2012 03:00:57 GMT
21
+ content-type:
22
+ - application/xml
23
+ connection:
24
+ - close
25
+ vary:
26
+ - Accept-Encoding
27
+ x-powered-by:
28
+ - PHP/5.3.2
29
+ set-cookie:
30
+ - _AVESTA_ENVIRONMENT=prod; path=/
31
+ content-length:
32
+ - '938'
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '<MCAPI type="array">
36
+
37
+ <struct key="0" type="array">
38
+
39
+ <id type="string">6ed27effda</id>
40
+
41
+ <web_id type="integer">47457</web_id>
42
+
43
+ <name type="string">Testing</name>
44
+
45
+ <date_created type="string">2012-03-11 03:00:40</date_created>
46
+
47
+ <member_count type="double">0</member_count>
48
+
49
+ <unsubscribe_count type="double">0</unsubscribe_count>
50
+
51
+ <cleaned_count type="double">0</cleaned_count>
52
+
53
+ <email_type_option type="boolean" />
54
+
55
+ <default_from_name type="string">Launchware</default_from_name>
56
+
57
+ <default_from_email type="string">dan.pickett+test@launchware.com</default_from_email>
58
+
59
+ <default_subject type="string">test</default_subject>
60
+
61
+ <default_language type="string">en</default_language>
62
+
63
+ <list_rating type="double">0</list_rating>
64
+
65
+ <member_count_since_send type="double">0</member_count_since_send>
66
+
67
+ <unsubscribe_count_since_send type="double">0</unsubscribe_count_since_send>
68
+
69
+ <cleaned_count_since_send type="double">0</cleaned_count_since_send>
70
+
71
+ </struct>
72
+
73
+ </MCAPI>'
74
+ http_version: '1.1'
75
+ recorded_at: Sun, 11 Mar 2012 03:00:57 GMT
76
+ - request:
77
+ method: get
78
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchSubscribe&double_optin=false&update_existing=false&replace_interests=true&batch[0][EMAIL]=auser%40launchware.com
79
+ body:
80
+ encoding: US-ASCII
81
+ string: ''
82
+ headers:
83
+ connection:
84
+ - close
85
+ response:
86
+ status:
87
+ code: 200
88
+ message: OK
89
+ headers:
90
+ server:
91
+ - nginx/0.7.65
92
+ date:
93
+ - Sun, 11 Mar 2012 03:00:57 GMT
94
+ content-type:
95
+ - application/xml
96
+ connection:
97
+ - close
98
+ vary:
99
+ - Accept-Encoding
100
+ x-powered-by:
101
+ - PHP/5.3.2
102
+ set-cookie:
103
+ - _AVESTA_ENVIRONMENT=prod; path=/
104
+ content-length:
105
+ - '145'
106
+ body:
107
+ encoding: US-ASCII
108
+ string: ! '<MCAPI type="array">
109
+
110
+ <success_count type="integer">1</success_count>
111
+
112
+ <error_count type="integer">0</error_count>
113
+
114
+ <errors type="array" />
115
+
116
+ </MCAPI>'
117
+ http_version: '1.1'
118
+ recorded_at: Sun, 11 Mar 2012 03:00:57 GMT
119
+ - request:
120
+ method: get
121
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchUnsubscribe&delete_member=false&send_goodbye=true&send_notify=false&emails[0]=auser%40launchware.com
122
+ body:
123
+ encoding: US-ASCII
124
+ string: ''
125
+ headers:
126
+ connection:
127
+ - close
128
+ response:
129
+ status:
130
+ code: 200
131
+ message: OK
132
+ headers:
133
+ server:
134
+ - nginx/0.7.65
135
+ date:
136
+ - Sun, 11 Mar 2012 03:00:58 GMT
137
+ content-type:
138
+ - application/xml
139
+ connection:
140
+ - close
141
+ vary:
142
+ - Accept-Encoding
143
+ x-powered-by:
144
+ - PHP/5.3.2
145
+ set-cookie:
146
+ - _AVESTA_ENVIRONMENT=prod; path=/
147
+ content-length:
148
+ - '145'
149
+ body:
150
+ encoding: US-ASCII
151
+ string: ! '<MCAPI type="array">
152
+
153
+ <success_count type="integer">1</success_count>
154
+
155
+ <error_count type="integer">0</error_count>
156
+
157
+ <errors type="array" />
158
+
159
+ </MCAPI>'
160
+ http_version: '1.1'
161
+ recorded_at: Sun, 11 Mar 2012 03:00:58 GMT
162
+ - request:
163
+ method: get
164
+ uri: http://us4.api.mailchimp.com/1.2/?output=xml&apikey=<API KEY>&id=6ed27effda&method=listBatchUnsubscribe&delete_member=true&send_goodbye=true&send_notify=false&emails[0]=auser%40launchware.com
165
+ body:
166
+ encoding: US-ASCII
167
+ string: ''
168
+ headers:
169
+ connection:
170
+ - close
171
+ response:
172
+ status:
173
+ code: 200
174
+ message: OK
175
+ headers:
176
+ server:
177
+ - nginx/0.7.65
178
+ date:
179
+ - Sun, 11 Mar 2012 03:00:59 GMT
180
+ content-type:
181
+ - application/xml
182
+ connection:
183
+ - close
184
+ vary:
185
+ - Accept-Encoding
186
+ x-powered-by:
187
+ - PHP/5.3.2
188
+ set-cookie:
189
+ - _AVESTA_ENVIRONMENT=prod; path=/
190
+ content-length:
191
+ - '145'
192
+ body:
193
+ encoding: US-ASCII
194
+ string: ! '<MCAPI type="array">
195
+
196
+ <success_count type="integer">1</success_count>
197
+
198
+ <error_count type="integer">0</error_count>
199
+
200
+ <errors type="array" />
201
+
202
+ </MCAPI>'
203
+ http_version: '1.1'
204
+ recorded_at: Sun, 11 Mar 2012 03:00:59 GMT
205
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe MonkeyParty::List, :vcr do
4
+ let(:list_name) { "Testing" }
5
+ let(:list) { MonkeyParty::List.find_by_name(list_name) }
6
+ let(:subscriber) do
7
+ MonkeyParty::Subscriber.new("auser@launchware.com")
8
+ end
9
+
10
+ describe "subscribing" do
11
+ let(:bad_subscriber) do
12
+ MonkeyParty::Subscriber.new("badEmail")
13
+ end
14
+
15
+ it "subscribes someone successfully" do
16
+ subs = list.create_subscribers([subscriber], :double_optin => false)
17
+ subs[0].should be_valid
18
+
19
+ #clean up after yourself
20
+ list.destroy_subscribers([subs[0]], :delete_member => true)
21
+ end
22
+
23
+ it "handles errors gracefully" do
24
+ subs = list.create_subscribers([bad_subscriber])
25
+ subs[0].should_not be_valid
26
+ end
27
+
28
+ end
29
+
30
+ describe "unsubscribing" do
31
+ after(:each) do
32
+ list.destroy_subscribers([subscriber], :delete_member => true)
33
+ end
34
+
35
+ it 'should have valid subscribers' do
36
+ subs = list.create_subscribers([subscriber], :double_optin => false)
37
+ subs[0].should be_valid
38
+ subs = list.destroy_subscribers([subscriber])
39
+ subs[0].should be_valid
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe MonkeyParty::Subscriber do
4
+ let(:email) { "user@example.com" }
5
+ let(:subscriber) { MonkeyParty::Subscriber.new(email) }
6
+
7
+ it "serializes to a mailchimp hash" do
8
+ subscriber.to_mailchimp_hash.keys.should include("EMAIL")
9
+ subscriber.to_mailchimp_hash["EMAIL"].should eql(email)
10
+ end
11
+ end
12
+
@@ -0,0 +1,14 @@
1
+ require 'rspec'
2
+ require 'vcr'
3
+
4
+ require 'monkey_party'
5
+
6
+ require "pry"
7
+ Dir[File.dirname(__FILE__) + "/support/*.rb"].each{|f| require f }
8
+
9
+ RSpec.configure do |c|
10
+ # so we can use `:vcr` rather than `:vcr => true`;
11
+ # in RSpec 3 this will no longer be necessary.
12
+ c.treat_symbols_as_metadata_keys_with_true_values = true
13
+ end
14
+
@@ -0,0 +1,3 @@
1
+ MonkeyParty.api_key = '<your api key>'
2
+ MonkeyParty.data_center = 'us1'
3
+
@@ -0,0 +1,28 @@
1
+ mailchimp_matcher = lambda do |request_1, request_2|
2
+ uri_1 = URI(request_1.uri)
3
+ uri_2 = URI(request_2.uri)
4
+ api_key_phrase = /apikey=[^\&]*/
5
+
6
+ params_match = uri_1.query.gsub(api_key_phrase, "") == uri_2.query.gsub(api_key_phrase, "")
7
+ hosts_match = uri_1.host.gsub(/^us\d\./, "") == uri_2.host.gsub(/^us\d\./, "")
8
+ [
9
+ params_match,
10
+ hosts_match
11
+ ]
12
+ end
13
+
14
+ VCR.configure do |c|
15
+ c.cassette_library_dir = 'spec/cassettes'
16
+ c.hook_into :fakeweb
17
+ c.configure_rspec_metadata!
18
+ c.register_request_matcher :mailchimp_matcher do |req1, req2|
19
+ mailchimp_matcher.call(req1, req2)
20
+ end
21
+
22
+ c.default_cassette_options = {
23
+ :match_requests_on => [:method, :mailchimp_matcher],
24
+ :record => :new_episodes
25
+ }
26
+ c.filter_sensitive_data('<API KEY>') { MonkeyParty.api_key }
27
+ end
28
+