mailchimp_api_v3 0.0.0 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -6
- data/circle.yml +5 -0
- data/lib/{mailchimp → mailchimp_api_v3}/account.rb +2 -3
- data/lib/{mailchimp → mailchimp_api_v3}/client/remote.rb +5 -6
- data/lib/{mailchimp → mailchimp_api_v3}/client.rb +15 -10
- data/lib/{mailchimp → mailchimp_api_v3}/collection/paging.rb +1 -1
- data/lib/{mailchimp → mailchimp_api_v3}/collection.rb +16 -9
- data/lib/{mailchimp → mailchimp_api_v3}/exception.rb +13 -9
- data/lib/mailchimp_api_v3/instance.rb +62 -0
- data/lib/mailchimp_api_v3/interest.rb +10 -0
- data/lib/{mailchimp → mailchimp_api_v3}/interest_categories.rb +4 -4
- data/lib/mailchimp_api_v3/interest_category.rb +16 -0
- data/lib/{mailchimp → mailchimp_api_v3}/interests.rb +4 -4
- data/lib/mailchimp_api_v3/list.rb +26 -0
- data/lib/{mailchimp → mailchimp_api_v3}/lists.rb +4 -4
- data/lib/mailchimp_api_v3/member.rb +55 -0
- data/lib/{mailchimp → mailchimp_api_v3}/members.rb +4 -4
- data/lib/mailchimp_api_v3/version.rb +3 -0
- data/mailchimp_api_v3.gemspec +5 -5
- data/spec/fixtures/cassettes/mailchimp.yml +335 -73
- data/spec/fixtures/cassettes/members.yml +16 -16
- data/spec/mailchimp/account_spec.rb +5 -5
- data/spec/mailchimp/client_spec.rb +10 -10
- data/spec/mailchimp/exception_spec.rb +22 -14
- data/spec/mailchimp/interest_categories_spec.rb +10 -10
- data/spec/mailchimp/interest_category_spec.rb +5 -5
- data/spec/mailchimp/interest_spec.rb +4 -4
- data/spec/mailchimp/interests_spec.rb +8 -8
- data/spec/mailchimp/list_spec.rb +25 -6
- data/spec/mailchimp/lists_spec.rb +4 -4
- data/spec/mailchimp/member_spec.rb +28 -4
- data/spec/mailchimp/members_spec.rb +5 -5
- data/spec/mailchimp_spec.rb +6 -10
- data/spec/support/api_key.rb +8 -4
- data/spec/support/vcr_setup.rb +1 -0
- metadata +32 -20
- data/lib/mailchimp/instance.rb +0 -31
- data/lib/mailchimp/interest.rb +0 -9
- data/lib/mailchimp/interest_category.rb +0 -19
- data/lib/mailchimp/list.rb +0 -20
- data/lib/mailchimp/member.rb +0 -15
- data/lib/mailchimp/version.rb +0 -3
- data/lib/mailchimp.rb +0 -8
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https
|
5
|
+
uri: https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/lists?count=500&exclude_fields=lists._links&offset=0
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -12,7 +12,7 @@ http_interactions:
|
|
12
12
|
Accept-Encoding:
|
13
13
|
- gzip, deflate
|
14
14
|
Authorization:
|
15
|
-
- apikey
|
15
|
+
- apikey <%= ENV['MAILCHIMP_API_KEY'] %>
|
16
16
|
User-Agent:
|
17
17
|
- Mailchimp API v3 Ruby gem https://rubygems.org/gems/mailchimp_api_v3
|
18
18
|
response:
|
@@ -29,7 +29,7 @@ http_interactions:
|
|
29
29
|
X-Request-Id:
|
30
30
|
- 652e3f6c-ccf1-41e9-b759-a18c7732e8a7
|
31
31
|
Link:
|
32
|
-
- <https
|
32
|
+
- <https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Lists/Collection.json>; rel="describedBy"
|
33
33
|
Vary:
|
34
34
|
- Accept-Encoding
|
35
35
|
Date:
|
@@ -41,12 +41,12 @@ http_interactions:
|
|
41
41
|
string: '{"lists":[{"id":"e73f5910ca","name":"My first list","contact":{"company":"InSite
|
42
42
|
Arts","address1":"300 Burdett Road","address2":"London","city":"London","state":"","zip":"E14
|
43
43
|
7DQ","country":"262","phone":"07917153555"},"permission_reminder":"Opt-in
|
44
|
-
only","use_archive_bar":true,"campaign_defaults":{"from_name":"Sam Sayers","from_email":"sam@sayers.cc","subject":"","language":"en"},"notify_on_subscribe":"","notify_on_unsubscribe":"","date_created":"2015-06-27T14:49:18+00:00","list_rating":0,"email_type_option":false,"subscribe_url_short":"http://eepurl.com/brGTO9","subscribe_url_long":"http://insitearts.us11.list-manage.com/subscribe?u=1dbca289fd41b54838bcbb501&id=e73f5910ca","beamer_address":"us11-6692a2b3c3-bcd2a8b144@inbound.mailchimp.com","visibility":"pub","modules":[],"stats":{"member_count":2,"unsubscribe_count":0,"cleaned_count":0,"member_count_since_send":2,"unsubscribe_count_since_send":0,"cleaned_count_since_send":0,"campaign_count":0,"campaign_last_sent":"","merge_field_count":2,"avg_sub_rate":0,"avg_unsub_rate":0,"target_sub_rate":0,"open_rate":0,"click_rate":0,"last_sub_date":"2015-06-27T14:50:39+00:00","last_unsub_date":""}}],"_links":[{"rel":"self","href":"https
|
44
|
+
only","use_archive_bar":true,"campaign_defaults":{"from_name":"Sam Sayers","from_email":"sam@sayers.cc","subject":"","language":"en"},"notify_on_subscribe":"","notify_on_unsubscribe":"","date_created":"2015-06-27T14:49:18+00:00","list_rating":0,"email_type_option":false,"subscribe_url_short":"http://eepurl.com/brGTO9","subscribe_url_long":"http://insitearts.us11.list-manage.com/subscribe?u=1dbca289fd41b54838bcbb501&id=e73f5910ca","beamer_address":"us11-6692a2b3c3-bcd2a8b144@inbound.mailchimp.com","visibility":"pub","modules":[],"stats":{"member_count":2,"unsubscribe_count":0,"cleaned_count":0,"member_count_since_send":2,"unsubscribe_count_since_send":0,"cleaned_count_since_send":0,"campaign_count":0,"campaign_last_sent":"","merge_field_count":2,"avg_sub_rate":0,"avg_unsub_rate":0,"target_sub_rate":0,"open_rate":0,"click_rate":0,"last_sub_date":"2015-06-27T14:50:39+00:00","last_unsub_date":""}}],"_links":[{"rel":"self","href":"https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/lists","method":"GET","targetSchema":"https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Lists/Collection.json"},{"rel":"parent","href":"https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/","method":"GET","targetSchema":"https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Root.json"},{"rel":"create","href":"https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/lists","method":"POST","schema":"https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Lists/Instance.json"}],"total_items":1}'
|
45
45
|
http_version:
|
46
46
|
recorded_at: Wed, 01 Jul 2015 14:30:32 GMT
|
47
47
|
- request:
|
48
48
|
method: get
|
49
|
-
uri: https
|
49
|
+
uri: https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/lists/e73f5910ca/members?count=10&exclude_fields=members._links&offset=0
|
50
50
|
body:
|
51
51
|
encoding: US-ASCII
|
52
52
|
string: ''
|
@@ -56,7 +56,7 @@ http_interactions:
|
|
56
56
|
Accept-Encoding:
|
57
57
|
- gzip, deflate
|
58
58
|
Authorization:
|
59
|
-
- apikey
|
59
|
+
- apikey <%= ENV['MAILCHIMP_API_KEY'] %>
|
60
60
|
User-Agent:
|
61
61
|
- Mailchimp API v3 Ruby gem https://rubygems.org/gems/mailchimp_api_v3
|
62
62
|
response:
|
@@ -73,7 +73,7 @@ http_interactions:
|
|
73
73
|
X-Request-Id:
|
74
74
|
- acf5f935-1ae1-4851-ad92-357d60b3ff2a
|
75
75
|
Link:
|
76
|
-
- <https
|
76
|
+
- <https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Lists/Members/Collection.json>;
|
77
77
|
rel="describedBy"
|
78
78
|
Vary:
|
79
79
|
- Accept-Encoding
|
@@ -105,7 +105,7 @@ http_interactions:
|
|
105
105
|
recorded_at: Wed, 01 Jul 2015 14:30:32 GMT
|
106
106
|
- request:
|
107
107
|
method: get
|
108
|
-
uri: https
|
108
|
+
uri: https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/lists/e73f5910ca/members?count=10&exclude_fields=members._links&offset=10
|
109
109
|
body:
|
110
110
|
encoding: US-ASCII
|
111
111
|
string: ''
|
@@ -115,7 +115,7 @@ http_interactions:
|
|
115
115
|
Accept-Encoding:
|
116
116
|
- gzip, deflate
|
117
117
|
Authorization:
|
118
|
-
- apikey
|
118
|
+
- apikey <%= ENV['MAILCHIMP_API_KEY'] %>
|
119
119
|
User-Agent:
|
120
120
|
- Mailchimp API v3 Ruby gem https://rubygems.org/gems/mailchimp_api_v3
|
121
121
|
response:
|
@@ -132,7 +132,7 @@ http_interactions:
|
|
132
132
|
X-Request-Id:
|
133
133
|
- acf5f935-1ae1-4851-ad92-357d60b3ff2a
|
134
134
|
Link:
|
135
|
-
- <https
|
135
|
+
- <https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Lists/Members/Collection.json>;
|
136
136
|
rel="describedBy"
|
137
137
|
Vary:
|
138
138
|
- Accept-Encoding
|
@@ -164,7 +164,7 @@ http_interactions:
|
|
164
164
|
recorded_at: Wed, 01 Jul 2015 14:30:32 GMT
|
165
165
|
- request:
|
166
166
|
method: get
|
167
|
-
uri: https
|
167
|
+
uri: https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/lists/e73f5910ca/members?count=10&exclude_fields=members._links&offset=20
|
168
168
|
body:
|
169
169
|
encoding: US-ASCII
|
170
170
|
string: ''
|
@@ -174,7 +174,7 @@ http_interactions:
|
|
174
174
|
Accept-Encoding:
|
175
175
|
- gzip, deflate
|
176
176
|
Authorization:
|
177
|
-
- apikey
|
177
|
+
- apikey <%= ENV['MAILCHIMP_API_KEY'] %>
|
178
178
|
User-Agent:
|
179
179
|
- Mailchimp API v3 Ruby gem https://rubygems.org/gems/mailchimp_api_v3
|
180
180
|
response:
|
@@ -191,7 +191,7 @@ http_interactions:
|
|
191
191
|
X-Request-Id:
|
192
192
|
- acf5f935-1ae1-4851-ad92-357d60b3ff2a
|
193
193
|
Link:
|
194
|
-
- <https
|
194
|
+
- <https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Lists/Members/Collection.json>;
|
195
195
|
rel="describedBy"
|
196
196
|
Vary:
|
197
197
|
- Accept-Encoding
|
@@ -223,7 +223,7 @@ http_interactions:
|
|
223
223
|
recorded_at: Wed, 01 Jul 2015 14:30:32 GMT
|
224
224
|
- request:
|
225
225
|
method: get
|
226
|
-
uri: https
|
226
|
+
uri: https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/3.0/lists/e73f5910ca/members?count=10&exclude_fields=members._links&offset=30
|
227
227
|
body:
|
228
228
|
encoding: US-ASCII
|
229
229
|
string: ''
|
@@ -233,7 +233,7 @@ http_interactions:
|
|
233
233
|
Accept-Encoding:
|
234
234
|
- gzip, deflate
|
235
235
|
Authorization:
|
236
|
-
- apikey
|
236
|
+
- apikey <%= ENV['MAILCHIMP_API_KEY'] %>
|
237
237
|
User-Agent:
|
238
238
|
- Mailchimp API v3 Ruby gem https://rubygems.org/gems/mailchimp_api_v3
|
239
239
|
response:
|
@@ -250,7 +250,7 @@ http_interactions:
|
|
250
250
|
X-Request-Id:
|
251
251
|
- acf5f935-1ae1-4851-ad92-357d60b3ff2a
|
252
252
|
Link:
|
253
|
-
- <https
|
253
|
+
- <https://<%= ENV['MAILCHIMP_DC'] %>.api.mailchimp.com/schema/3.0/Lists/Members/Collection.json>;
|
254
254
|
rel="describedBy"
|
255
255
|
Vary:
|
256
256
|
- Accept-Encoding
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe MailchimpAPIV3::Account, vcr: { cassette_name: 'mailchimp' } do
|
6
6
|
it 'is the expected class' do
|
7
|
-
expect(
|
7
|
+
expect(MailchimpAPIV3.connect.account).to be_a MailchimpAPIV3::Account
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'has a name' do
|
11
|
-
expect(
|
11
|
+
expect(MailchimpAPIV3.connect.account.name).to eq 'InSite Arts'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has an id' do
|
15
|
-
expect(
|
15
|
+
expect(MailchimpAPIV3.connect.account.id).to eq '1dbca289fd41b54838bcbb501'
|
16
16
|
end
|
17
17
|
end
|
@@ -1,42 +1,42 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe MailchimpAPIV3::Client, vcr: { cassette_name: 'mailchimp' } do
|
6
6
|
context 'unauthorized API key' do
|
7
7
|
let(:bad_key) { 'xxxxxxxxxx-us11' }
|
8
8
|
|
9
9
|
it 'raises an exception if we try to get data' do
|
10
|
-
expect {
|
10
|
+
expect { MailchimpAPIV3::Client.new(bad_key).account }.to raise_error MailchimpAPIV3::Exception::APIKeyError
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'says it is not connected' do
|
14
|
-
expect(
|
14
|
+
expect(MailchimpAPIV3::Client.new(bad_key).connected?).to be_falsey
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'valid API key' do
|
19
19
|
it 'says it is connected' do
|
20
|
-
expect(
|
20
|
+
expect(MailchimpAPIV3::Client.new.connected?).to be_truthy
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'is the expected class' do
|
24
|
-
expect(
|
24
|
+
expect(MailchimpAPIV3::Client.new).to be_a MailchimpAPIV3::Client
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'has an account method' do
|
28
|
-
expect(
|
28
|
+
expect(MailchimpAPIV3::Client.new.account).to be_a MailchimpAPIV3::Account
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'has a lists collection' do
|
32
|
-
lists =
|
32
|
+
lists = MailchimpAPIV3::Client.new.lists
|
33
33
|
expect(lists).to be_an Array
|
34
|
-
expect(lists.sample).to be_a
|
34
|
+
expect(lists.sample).to be_a MailchimpAPIV3::List
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'problems we can retry the request for' do
|
39
|
-
let(:client) {
|
39
|
+
let(:client) { MailchimpAPIV3::Client.new }
|
40
40
|
|
41
41
|
it 'eventually raises the exception' do
|
42
42
|
allow(client).to receive(:remote_no_payload).and_raise SocketError.new('test message')
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe MailchimpAPIV3::Exception::APIKeyError, vcr: { cassette_name: 'mailchimp' } do
|
6
6
|
let(:bad_key) { 'xxxxxxxxxx-us11' }
|
7
7
|
|
8
8
|
it 'raises an exception if the API key is not valid' do
|
9
|
-
expect {
|
10
|
-
expect(e).to be_a
|
9
|
+
expect { MailchimpAPIV3.connect(bad_key).account }.to raise_error { |e|
|
10
|
+
expect(e).to be_a MailchimpAPIV3::Exception::APIKeyError
|
11
11
|
expect(e.type).to eq 'http://kb.mailchimp.com/api/error-docs/401-api-key-invalid'
|
12
12
|
expect(e.title).to eq 'API Key Invalid'
|
13
13
|
expect(e.status).to eq 401
|
@@ -16,30 +16,38 @@ describe Mailchimp::Exception::APIKeyError, vcr: { cassette_name: 'mailchimp' }
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'does not raise an exception if the API key is valid' do
|
19
|
-
expect {
|
19
|
+
expect { MailchimpAPIV3.connect.account }.not_to raise_error
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
24
|
-
let(:account) {
|
23
|
+
describe MailchimpAPIV3::Exception::UnknownAttribute, vcr: { cassette_name: 'mailchimp' } do
|
24
|
+
let(:account) { MailchimpAPIV3.connect.account }
|
25
25
|
|
26
26
|
it 'returns a known attribute' do
|
27
27
|
expect { account.name }.not_to raise_error
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'fails if we ask for an unknown attribute' do
|
31
|
-
expect { account.blarbleferry }.to raise_error
|
31
|
+
expect { account.blarbleferry }.to raise_error MailchimpAPIV3::Exception::UnknownAttribute
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe
|
36
|
-
|
35
|
+
describe MailchimpAPIV3::Exception::BadRequest do
|
36
|
+
it 'raises a Duplicate exception if the message says so' do
|
37
|
+
data = { 'detail' => 'The thing already exists, idiot' }
|
38
|
+
expect { MailchimpAPIV3::Exception.parse_invalid_resource_exception data }
|
39
|
+
.to raise_error MailchimpAPIV3::Exception::Duplicate
|
40
|
+
end
|
37
41
|
|
38
|
-
it '
|
39
|
-
|
42
|
+
it 'raises a MissingField exception if the message says so' do
|
43
|
+
data = { 'detail' => 'The thing can\'t be blank, idiot' }
|
44
|
+
expect { MailchimpAPIV3::Exception.parse_invalid_resource_exception data }
|
45
|
+
.to raise_error MailchimpAPIV3::Exception::MissingField
|
40
46
|
end
|
41
47
|
|
42
|
-
it '
|
43
|
-
|
48
|
+
it 'raises a BadRequest exception otherwise' do
|
49
|
+
data = { 'detail' => 'The thing is an idiot' }
|
50
|
+
expect { MailchimpAPIV3::Exception.parse_invalid_resource_exception data }
|
51
|
+
.to raise_error MailchimpAPIV3::Exception::BadRequest
|
44
52
|
end
|
45
53
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:list) {
|
5
|
+
describe MailchimpAPIV3::List::InterestCategories, vcr: { cassette_name: 'mailchimp' } do
|
6
|
+
let(:list) { MailchimpAPIV3.connect.lists.first }
|
7
7
|
let(:interest_categories) { list.interest_categories }
|
8
8
|
|
9
9
|
it 'is the expected class' do
|
10
|
-
expect(interest_categories).to be_a
|
10
|
+
expect(interest_categories).to be_a MailchimpAPIV3::List::InterestCategories
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'has a count' do
|
@@ -16,8 +16,8 @@ describe Mailchimp::List::InterestCategories, vcr: { cassette_name: 'mailchimp'
|
|
16
16
|
|
17
17
|
it 'finds a matching instance' do
|
18
18
|
data = { 'title' => 'Colors' }
|
19
|
-
interest_category = interest_categories.
|
20
|
-
expect(interest_category).to be_a
|
19
|
+
interest_category = interest_categories.find_by data
|
20
|
+
expect(interest_category).to be_a MailchimpAPIV3::List::InterestCategory
|
21
21
|
expect(interest_category.id).to eq '2ce011eb68'
|
22
22
|
end
|
23
23
|
|
@@ -26,13 +26,13 @@ describe Mailchimp::List::InterestCategories, vcr: { cassette_name: 'mailchimp'
|
|
26
26
|
it 'can add a new instance' do
|
27
27
|
data = { 'title' => 'Days', 'type' => 'checkboxes' }
|
28
28
|
interest_category = interest_categories.create data
|
29
|
-
expect(interest_category).to be_a
|
29
|
+
expect(interest_category).to be_a MailchimpAPIV3::List::InterestCategory
|
30
30
|
expect(interest_category.title).to eq 'Days'
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'fails adding an instance with the same details' do
|
34
34
|
data = { 'title' => 'Colors', 'type' => 'checkboxes' }
|
35
|
-
expect { interest_categories.create data }.to raise_error
|
35
|
+
expect { interest_categories.create data }.to raise_error MailchimpAPIV3::Exception::Duplicate
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -40,14 +40,14 @@ describe Mailchimp::List::InterestCategories, vcr: { cassette_name: 'mailchimp'
|
|
40
40
|
it 'finds an instance with the same details' do
|
41
41
|
data = { 'title' => 'Colors', 'type' => 'checkboxes' }
|
42
42
|
interest_category = interest_categories.first_or_create data
|
43
|
-
expect(interest_category).to be_a
|
43
|
+
expect(interest_category).to be_a MailchimpAPIV3::List::InterestCategory
|
44
44
|
expect(interest_category.title).to eq 'Colors'
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'creates a new instance if one does not yet exist' do
|
48
48
|
data = { 'title' => 'Sex', 'type' => 'radio' }
|
49
49
|
interest_category = interest_categories.first_or_create data
|
50
|
-
expect(interest_category).to be_a
|
50
|
+
expect(interest_category).to be_a MailchimpAPIV3::List::InterestCategory
|
51
51
|
expect(interest_category.title).to eq 'Sex'
|
52
52
|
end
|
53
53
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:lists) {
|
5
|
+
describe MailchimpAPIV3::List::InterestCategory, vcr: { cassette_name: 'mailchimp' } do
|
6
|
+
let(:lists) { MailchimpAPIV3.connect.lists }
|
7
7
|
let(:list) { lists.first }
|
8
8
|
let(:interest_category) { list.interest_categories.first }
|
9
9
|
|
10
10
|
it 'is the expected class' do
|
11
|
-
expect(interest_category).to be_a
|
11
|
+
expect(interest_category).to be_a MailchimpAPIV3::List::InterestCategory
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has a title' do
|
@@ -22,6 +22,6 @@ describe Mailchimp::List::InterestCategory, vcr: { cassette_name: 'mailchimp' }
|
|
22
22
|
it 'has an interests collection' do
|
23
23
|
interests = interest_category.interests
|
24
24
|
expect(interests).to be_an Array
|
25
|
-
expect(interests.sample).to be_a
|
25
|
+
expect(interests.sample).to be_a MailchimpAPIV3::List::InterestCategory::Interest
|
26
26
|
end
|
27
27
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:lists) {
|
5
|
+
describe MailchimpAPIV3::List::InterestCategory::Interest, vcr: { cassette_name: 'mailchimp' } do
|
6
|
+
let(:lists) { MailchimpAPIV3.connect.lists }
|
7
7
|
let(:list) { lists.first }
|
8
8
|
let(:interest_category) { list.interest_categories.first }
|
9
9
|
let(:interest) { interest_category.interests.first }
|
10
10
|
|
11
11
|
it 'is the expected class' do
|
12
|
-
expect(interest).to be_a
|
12
|
+
expect(interest).to be_a MailchimpAPIV3::List::InterestCategory::Interest
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'has a name' do
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:list) {
|
5
|
+
describe MailchimpAPIV3::List::InterestCategory::Interests, vcr: { cassette_name: 'mailchimp' } do
|
6
|
+
let(:list) { MailchimpAPIV3.connect.lists.first }
|
7
7
|
let(:interest_category) { list.interest_categories.first }
|
8
8
|
let(:interests) { interest_category.interests }
|
9
9
|
|
10
10
|
it 'is the expected class' do
|
11
|
-
expect(interests).to be_a
|
11
|
+
expect(interests).to be_a MailchimpAPIV3::List::InterestCategory::Interests
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has a count' do
|
@@ -20,13 +20,13 @@ describe Mailchimp::List::InterestCategory::Interests, vcr: { cassette_name: 'ma
|
|
20
20
|
it 'can add a new instance' do
|
21
21
|
data = { 'name' => 'Green' }
|
22
22
|
interest = interests.create data
|
23
|
-
expect(interest).to be_a
|
23
|
+
expect(interest).to be_a MailchimpAPIV3::List::InterestCategory::Interest
|
24
24
|
expect(interest.name).to eq 'Green'
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'fails adding an instance with the same details' do
|
28
28
|
data = { 'name' => 'Red' }
|
29
|
-
expect { interests.create data }.to raise_error
|
29
|
+
expect { interests.create data }.to raise_error MailchimpAPIV3::Exception::Duplicate
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,14 +34,14 @@ describe Mailchimp::List::InterestCategory::Interests, vcr: { cassette_name: 'ma
|
|
34
34
|
it 'finds an instance with the same details' do
|
35
35
|
data = { 'name' => 'Red' }
|
36
36
|
interest = interests.first_or_create data
|
37
|
-
expect(interest).to be_a
|
37
|
+
expect(interest).to be_a MailchimpAPIV3::List::InterestCategory::Interest
|
38
38
|
expect(interest.name).to eq 'red' # Note case
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'creates a new instance if one does not yet exist' do
|
42
42
|
data = { 'name' => 'Amber' }
|
43
43
|
interest = interests.first_or_create data
|
44
|
-
expect(interest).to be_a
|
44
|
+
expect(interest).to be_a MailchimpAPIV3::List::InterestCategory::Interest
|
45
45
|
expect(interest.name).to eq 'Amber'
|
46
46
|
end
|
47
47
|
end
|
data/spec/mailchimp/list_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:lists) {
|
5
|
+
describe MailchimpAPIV3::List, vcr: { cassette_name: 'mailchimp' } do
|
6
|
+
let(:lists) { MailchimpAPIV3.connect.lists }
|
7
7
|
let(:list) { lists.first }
|
8
8
|
|
9
9
|
it 'is the expected class' do
|
10
|
-
expect(list).to be_a
|
10
|
+
expect(list).to be_a MailchimpAPIV3::List
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'has a name' do
|
@@ -25,12 +25,31 @@ describe Mailchimp::List, vcr: { cassette_name: 'mailchimp' } do
|
|
25
25
|
it 'has a members collection' do
|
26
26
|
members = list.members
|
27
27
|
expect(members).to be_an Array
|
28
|
-
expect(members.sample).to be_a
|
28
|
+
expect(members.sample).to be_a MailchimpAPIV3::List::Member
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'has a interest_categories collection' do
|
32
32
|
interest_categories = list.interest_categories
|
33
33
|
expect(interest_categories).to be_an Array
|
34
|
-
expect(interest_categories.sample).to be_a
|
34
|
+
expect(interest_categories.sample).to be_a MailchimpAPIV3::List::InterestCategory
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'get a specific member' do
|
38
|
+
let(:email_address) { 'ann@sayers.cc' }
|
39
|
+
let(:id) { '140b91c107d2058dee730e75be0b1151' }
|
40
|
+
|
41
|
+
it 'gets a member by id' do
|
42
|
+
member = list.members id
|
43
|
+
expect(member).to be_a MailchimpAPIV3::List::Member
|
44
|
+
expect(member.id).to eq id
|
45
|
+
expect(member.email_address).to eq email_address
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'gets a member by email address' do
|
49
|
+
member = list.members email_address
|
50
|
+
expect(member).to be_a MailchimpAPIV3::List::Member
|
51
|
+
expect(member.id).to eq id
|
52
|
+
expect(member.email_address).to eq email_address
|
53
|
+
end
|
35
54
|
end
|
36
55
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:lists) {
|
5
|
+
describe MailchimpAPIV3::Lists, vcr: { cassette_name: 'mailchimp' } do
|
6
|
+
let(:lists) { MailchimpAPIV3.connect.lists }
|
7
7
|
|
8
8
|
it 'is the expected class' do
|
9
|
-
expect(lists).to be_a
|
9
|
+
expect(lists).to be_a MailchimpAPIV3::Lists
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'has a count' do
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
6
|
-
let(:lists) {
|
5
|
+
describe MailchimpAPIV3::List::Member, vcr: { cassette_name: 'mailchimp' } do
|
6
|
+
let(:lists) { MailchimpAPIV3.connect.lists }
|
7
7
|
let(:list) { lists.first }
|
8
8
|
let(:member) { list.members.first }
|
9
9
|
|
10
10
|
it 'is the expected class' do
|
11
|
-
expect(member).to be_a
|
11
|
+
expect(member).to be_a MailchimpAPIV3::List::Member
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has a name' do
|
@@ -18,4 +18,28 @@ describe Mailchimp::List::Member, vcr: { cassette_name: 'mailchimp' } do
|
|
18
18
|
it 'has an id' do
|
19
19
|
expect(member.id).to eq '140b91c107d2058dee730e75be0b1151'
|
20
20
|
end
|
21
|
+
|
22
|
+
context 'updates name fields correctly' do
|
23
|
+
it 'uses friendly name fields' do
|
24
|
+
updated_member = member.update name: 'Billy Bonkers'
|
25
|
+
expect(updated_member).to be_a MailchimpAPIV3::List::Member
|
26
|
+
expect(updated_member).to have_attributes name: 'Billy Bonkers'
|
27
|
+
|
28
|
+
updated_member = updated_member.update first_name: 'William'
|
29
|
+
expect(updated_member).to have_attributes name: 'William Bonkers'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'handles multiple definitions of the same field' do
|
33
|
+
data = {
|
34
|
+
name: 'Billy Bonkers',
|
35
|
+
first_name: 'William',
|
36
|
+
merge_fields: {
|
37
|
+
FNAME: 'Ann',
|
38
|
+
LNAME: 'Example'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
expect(member.update data).to have_attributes name: 'Ann Example'
|
43
|
+
end
|
44
|
+
end
|
21
45
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
3
|
+
require 'mailchimp_api_v3'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe MailchimpAPIV3::List::Members, vcr: { cassette_name: 'members' } do
|
6
6
|
let(:page_size) { 10 }
|
7
7
|
let(:member_count) { 37 }
|
8
|
-
let(:list) {
|
8
|
+
let(:list) { MailchimpAPIV3.connect.lists.first }
|
9
9
|
let(:members) { list.members 'page_size' => page_size }
|
10
10
|
|
11
11
|
it 'is the expected class' do
|
12
|
-
expect(members).to be_a
|
12
|
+
expect(members).to be_a MailchimpAPIV3::List::Members
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'has a count' do
|
@@ -29,6 +29,6 @@ describe Mailchimp::List::Members, vcr: { cassette_name: 'members' } do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'has a Member for each item' do
|
32
|
-
expect(members.sample).to be_a
|
32
|
+
expect(members.sample).to be_a MailchimpAPIV3::List::Member
|
33
33
|
end
|
34
34
|
end
|
data/spec/mailchimp_spec.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
|
-
require '
|
4
|
-
|
5
|
-
describe Mailchimp do
|
6
|
-
it 'has an API key to work with' do
|
7
|
-
expect(api_key?).to be_truthy
|
8
|
-
end
|
3
|
+
require 'mailchimp_api_v3'
|
9
4
|
|
5
|
+
describe MailchimpAPIV3 do
|
10
6
|
it 'does not attempt to connect without an API key in the right format' do
|
11
|
-
expect {
|
12
|
-
expect(e).to be_a
|
13
|
-
expect(e.message).to eq 'Invalid API key format'
|
7
|
+
expect { MailchimpAPIV3.connect '' }.to raise_error { |e|
|
8
|
+
expect(e).to be_a MailchimpAPIV3::Exception::APIKeyError
|
9
|
+
expect(e.message).to eq 'Invalid API key format: '
|
14
10
|
}
|
15
11
|
end
|
16
12
|
|
17
13
|
it 'connects with an API key' do
|
18
|
-
expect {
|
14
|
+
expect { MailchimpAPIV3.connect }.not_to raise_error
|
19
15
|
end
|
20
16
|
end
|
data/spec/support/api_key.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
-
ENV['MAILCHIMP_API_KEY']
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
unless ENV['MAILCHIMP_API_KEY']
|
4
|
+
if File.exist?('api_key.yml')
|
5
|
+
ENV['MAILCHIMP_API_KEY'] = YAML.load_file('api_key.yml')['api_key']
|
6
|
+
else
|
7
|
+
ENV['MAILCHIMP_API_KEY'] = 'vcr_playback-us11' # Will successfully replay the VCR cassettes
|
8
|
+
end
|
7
9
|
end
|
10
|
+
|
11
|
+
ENV['MAILCHIMP_DC'] = ENV['MAILCHIMP_API_KEY'].split('-')[1]
|