dotmailer 0.0.3 → 0.0.4
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.
- checksums.yaml +6 -14
- data/.gitignore +0 -1
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile.lock +58 -0
- data/README.md +75 -2
- data/Rakefile +9 -0
- data/dotmailer.gemspec +1 -0
- data/lib/dot_mailer.rb +6 -1
- data/lib/dot_mailer/account.rb +22 -2
- data/lib/dot_mailer/campaign.rb +95 -0
- data/lib/dot_mailer/campaign_summary.rb +77 -0
- data/lib/dot_mailer/client.rb +7 -0
- data/lib/dot_mailer/contact.rb +4 -0
- data/lib/dot_mailer/contact_import.rb +21 -3
- data/lib/dot_mailer/exceptions.rb +6 -0
- data/lib/dot_mailer/from_address.rb +36 -0
- data/lib/dot_mailer/segment.rb +36 -0
- data/lib/dot_mailer/version.rb +1 -1
- data/spec/dot_mailer/account_spec.rb +57 -8
- data/spec/dot_mailer/campaign_spec.rb +206 -0
- data/spec/dot_mailer/campaign_summary_spec.rb +20 -0
- data/spec/dot_mailer/client_spec.rb +15 -1
- data/spec/dot_mailer/contact_import_spec.rb +47 -6
- data/spec/dot_mailer/contact_spec.rb +9 -1
- data/spec/dot_mailer/from_address_spec.rb +25 -0
- data/spec/dot_mailer/segment_spec.rb +80 -0
- data/spec/dot_mailer/suppression_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- metadata +38 -13
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DotMailer::CampaignSummary do
|
4
|
+
let(:client) { double 'client' }
|
5
|
+
let(:account) { double 'account', :client => client }
|
6
|
+
let(:response) {{
|
7
|
+
"dateSent" => '2013-07-30T16:01:21.603Z',
|
8
|
+
"numTotalSent" => '123',
|
9
|
+
"percentageDelivered" => '95.8'
|
10
|
+
}}
|
11
|
+
|
12
|
+
subject do
|
13
|
+
client.should_receive(:get).with("/campaigns/1/summary").and_return(response)
|
14
|
+
DotMailer::CampaignSummary.new(account, 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
specify { subject.date_sent.should eq(Time.parse('2013-07-30T16:01:21.603Z')) }
|
18
|
+
specify { subject.num_total_sent.should eq(123) }
|
19
|
+
specify { subject.percentage_delivered.should eq(95.8) }
|
20
|
+
end
|
@@ -56,7 +56,7 @@ describe DotMailer::Client do
|
|
56
56
|
subject.get_csv api_path
|
57
57
|
|
58
58
|
WebMock.should have_requested(:get, api_endpoint).with(
|
59
|
-
:headers => { 'Accept' => 'text/
|
59
|
+
:headers => { 'Accept' => 'text/comma-separated-values' }
|
60
60
|
)
|
61
61
|
end
|
62
62
|
|
@@ -157,4 +157,18 @@ describe DotMailer::Client do
|
|
157
157
|
subject.post_csv api_path, csv
|
158
158
|
end
|
159
159
|
end
|
160
|
+
|
161
|
+
describe '#delete' do
|
162
|
+
before(:each) do
|
163
|
+
stub_request(:delete, api_endpoint)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should DELETE the endpoint with a JSON accept header' do
|
167
|
+
subject.delete api_path
|
168
|
+
|
169
|
+
WebMock.should have_requested(:delete, api_endpoint).with(
|
170
|
+
:headers => { 'Accept' => 'application/json' }
|
171
|
+
)
|
172
|
+
end
|
173
|
+
end
|
160
174
|
end
|
@@ -15,6 +15,7 @@ describe DotMailer::ContactImport do
|
|
15
15
|
|
16
16
|
describe '.import' do
|
17
17
|
let(:contact_import) { double 'contact import', :start => double }
|
18
|
+
let(:wait_for_finish) { false }
|
18
19
|
|
19
20
|
before(:each) do
|
20
21
|
subject.stub :new => contact_import
|
@@ -23,17 +24,17 @@ describe DotMailer::ContactImport do
|
|
23
24
|
it 'should create a new instance with the account and contacts' do
|
24
25
|
subject.should_receive(:new).with(account, contacts)
|
25
26
|
|
26
|
-
subject.import account, contacts
|
27
|
+
subject.import account, contacts, wait_for_finish
|
27
28
|
end
|
28
29
|
|
29
30
|
it 'should start the new contact import' do
|
30
31
|
contact_import.should_receive :start
|
31
32
|
|
32
|
-
subject.import account, contacts
|
33
|
+
subject.import account, contacts, wait_for_finish
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'should return the contact import' do
|
36
|
-
subject.import(account, contacts).should == contact_import
|
37
|
+
subject.import(account, contacts, wait_for_finish).should == contact_import
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -46,6 +47,7 @@ describe DotMailer::ContactImport do
|
|
46
47
|
before(:each) do
|
47
48
|
account.stub :data_fields => [double('data field', :name => 'CODE')]
|
48
49
|
end
|
50
|
+
let(:wait_for_finish) { false }
|
49
51
|
|
50
52
|
context 'when the contacts include a non existent data field' do
|
51
53
|
let(:data_field_name) { 'UNKNOWN' }
|
@@ -57,7 +59,7 @@ describe DotMailer::ContactImport do
|
|
57
59
|
end
|
58
60
|
|
59
61
|
it 'should raise an UnknownDataField error with the data field name' do
|
60
|
-
expect { subject.start }.to raise_error(DotMailer::UnknownDataField, data_field_name)
|
62
|
+
expect { subject.start(wait_for_finish) }.to raise_error(DotMailer::UnknownDataField, data_field_name)
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
@@ -72,13 +74,23 @@ describe DotMailer::ContactImport do
|
|
72
74
|
it 'should call post_csv on the client with the contacts in CSV format' do
|
73
75
|
client.should_receive(:post_csv).with('/contacts/import', contacts_csv)
|
74
76
|
|
75
|
-
subject.start
|
77
|
+
subject.start(wait_for_finish)
|
76
78
|
end
|
77
79
|
|
78
80
|
it 'should set the id from the response' do
|
79
|
-
subject.start
|
81
|
+
subject.start(wait_for_finish)
|
80
82
|
subject.id.should == id
|
81
83
|
end
|
84
|
+
|
85
|
+
context "with a wait_for_finish request" do
|
86
|
+
let(:wait_for_finish) { true }
|
87
|
+
|
88
|
+
it "should call the blocking wait_for_finish method" do
|
89
|
+
subject.should_receive(:wait_until_finished)
|
90
|
+
|
91
|
+
subject.start wait_for_finish
|
92
|
+
end
|
93
|
+
end
|
82
94
|
end
|
83
95
|
|
84
96
|
describe '#status' do
|
@@ -170,4 +182,33 @@ describe DotMailer::ContactImport do
|
|
170
182
|
end
|
171
183
|
end
|
172
184
|
end
|
185
|
+
|
186
|
+
describe '#wait_for_finish' do
|
187
|
+
before { subject.stub(:sleep).and_return(1) }
|
188
|
+
|
189
|
+
it "returns when finished is true" do
|
190
|
+
subject.should_receive(:finished?).once.and_return(true)
|
191
|
+
|
192
|
+
subject.send(:wait_until_finished)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "returns nil when batch finished within max tries" do
|
196
|
+
subject.stub(:finished? => true)
|
197
|
+
|
198
|
+
subject.send(:wait_until_finished).should be_nil
|
199
|
+
end
|
200
|
+
|
201
|
+
it "sleeps between each call to finished" do
|
202
|
+
subject.stub(:finished? => true)
|
203
|
+
subject.should_receive(:sleep).once.with(1).and_return(true)
|
204
|
+
|
205
|
+
subject.send(:wait_until_finished)
|
206
|
+
end
|
207
|
+
|
208
|
+
it "raises an error when not finished within max tries" do
|
209
|
+
subject.should_receive(:finished?).exactly(10).times.and_return(false)
|
210
|
+
|
211
|
+
expect { subject.send(:wait_until_finished) }.to raise_error(DotMailer::ImportNotFinished)
|
212
|
+
end
|
213
|
+
end
|
173
214
|
end
|
@@ -64,7 +64,7 @@ describe DotMailer::Contact do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
describe '.modified_since' do
|
67
|
-
let(:time) { Time.parse('1st March 2013
|
67
|
+
let(:time) { Time.parse('1st March 2013 16:30:45 +01:00') }
|
68
68
|
let(:attributes) { double 'attributes' }
|
69
69
|
let(:response) { 3.times.map { attributes } }
|
70
70
|
let(:contact) { double 'contact' }
|
@@ -230,6 +230,14 @@ describe DotMailer::Contact do
|
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
233
|
+
describe '#delete' do
|
234
|
+
it 'should call delete on the client with the id path' do
|
235
|
+
client.should_receive(:delete).with("/contacts/#{id}")
|
236
|
+
|
237
|
+
subject.delete
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
233
241
|
describe '#subscribed?' do
|
234
242
|
context 'when the status is the SUBSCRIBED_STATUS' do
|
235
243
|
let(:status) { DotMailer::SUBSCRIBED_STATUS }
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DotMailer::FromAddress do
|
4
|
+
let(:id) { double 'id' }
|
5
|
+
let(:email) { double 'email' }
|
6
|
+
|
7
|
+
let(:attributes) do
|
8
|
+
{
|
9
|
+
'id' => id,
|
10
|
+
'email' => email
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { DotMailer::FromAddress.new(attributes) }
|
15
|
+
|
16
|
+
its(:id) { should == id }
|
17
|
+
its(:email) { should == email}
|
18
|
+
its(:to_hash) { should == attributes }
|
19
|
+
|
20
|
+
describe '#==' do
|
21
|
+
it 'should equal a from address with the same attributes' do
|
22
|
+
subject.should == DotMailer::FromAddress.new(attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DotMailer::Segment do
|
4
|
+
let(:client) { double 'client' }
|
5
|
+
let(:account) { double 'account', :client => client }
|
6
|
+
let(:id) { 123 }
|
7
|
+
|
8
|
+
subject do
|
9
|
+
DotMailer::Segment.new(account, { 'id' => id } )
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'Class' do
|
13
|
+
subject { DotMailer::Segment }
|
14
|
+
|
15
|
+
describe '.find_by_id' do
|
16
|
+
|
17
|
+
let(:response) { [
|
18
|
+
{ "id"=>121, "name"=>"Segment A", "contacts"=>0 },
|
19
|
+
{ "id"=>id, "name"=>"Segment B", "contacts"=>1 }
|
20
|
+
] }
|
21
|
+
|
22
|
+
let(:segment) { double 'segment' }
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
subject.stub :new => segment
|
26
|
+
client.stub :get => response
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should call get on the client with the correct parameters' do
|
30
|
+
client.should_receive(:get).with("/segments")
|
31
|
+
|
32
|
+
subject.find_by_id(account, id)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should initialize a Segement with the response' do
|
36
|
+
subject.should_receive(:new).with(account, response[1])
|
37
|
+
|
38
|
+
subject.find_by_id(account, id)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should return the new Segement object' do
|
42
|
+
subject.find_by_id(account, id).should == segment
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.refresh!' do
|
48
|
+
let(:response) { double 'response' }
|
49
|
+
let(:segment) { double 'segment' }
|
50
|
+
|
51
|
+
before(:each) do
|
52
|
+
subject.stub :new => segment
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should call post on the client with the correct parameters' do
|
56
|
+
client.should_receive(:post_json).with("/segments/refresh/#{id}",{})
|
57
|
+
|
58
|
+
subject.refresh!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.refresh_progress' do
|
63
|
+
let(:status) { double 'status'}
|
64
|
+
let(:response) { {"id" => id, "status" => status} }
|
65
|
+
|
66
|
+
before(:each) do
|
67
|
+
client.stub :get => response
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should call get on the client with the correct parameters' do
|
71
|
+
client.should_receive(:get).with("/segments/refresh/#{id}")
|
72
|
+
|
73
|
+
subject.refresh_progress
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should return a percentage complete' do
|
77
|
+
subject.refresh_progress.should == status
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -22,14 +22,14 @@ describe DotMailer::Suppression do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
its(:contact) { should == contact }
|
25
|
-
its(:date_removed) { should == Time.parse('1st March 2013
|
25
|
+
its(:date_removed) { should == Time.parse('1st March 2013 16:30:45 +01:00') }
|
26
26
|
its(:reason) { should == reason }
|
27
27
|
|
28
28
|
describe 'Class' do
|
29
29
|
subject { DotMailer::Suppression }
|
30
30
|
|
31
31
|
describe '.suppressed_since' do
|
32
|
-
let(:time) { Time.parse('1st February 2013
|
32
|
+
let(:time) { Time.parse('1st February 2013 16:30:45 +01:00') }
|
33
33
|
let(:suppression) { double 'suppression' }
|
34
34
|
|
35
35
|
let(:attributes) do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,69 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotmailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Econsultancy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
description:
|
@@ -74,28 +88,39 @@ extensions: []
|
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
90
|
- .gitignore
|
91
|
+
- .ruby-version
|
92
|
+
- .travis.yml
|
77
93
|
- Gemfile
|
94
|
+
- Gemfile.lock
|
78
95
|
- README.md
|
79
96
|
- Rakefile
|
80
97
|
- TODO.md
|
81
98
|
- dotmailer.gemspec
|
82
99
|
- lib/dot_mailer.rb
|
83
100
|
- lib/dot_mailer/account.rb
|
101
|
+
- lib/dot_mailer/campaign.rb
|
102
|
+
- lib/dot_mailer/campaign_summary.rb
|
84
103
|
- lib/dot_mailer/client.rb
|
85
104
|
- lib/dot_mailer/contact.rb
|
86
105
|
- lib/dot_mailer/contact_import.rb
|
87
106
|
- lib/dot_mailer/data_field.rb
|
88
107
|
- lib/dot_mailer/exceptions.rb
|
108
|
+
- lib/dot_mailer/from_address.rb
|
89
109
|
- lib/dot_mailer/opt_in_type.rb
|
110
|
+
- lib/dot_mailer/segment.rb
|
90
111
|
- lib/dot_mailer/suppression.rb
|
91
112
|
- lib/dot_mailer/version.rb
|
92
113
|
- lib/dotmailer.rb
|
93
114
|
- spec/dot_mailer/account_spec.rb
|
115
|
+
- spec/dot_mailer/campaign_spec.rb
|
116
|
+
- spec/dot_mailer/campaign_summary_spec.rb
|
94
117
|
- spec/dot_mailer/client_spec.rb
|
95
118
|
- spec/dot_mailer/contact_import_spec.rb
|
96
119
|
- spec/dot_mailer/contact_spec.rb
|
97
120
|
- spec/dot_mailer/data_field_spec.rb
|
121
|
+
- spec/dot_mailer/from_address_spec.rb
|
98
122
|
- spec/dot_mailer/opt_in_type_spec.rb
|
123
|
+
- spec/dot_mailer/segment_spec.rb
|
99
124
|
- spec/dot_mailer/suppression_spec.rb
|
100
125
|
- spec/spec_helper.rb
|
101
126
|
- spec/support/assignable_attributes_helper.rb
|
@@ -108,12 +133,12 @@ require_paths:
|
|
108
133
|
- lib
|
109
134
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
135
|
requirements:
|
111
|
-
- -
|
136
|
+
- - '>='
|
112
137
|
- !ruby/object:Gem::Version
|
113
138
|
version: '0'
|
114
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
140
|
requirements:
|
116
|
-
- -
|
141
|
+
- - '>='
|
117
142
|
- !ruby/object:Gem::Version
|
118
143
|
version: '0'
|
119
144
|
requirements: []
|
@@ -121,5 +146,5 @@ rubyforge_project: dotmailer
|
|
121
146
|
rubygems_version: 2.0.3
|
122
147
|
signing_key:
|
123
148
|
specification_version: 4
|
124
|
-
summary:
|
149
|
+
summary: 'A Ruby wrapper around the dotMailer REST API: https://apiconnector.com/v2/help/wadl'
|
125
150
|
test_files: []
|