i_contact 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rvmrc +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +11 -0
- data/Guardfile +9 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +15 -0
- data/bin/tmux.sh +16 -0
- data/i_contact.gemspec +32 -0
- data/lib/i_contact.rb +87 -0
- data/lib/i_contact/account.rb +14 -0
- data/lib/i_contact/client_folder.rb +19 -0
- data/lib/i_contact/configuration.rb +31 -0
- data/lib/i_contact/contact.rb +32 -0
- data/lib/i_contact/list.rb +11 -0
- data/lib/i_contact/model.rb +138 -0
- data/lib/i_contact/response.rb +24 -0
- data/lib/i_contact/subscription.rb +10 -0
- data/lib/i_contact/version.rb +4 -0
- data/spec/cassettes/IContact_Account.yml +57 -0
- data/spec/cassettes/IContact_ClientFolder.yml +53 -0
- data/spec/cassettes/IContact_Contact.yml +249 -0
- data/spec/cassettes/IContact_List.yml +89 -0
- data/spec/cassettes/IContact_Subscription.yml +220 -0
- data/spec/i_contact/account_spec.rb +11 -0
- data/spec/i_contact/client_folder_spec.rb +10 -0
- data/spec/i_contact/configuration_spec.rb +57 -0
- data/spec/i_contact/contact_spec.rb +45 -0
- data/spec/i_contact/list_spec.rb +13 -0
- data/spec/i_contact/model_spec.rb +49 -0
- data/spec/i_contact/response_spec.rb +27 -0
- data/spec/i_contact/subscription_spec.rb +35 -0
- data/spec/i_contact_spec.rb +40 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/active_attr.rb +17 -0
- data/spec/support/configuration.rb +9 -0
- data/spec/support/vcr.rb +17 -0
- metadata +301 -0
@@ -0,0 +1,220 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://app.sandbox.icontact.com/icp/a/413323/c/124667/contacts
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ! '[{"email":"subscriber@example.com"}]'
|
9
|
+
headers:
|
10
|
+
Api-Appid:
|
11
|
+
- <APP_ID>
|
12
|
+
Api-Username:
|
13
|
+
- <USER_NAME>
|
14
|
+
Api-Password:
|
15
|
+
- <PASSWORD>
|
16
|
+
Api-Version:
|
17
|
+
- '2.2'
|
18
|
+
Accept:
|
19
|
+
- application/json
|
20
|
+
Content-Type:
|
21
|
+
- application/json
|
22
|
+
User-Agent:
|
23
|
+
- Ruby
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
Date:
|
30
|
+
- Sat, 09 Jun 2012 20:25:49 GMT
|
31
|
+
Server:
|
32
|
+
- Apache
|
33
|
+
Vary:
|
34
|
+
- Accept-Encoding
|
35
|
+
Content-Length:
|
36
|
+
- '291'
|
37
|
+
Connection:
|
38
|
+
- close
|
39
|
+
Content-Type:
|
40
|
+
- text/html; charset=utf-8
|
41
|
+
body:
|
42
|
+
encoding: US-ASCII
|
43
|
+
string: ! '{"contacts":[{"contactId":"66695798","prefix":"","firstName":"","lastName":"","suffix":"","street":"","street2":"","city":"","state":"","postalCode":"","phone":"","fax":"","business":"","email":"subscriber@example.com","createDate":"2012-06-09
|
44
|
+
16:25:49","bounceCount":"","status":"normal"}]}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Sat, 09 Jun 2012 20:25:49 GMT
|
47
|
+
- request:
|
48
|
+
method: post
|
49
|
+
uri: https://app.sandbox.icontact.com/icp/a/413323/c/124667/lists
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: ! '[{"name":"Test Subscription List"}]'
|
53
|
+
headers:
|
54
|
+
Api-Appid:
|
55
|
+
- <APP_ID>
|
56
|
+
Api-Username:
|
57
|
+
- <USER_NAME>
|
58
|
+
Api-Password:
|
59
|
+
- <PASSWORD>
|
60
|
+
Api-Version:
|
61
|
+
- '2.2'
|
62
|
+
Accept:
|
63
|
+
- application/json
|
64
|
+
Content-Type:
|
65
|
+
- application/json
|
66
|
+
User-Agent:
|
67
|
+
- Ruby
|
68
|
+
response:
|
69
|
+
status:
|
70
|
+
code: 200
|
71
|
+
message: OK
|
72
|
+
headers:
|
73
|
+
Date:
|
74
|
+
- Sat, 09 Jun 2012 20:25:50 GMT
|
75
|
+
Server:
|
76
|
+
- Apache
|
77
|
+
Vary:
|
78
|
+
- Accept-Encoding
|
79
|
+
Content-Length:
|
80
|
+
- '187'
|
81
|
+
Connection:
|
82
|
+
- close
|
83
|
+
Content-Type:
|
84
|
+
- text/html; charset=utf-8
|
85
|
+
body:
|
86
|
+
encoding: US-ASCII
|
87
|
+
string: ! '{"lists":[{"listId":"205305","name":"Test Subscription List","publicname":"","description":"","emailOwnerOnChange":1,"welcomeOnManualAdd":0,"welcomeOnSignupAdd":0,"welcomeMessageId":""}]}'
|
88
|
+
http_version:
|
89
|
+
recorded_at: Sat, 09 Jun 2012 20:25:49 GMT
|
90
|
+
- request:
|
91
|
+
method: post
|
92
|
+
uri: https://app.sandbox.icontact.com/icp/a/413323/c/124667/subscriptions
|
93
|
+
body:
|
94
|
+
encoding: UTF-8
|
95
|
+
string: ! '[{"contactId":66695798,"listId":205305,"status":"normal"}]'
|
96
|
+
headers:
|
97
|
+
Api-Appid:
|
98
|
+
- <APP_ID>
|
99
|
+
Api-Username:
|
100
|
+
- <USER_NAME>
|
101
|
+
Api-Password:
|
102
|
+
- <PASSWORD>
|
103
|
+
Api-Version:
|
104
|
+
- '2.2'
|
105
|
+
Accept:
|
106
|
+
- application/json
|
107
|
+
Content-Type:
|
108
|
+
- application/json
|
109
|
+
User-Agent:
|
110
|
+
- Ruby
|
111
|
+
response:
|
112
|
+
status:
|
113
|
+
code: 200
|
114
|
+
message: OK
|
115
|
+
headers:
|
116
|
+
Date:
|
117
|
+
- Sat, 09 Jun 2012 20:25:50 GMT
|
118
|
+
Server:
|
119
|
+
- Apache
|
120
|
+
Vary:
|
121
|
+
- Accept-Encoding
|
122
|
+
Content-Length:
|
123
|
+
- '153'
|
124
|
+
Connection:
|
125
|
+
- close
|
126
|
+
Content-Type:
|
127
|
+
- text/html; charset=utf-8
|
128
|
+
body:
|
129
|
+
encoding: US-ASCII
|
130
|
+
string: ! '{"subscriptions":[{"addDate":"2012-06-09T16:25:50-04:00","contactId":"66695798","listId":"205305","status":"normal","subscriptionId":"205305_66695798"}]}'
|
131
|
+
http_version:
|
132
|
+
recorded_at: Sat, 09 Jun 2012 20:25:50 GMT
|
133
|
+
- request:
|
134
|
+
method: post
|
135
|
+
uri: https://app.sandbox.icontact.com/icp/a/413323/c/124667/contacts/66695798
|
136
|
+
body:
|
137
|
+
encoding: UTF-8
|
138
|
+
string: ! '{"status":"deleted"}'
|
139
|
+
headers:
|
140
|
+
Api-Appid:
|
141
|
+
- <APP_ID>
|
142
|
+
Api-Username:
|
143
|
+
- <USER_NAME>
|
144
|
+
Api-Password:
|
145
|
+
- <PASSWORD>
|
146
|
+
Api-Version:
|
147
|
+
- '2.2'
|
148
|
+
Accept:
|
149
|
+
- application/json
|
150
|
+
Content-Type:
|
151
|
+
- application/json
|
152
|
+
User-Agent:
|
153
|
+
- Ruby
|
154
|
+
response:
|
155
|
+
status:
|
156
|
+
code: 400
|
157
|
+
message: Bad Request
|
158
|
+
headers:
|
159
|
+
Date:
|
160
|
+
- Sat, 09 Jun 2012 20:25:51 GMT
|
161
|
+
Server:
|
162
|
+
- Apache
|
163
|
+
Vary:
|
164
|
+
- Accept-Encoding
|
165
|
+
Content-Length:
|
166
|
+
- '134'
|
167
|
+
Connection:
|
168
|
+
- close
|
169
|
+
Content-Type:
|
170
|
+
- text/html; charset=utf-8
|
171
|
+
body:
|
172
|
+
encoding: US-ASCII
|
173
|
+
string: ! '{"errors":["The status value you provided was not valid. status can
|
174
|
+
be either donotcontact or normal. Please provide a valid status"]}'
|
175
|
+
http_version:
|
176
|
+
recorded_at: Sat, 09 Jun 2012 20:25:50 GMT
|
177
|
+
- request:
|
178
|
+
method: delete
|
179
|
+
uri: https://app.sandbox.icontact.com/icp/a/413323/c/124667/lists/205305
|
180
|
+
body:
|
181
|
+
encoding: US-ASCII
|
182
|
+
string: ''
|
183
|
+
headers:
|
184
|
+
Api-Appid:
|
185
|
+
- <APP_ID>
|
186
|
+
Api-Username:
|
187
|
+
- <USER_NAME>
|
188
|
+
Api-Password:
|
189
|
+
- <PASSWORD>
|
190
|
+
Api-Version:
|
191
|
+
- '2.2'
|
192
|
+
Accept:
|
193
|
+
- application/json
|
194
|
+
Content-Type:
|
195
|
+
- application/json
|
196
|
+
User-Agent:
|
197
|
+
- Ruby
|
198
|
+
response:
|
199
|
+
status:
|
200
|
+
code: 200
|
201
|
+
message: OK
|
202
|
+
headers:
|
203
|
+
Date:
|
204
|
+
- Sat, 09 Jun 2012 20:25:51 GMT
|
205
|
+
Server:
|
206
|
+
- Apache
|
207
|
+
Vary:
|
208
|
+
- Accept-Encoding
|
209
|
+
Content-Length:
|
210
|
+
- '2'
|
211
|
+
Connection:
|
212
|
+
- close
|
213
|
+
Content-Type:
|
214
|
+
- text/html; charset=utf-8
|
215
|
+
body:
|
216
|
+
encoding: US-ASCII
|
217
|
+
string: ! '[]'
|
218
|
+
http_version:
|
219
|
+
recorded_at: Sat, 09 Jun 2012 20:25:51 GMT
|
220
|
+
recorded_with: VCR 2.1.1
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::ClientFolder do
|
4
|
+
use_vcr_cassette
|
5
|
+
|
6
|
+
it 'returns a valid contact folder' do
|
7
|
+
folder = IContact::ClientFolder.get.first
|
8
|
+
folder.client_folder_id.to_s.should eql(IContact.configuration.client_folder_id)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Configuration do
|
4
|
+
let(:app_id) { 'app_id' }
|
5
|
+
let(:user_name) { 'user_name' }
|
6
|
+
let(:password) { 'password' }
|
7
|
+
let(:account_id) { 'account_id' }
|
8
|
+
let(:client_folder_id) { 'client_folder_id' }
|
9
|
+
|
10
|
+
let(:configuration) do
|
11
|
+
IContact::Configuration.new do |config|
|
12
|
+
config.app_id = app_id
|
13
|
+
config.user_name = user_name
|
14
|
+
config.password = password
|
15
|
+
config.account_id = account_id
|
16
|
+
config.client_folder_id = client_folder_id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has an api key' do
|
21
|
+
configuration.app_id.should eql(app_id)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has a user name' do
|
25
|
+
configuration.user_name.should eql(user_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has a password' do
|
29
|
+
configuration.password.should eql(password)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'defaults the api version to 2.2' do
|
33
|
+
configuration.api_version = '2.2'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'defaults to sandbox mode' do
|
37
|
+
configuration.mode = :sandbox
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'validity' do
|
41
|
+
it 'is invalid if I do not specify an app_id' do
|
42
|
+
configuration.app_id = nil
|
43
|
+
configuration.should_not be_valid
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'is invalid if I do not specify a user_name' do
|
47
|
+
configuration.user_name = nil
|
48
|
+
configuration.should_not be_valid
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'is invalid if I do not specify a password' do
|
52
|
+
configuration.password = nil
|
53
|
+
configuration.should_not be_valid
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Contact do
|
4
|
+
let(:email) { "user@example.com" }
|
5
|
+
|
6
|
+
has_attr :contact_id, Integer
|
7
|
+
has_attr :email, String
|
8
|
+
has_attr :first_name, String
|
9
|
+
has_attr :last_name, String
|
10
|
+
has_attr :suffix, String
|
11
|
+
has_attr :street, String
|
12
|
+
has_attr :street2, String
|
13
|
+
has_attr :city, String
|
14
|
+
has_attr :state, String
|
15
|
+
has_attr :postalCode, String
|
16
|
+
has_attr :phone, String
|
17
|
+
has_attr :fax, String
|
18
|
+
has_attr :business, String
|
19
|
+
|
20
|
+
use_vcr_cassette
|
21
|
+
|
22
|
+
it 'allows me to create a contact' do
|
23
|
+
contact = IContact::Contact.new(:email => email)
|
24
|
+
contact.save.should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'allows me to get all the contacts that are unlisted' do
|
28
|
+
contacts = IContact::Contact.unlisted
|
29
|
+
contacts.should_not be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'handles for when something goes wrong' do
|
33
|
+
contact = IContact::Contact.new(:email => nil)
|
34
|
+
contact.save.should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'destroys a contact' do
|
38
|
+
contact = IContact::Contact.unlisted(:email => email).first
|
39
|
+
if contact.nil?
|
40
|
+
contact = IContact::Contact.new(:email => email).save!
|
41
|
+
end
|
42
|
+
lambda { contact.destroy }.should_not raise_error
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::List do
|
4
|
+
use_vcr_cassette
|
5
|
+
|
6
|
+
it 'can be created' do
|
7
|
+
list = IContact::List.new(:name => "Test List")
|
8
|
+
list.save.should be_true
|
9
|
+
list.should be_persisted
|
10
|
+
lambda { list.destroy }.should_not raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Model do
|
4
|
+
class TestModel
|
5
|
+
include IContact::Model
|
6
|
+
|
7
|
+
key_attribute :test_model_id
|
8
|
+
attribute :email, :type => String
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:email) { 'user@example.com' }
|
12
|
+
let(:model) { TestModel.new(:email => email) }
|
13
|
+
|
14
|
+
|
15
|
+
it 'has a getter and setter for a declared model' do
|
16
|
+
new_email = 'another_user@example.com'
|
17
|
+
model.email.should eql(email)
|
18
|
+
model.email = new_email
|
19
|
+
model.email.should eql(new_email)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'defaults to a resource name a demodulized version of the class name' do
|
23
|
+
model.class.resource_name.should eql('testmodel')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'uses the IContact http connection' do
|
27
|
+
TestModel.connection.should eql(IContact.connection)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'is persisted if the key attribute is populated' do
|
31
|
+
model.test_model_id = 1234
|
32
|
+
model.should be_persisted
|
33
|
+
|
34
|
+
model.test_model_id = nil
|
35
|
+
model.attributes = { :test_model_id => 1234 }
|
36
|
+
model.test_model_id.should_not be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'appropriately parses json when an array is specified' do
|
40
|
+
mock_resp = mock
|
41
|
+
mock_resp.stubs(:valid?).returns(false)
|
42
|
+
mock_resp.stubs(:body).returns({:testmodels => [{:email => email}]}.to_json)
|
43
|
+
mock_resp.stubs(:status).returns(200)
|
44
|
+
result = model.class.parse(mock_resp)
|
45
|
+
result.size.should eql(1)
|
46
|
+
result.first.email.should eql(email)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Response do
|
4
|
+
let(:mock_raw_resp) do
|
5
|
+
mock_resp = mock.tap do |m|
|
6
|
+
m.stubs(:body).returns('{"errors":["Resource Or Version Not Implemented"]}')
|
7
|
+
m.stubs(:status).returns(200)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:response) { IContact::Response.new(mock_raw_resp) }
|
12
|
+
|
13
|
+
it 'finds errors when present' do
|
14
|
+
response.errors.should eql(JSON.parse(mock_raw_resp.body)["errors"])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is invalid when errors are present' do
|
18
|
+
response.stubs(:errors).returns(['something is wonky'])
|
19
|
+
response.should_not be_valid
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'is valid when errors are present' do
|
23
|
+
response.stubs(:errors).returns([])
|
24
|
+
response.should be_valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Subscription do
|
4
|
+
let(:email) { "subscriber@example.com" }
|
5
|
+
|
6
|
+
use_vcr_cassette
|
7
|
+
|
8
|
+
let(:contact) do
|
9
|
+
c = IContact::Contact.new(:email => email)
|
10
|
+
c.save
|
11
|
+
c
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:list) do
|
15
|
+
l = IContact::List.new(:name => "Test Subscription List")
|
16
|
+
l.save
|
17
|
+
l
|
18
|
+
end
|
19
|
+
|
20
|
+
after(:each) do
|
21
|
+
contact.destroy
|
22
|
+
list.destroy
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'allows me to add a list subscription for a given contact' do
|
26
|
+
sub = IContact::Subscription.new({
|
27
|
+
:contact_id => contact.contact_id,
|
28
|
+
:list_id => list.list_id,
|
29
|
+
:status => 'normal'
|
30
|
+
});
|
31
|
+
|
32
|
+
sub.save.should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|