xednese 0.0.1 → 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.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +22 -3
- data/Rakefile +8 -2
- data/bin/xednese +16 -0
- data/lib/xednese.rb +36 -9
- data/lib/xednese/account.rb +37 -0
- data/lib/xednese/account/dispatcher.rb +30 -0
- data/lib/xednese/account/messages.rb +47 -0
- data/lib/xednese/accounts.rb +14 -6
- data/lib/xednese/batch.rb +68 -0
- data/lib/xednese/batches.rb +33 -0
- data/lib/xednese/client.rb +46 -0
- data/lib/xednese/messages.rb +24 -0
- data/lib/xednese/requests/account.rb +17 -0
- data/lib/xednese/requests/batch.rb +17 -0
- data/lib/xednese/requests/messages.rb +1 -1
- data/lib/xednese/responses/batch.rb +20 -0
- data/lib/xednese/responses/batches.rb +15 -0
- data/lib/xednese/responses/status.rb +22 -0
- data/lib/xednese/users.rb +3 -8
- data/lib/xednese/version.rb +1 -1
- data/scenarios/accounts/getting_all_accounts.rb +37 -0
- data/scenarios/accounts/getting_an_account.rb +29 -0
- data/scenarios/helper.rb +113 -0
- data/spec/helper.rb +3 -3
- data/spec/xednese/{dispatcher_spec.rb → account/dispatcher_spec.rb} +5 -4
- data/spec/xednese/account/messages_spec.rb +56 -0
- data/spec/xednese/account_spec.rb +93 -0
- data/spec/xednese/accounts_spec.rb +19 -14
- data/spec/xednese/batch_spec.rb +121 -0
- data/spec/xednese/batches_spec.rb +70 -0
- data/spec/xednese/client_spec.rb +76 -2
- data/spec/xednese/messages_spec.rb +25 -1
- data/spec/xednese/requests/account_spec.rb +20 -0
- data/spec/xednese/requests/batch_spec.rb +20 -0
- data/spec/xednese/requests/messages_spec.rb +1 -1
- data/spec/xednese/responses/account_spec.rb +1 -1
- data/spec/xednese/responses/accounts_spec.rb +1 -1
- data/spec/xednese/responses/batch_spec.rb +83 -0
- data/spec/xednese/responses/batches_spec.rb +95 -0
- data/spec/xednese/responses/message_dispatcher_headers_spec.rb +1 -1
- data/spec/xednese/responses/message_header_spec.rb +1 -1
- data/spec/xednese/responses/message_headers_spec.rb +1 -1
- data/spec/xednese/responses/status_spec.rb +55 -0
- data/spec/xednese/users_spec.rb +1 -12
- data/spec/xednese_spec.rb +52 -12
- metadata +58 -8
- data/lib/xednese/dispatcher.rb +0 -20
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
describe Esendex::Messages do
|
4
4
|
subject { dummy_esendex }
|
@@ -28,6 +28,30 @@ describe Esendex::Messages do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
describe '#received' do
|
32
|
+
let(:xml) { "Hey I'm xml" }
|
33
|
+
let(:first_message) { mock }
|
34
|
+
let(:parsed_messages) { stub(message_headers: [first_message]) }
|
35
|
+
|
36
|
+
before {
|
37
|
+
Esendex::Client
|
38
|
+
.expects(:get)
|
39
|
+
.with(credentials, "v1.0/inbox/messages", startIndex: 0, count: 25)
|
40
|
+
.yields(200, xml)
|
41
|
+
.returns(parsed_messages.message_headers)
|
42
|
+
|
43
|
+
Esendex::Responses::MessageHeaders
|
44
|
+
.expects(:deserialise)
|
45
|
+
.with(xml)
|
46
|
+
.returns(parsed_messages)
|
47
|
+
}
|
48
|
+
|
49
|
+
it 'returns the messages received by the user on the account' do
|
50
|
+
received = subject.messages.received
|
51
|
+
received.first.must_equal first_message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
31
55
|
describe '#get' do
|
32
56
|
let(:message_id) { "guid" }
|
33
57
|
let(:xml) { "Hey I'm xml" }
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Esendex::Requests::Account do
|
4
|
+
subject { Esendex::Requests::Account }
|
5
|
+
|
6
|
+
describe '#serialise' do
|
7
|
+
let(:label) { "what a label?" }
|
8
|
+
|
9
|
+
it 'returns an xml representation of the instance' do
|
10
|
+
account = subject.new(label: label)
|
11
|
+
|
12
|
+
account.serialise.must_equal <<EOS
|
13
|
+
<?xml version="1.0" encoding="utf-8"?>
|
14
|
+
<account xmlns="http://api.esendex.com/ns/">
|
15
|
+
<label>#{label}</label>
|
16
|
+
</account>
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Esendex::Requests::Batch do
|
4
|
+
subject { Esendex::Requests::Batch }
|
5
|
+
|
6
|
+
describe '#serialise' do
|
7
|
+
let(:new_name) { "what a name!" }
|
8
|
+
|
9
|
+
it 'returns an xml representation of the instance' do
|
10
|
+
batch = subject.new(name: new_name)
|
11
|
+
|
12
|
+
batch.serialise.must_equal <<EOS
|
13
|
+
<?xml version="1.0" encoding="utf-8"?>
|
14
|
+
<messagebatch xmlns="http://api.esendex.com/ns/">
|
15
|
+
<name>#{new_name}</name>
|
16
|
+
</messagebatch>
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Esendex::Responses::Batch do
|
4
|
+
describe '.deserialise' do
|
5
|
+
let(:id) { "642A01A6-A483-44F3-A2F2-A48B1D0FE141" }
|
6
|
+
let(:createdat) { "2012-01-01T12:00:00.000Z" }
|
7
|
+
let(:batchsize) { 1 }
|
8
|
+
let(:persistedbatchsize) { 1 }
|
9
|
+
|
10
|
+
let(:acknowledged) { 0 }
|
11
|
+
let(:authorisationfailed) { 0 }
|
12
|
+
let(:connecting) { 0 }
|
13
|
+
let(:delivered) { 0 }
|
14
|
+
let(:failed) { 0 }
|
15
|
+
let(:partiallydelivered) { 0 }
|
16
|
+
let(:rejected) { 0 }
|
17
|
+
let(:scheduled) { 0 }
|
18
|
+
let(:sent) { 0 }
|
19
|
+
let(:submitted) { 1 }
|
20
|
+
let(:validityperiodexpired) { 0 }
|
21
|
+
let(:cancelled) { 0 }
|
22
|
+
|
23
|
+
let(:accountreference) { "EX0000000" }
|
24
|
+
let(:createdby) { "user@example.com" }
|
25
|
+
let(:batch_name) { "hey my batch" }
|
26
|
+
|
27
|
+
let(:xml) {
|
28
|
+
<<EOS
|
29
|
+
<?xml version="1.0" encoding="utf-8"?>
|
30
|
+
<messagebatch id="#{id}"
|
31
|
+
uri="https://api.esendex.com/v1.1/messagebatches/#{id}"
|
32
|
+
xmlns="http://api.esendex.com/ns/">
|
33
|
+
<createdat>#{createdat}</createdat>
|
34
|
+
<batchsize>#{batchsize}</batchsize>
|
35
|
+
<persistedbatchsize>#{persistedbatchsize}</persistedbatchsize>
|
36
|
+
<status>
|
37
|
+
<acknowledged>#{acknowledged}</acknowledged>
|
38
|
+
<authorisationfailed>#{authorisationfailed}</authorisationfailed>
|
39
|
+
<connecting>#{connecting}</connecting>
|
40
|
+
<delivered>#{delivered}</delivered>
|
41
|
+
<failed>#{failed}</failed>
|
42
|
+
<partiallydelivered>#{partiallydelivered}</partiallydelivered>
|
43
|
+
<rejected>#{rejected}</rejected>
|
44
|
+
<scheduled>#{scheduled}</scheduled>
|
45
|
+
<sent>#{sent}</sent>
|
46
|
+
<submitted>#{submitted}</submitted>
|
47
|
+
<validityperiodexpired>#{validityperiodexpired}</validityperiodexpired>
|
48
|
+
<cancelled>#{cancelled}</cancelled>
|
49
|
+
</status>
|
50
|
+
<accountreference>#{accountreference}</accountreference>
|
51
|
+
<createdby>#{createdby}</createdby>
|
52
|
+
<name>#{batch_name}</name>
|
53
|
+
</messagebatch>
|
54
|
+
EOS
|
55
|
+
}
|
56
|
+
|
57
|
+
it 'deserialises xml into a Batch instance' do
|
58
|
+
batch = Esendex::Responses::Batch.deserialise(xml)
|
59
|
+
|
60
|
+
batch.id.must_equal id
|
61
|
+
batch.created_at.must_equal createdat
|
62
|
+
batch.batch_size.must_equal batchsize
|
63
|
+
batch.persisted_batch_size.must_equal persistedbatchsize
|
64
|
+
|
65
|
+
batch.account_reference.must_equal accountreference
|
66
|
+
batch.created_by.must_equal createdby
|
67
|
+
batch.name.must_equal batch_name
|
68
|
+
|
69
|
+
batch.status.acknowledged.must_equal acknowledged
|
70
|
+
batch.status.authorisation_failed.must_equal authorisationfailed
|
71
|
+
batch.status.connecting.must_equal connecting
|
72
|
+
batch.status.delivered.must_equal delivered
|
73
|
+
batch.status.failed.must_equal failed
|
74
|
+
batch.status.partially_delivered.must_equal partiallydelivered
|
75
|
+
batch.status.rejected.must_equal rejected
|
76
|
+
batch.status.scheduled.must_equal scheduled
|
77
|
+
batch.status.sent.must_equal sent
|
78
|
+
batch.status.submitted.must_equal submitted
|
79
|
+
batch.status.validity_period_expired.must_equal validityperiodexpired
|
80
|
+
batch.status.cancelled.must_equal cancelled
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Esendex::Responses::Batches do
|
4
|
+
describe '.deserialise' do
|
5
|
+
let(:startindex) { 5 }
|
6
|
+
let(:count) { 2000 }
|
7
|
+
let(:totalcount) { 24565 }
|
8
|
+
|
9
|
+
let(:id) { "642A01A6-A483-44F3-A2F2-A48B1D0FE141" }
|
10
|
+
let(:createdat) { "2012-01-01T12:00:00.000Z" }
|
11
|
+
let(:batchsize) { 1 }
|
12
|
+
let(:persistedbatchsize) { 1 }
|
13
|
+
|
14
|
+
let(:acknowledged) { 0 }
|
15
|
+
let(:authorisationfailed) { 0 }
|
16
|
+
let(:connecting) { 0 }
|
17
|
+
let(:delivered) { 0 }
|
18
|
+
let(:failed) { 0 }
|
19
|
+
let(:partiallydelivered) { 0 }
|
20
|
+
let(:rejected) { 0 }
|
21
|
+
let(:scheduled) { 0 }
|
22
|
+
let(:sent) { 0 }
|
23
|
+
let(:submitted) { 1 }
|
24
|
+
let(:validityperiodexpired) { 0 }
|
25
|
+
let(:cancelled) { 0 }
|
26
|
+
|
27
|
+
let(:accountreference) { "EX0000000" }
|
28
|
+
let(:createdby) { "user@example.com" }
|
29
|
+
let(:batch_name) { "hey my batch" }
|
30
|
+
|
31
|
+
let(:xml) {
|
32
|
+
<<EOS
|
33
|
+
<?xml version="1.0" encoding="utf-8"?>
|
34
|
+
<messagebatches startindex="#{startindex}" count="#{count}" totalcount="#{totalcount}"
|
35
|
+
xmlns="http://api.esendex.com/ns/">
|
36
|
+
<messagebatch id="#{id}"
|
37
|
+
uri="https://api.esendex.com/v1.1/messagebatches/#{id}">
|
38
|
+
<createdat>#{createdat}</createdat>
|
39
|
+
<batchsize>#{batchsize}</batchsize>
|
40
|
+
<persistedbatchsize>#{persistedbatchsize}</persistedbatchsize>
|
41
|
+
<status>
|
42
|
+
<acknowledged>#{acknowledged}</acknowledged>
|
43
|
+
<authorisationfailed>#{authorisationfailed}</authorisationfailed>
|
44
|
+
<connecting>#{connecting}</connecting>
|
45
|
+
<delivered>#{delivered}</delivered>
|
46
|
+
<failed>#{failed}</failed>
|
47
|
+
<partiallydelivered>#{partiallydelivered}</partiallydelivered>
|
48
|
+
<rejected>#{rejected}</rejected>
|
49
|
+
<scheduled>#{scheduled}</scheduled>
|
50
|
+
<sent>#{sent}</sent>
|
51
|
+
<submitted>#{submitted}</submitted>
|
52
|
+
<validityperiodexpired>#{validityperiodexpired}</validityperiodexpired>
|
53
|
+
<cancelled>#{cancelled}</cancelled>
|
54
|
+
</status>
|
55
|
+
<accountreference>#{accountreference}</accountreference>
|
56
|
+
<createdby>#{createdby}</createdby>
|
57
|
+
<name>#{batch_name}</name>
|
58
|
+
</messagebatch>
|
59
|
+
</messagebatches>
|
60
|
+
EOS
|
61
|
+
}
|
62
|
+
|
63
|
+
it 'deserialises xml into a Batches instance' do
|
64
|
+
batches = Esendex::Responses::Batches.deserialise(xml)
|
65
|
+
|
66
|
+
batches.start_index.must_equal startindex
|
67
|
+
batches.count.must_equal count
|
68
|
+
batches.total_count.must_equal totalcount
|
69
|
+
|
70
|
+
batch = batches.batches.first
|
71
|
+
|
72
|
+
batch.id.must_equal id
|
73
|
+
batch.created_at.must_equal createdat
|
74
|
+
batch.batch_size.must_equal batchsize
|
75
|
+
batch.persisted_batch_size.must_equal persistedbatchsize
|
76
|
+
|
77
|
+
batch.account_reference.must_equal accountreference
|
78
|
+
batch.created_by.must_equal createdby
|
79
|
+
batch.name.must_equal batch_name
|
80
|
+
|
81
|
+
batch.status.acknowledged.must_equal acknowledged
|
82
|
+
batch.status.authorisation_failed.must_equal authorisationfailed
|
83
|
+
batch.status.connecting.must_equal connecting
|
84
|
+
batch.status.delivered.must_equal delivered
|
85
|
+
batch.status.failed.must_equal failed
|
86
|
+
batch.status.partially_delivered.must_equal partiallydelivered
|
87
|
+
batch.status.rejected.must_equal rejected
|
88
|
+
batch.status.scheduled.must_equal scheduled
|
89
|
+
batch.status.sent.must_equal sent
|
90
|
+
batch.status.submitted.must_equal submitted
|
91
|
+
batch.status.validity_period_expired.must_equal validityperiodexpired
|
92
|
+
batch.status.cancelled.must_equal cancelled
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Esendex::Responses::Status do
|
4
|
+
describe '.deserialise' do
|
5
|
+
let(:acknowledged) { 0 }
|
6
|
+
let(:authorisationfailed) { 0 }
|
7
|
+
let(:connecting) { 0 }
|
8
|
+
let(:delivered) { 0 }
|
9
|
+
let(:failed) { 0 }
|
10
|
+
let(:partiallydelivered) { 0 }
|
11
|
+
let(:rejected) { 0 }
|
12
|
+
let(:scheduled) { 0 }
|
13
|
+
let(:sent) { 0 }
|
14
|
+
let(:submitted) { 1 }
|
15
|
+
let(:validityperiodexpired) { 0 }
|
16
|
+
let(:cancelled) { 0 }
|
17
|
+
|
18
|
+
let(:xml) {
|
19
|
+
<<EOS
|
20
|
+
<?xml version="1.0" encoding="utf-8"?>
|
21
|
+
<status>
|
22
|
+
<acknowledged>#{acknowledged}</acknowledged>
|
23
|
+
<authorisationfailed>#{authorisationfailed}</authorisationfailed>
|
24
|
+
<connecting>#{connecting}</connecting>
|
25
|
+
<delivered>#{delivered}</delivered>
|
26
|
+
<failed>#{failed}</failed>
|
27
|
+
<partiallydelivered>#{partiallydelivered}</partiallydelivered>
|
28
|
+
<rejected>#{rejected}</rejected>
|
29
|
+
<scheduled>#{scheduled}</scheduled>
|
30
|
+
<sent>#{sent}</sent>
|
31
|
+
<submitted>#{submitted}</submitted>
|
32
|
+
<validityperiodexpired>#{validityperiodexpired}</validityperiodexpired>
|
33
|
+
<cancelled>#{cancelled}</cancelled>
|
34
|
+
</status>
|
35
|
+
EOS
|
36
|
+
}
|
37
|
+
|
38
|
+
it 'deserialises xml into a Status instance' do
|
39
|
+
status = Esendex::Responses::Status.deserialise(xml)
|
40
|
+
|
41
|
+
status.acknowledged.must_equal acknowledged
|
42
|
+
status.authorisation_failed.must_equal authorisationfailed
|
43
|
+
status.connecting.must_equal connecting
|
44
|
+
status.delivered.must_equal delivered
|
45
|
+
status.failed.must_equal failed
|
46
|
+
status.partially_delivered.must_equal partiallydelivered
|
47
|
+
status.rejected.must_equal rejected
|
48
|
+
status.scheduled.must_equal scheduled
|
49
|
+
status.sent.must_equal sent
|
50
|
+
status.submitted.must_equal submitted
|
51
|
+
status.validity_period_expired.must_equal validityperiodexpired
|
52
|
+
status.cancelled.must_equal cancelled
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/xednese/users_spec.rb
CHANGED
@@ -1,18 +1,7 @@
|
|
1
|
-
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
describe Esendex::Users do
|
4
4
|
let(:credentials) { Esendex::Credentials.new('user', 'pass', 'ref') }
|
5
5
|
subject { Esendex::Users.new(credentials) }
|
6
6
|
|
7
|
-
describe '#username' do
|
8
|
-
it 'returns the username' do
|
9
|
-
subject.username.must_equal credentials.username
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#password' do
|
14
|
-
it 'returns the password' do
|
15
|
-
subject.password.must_equal credentials.password
|
16
|
-
end
|
17
|
-
end
|
18
7
|
end
|
data/spec/xednese_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
describe Esendex do
|
4
4
|
|
@@ -6,28 +6,68 @@ describe Esendex do
|
|
6
6
|
let(:credentials) { subject.instance_variable_get(:@credentials) }
|
7
7
|
|
8
8
|
describe '#account' do
|
9
|
-
|
9
|
+
describe 'when account exists' do
|
10
|
+
let(:reference) { mock }
|
11
|
+
let(:account) { mock(reference: reference) }
|
12
|
+
let(:accounts) { [stub(reference: mock),
|
13
|
+
stub(reference: mock),
|
14
|
+
account,
|
15
|
+
stub(reference: mock)] }
|
16
|
+
|
17
|
+
before {
|
18
|
+
Esendex::Accounts
|
19
|
+
.expects(:new)
|
20
|
+
.with(credentials)
|
21
|
+
.returns(accounts)
|
22
|
+
}
|
23
|
+
|
24
|
+
it 'returns the Account with that reference' do
|
25
|
+
subject.account(reference).must_equal account
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'when account does not exist' do
|
30
|
+
let(:reference) { mock }
|
31
|
+
let(:accounts) { [stub(reference: mock),
|
32
|
+
stub(reference: mock),
|
33
|
+
stub(reference: mock)] }
|
34
|
+
|
35
|
+
before {
|
36
|
+
Esendex::Accounts
|
37
|
+
.expects(:new)
|
38
|
+
.with(credentials)
|
39
|
+
.returns(accounts)
|
40
|
+
}
|
41
|
+
|
42
|
+
it 'is nil' do
|
43
|
+
subject.account(reference).must_equal nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#accounts' do
|
49
|
+
let(:accounts) { Object.new }
|
10
50
|
|
11
51
|
it 'returns a new Accounts instance' do
|
12
52
|
Esendex::Accounts
|
13
53
|
.expects(:new)
|
14
54
|
.with(credentials)
|
15
|
-
.returns(
|
55
|
+
.returns(accounts)
|
16
56
|
|
17
|
-
subject.
|
57
|
+
subject.accounts.must_equal accounts
|
18
58
|
end
|
19
59
|
end
|
20
60
|
|
21
|
-
describe '#
|
22
|
-
let(:
|
61
|
+
describe '#batches' do
|
62
|
+
let(:batches) { mock }
|
23
63
|
|
24
|
-
it 'returns a new
|
25
|
-
Esendex::
|
64
|
+
it 'returns a new Batches instance' do
|
65
|
+
Esendex::Batches
|
26
66
|
.expects(:new)
|
27
67
|
.with(credentials)
|
28
|
-
.returns(
|
68
|
+
.returns(batches)
|
29
69
|
|
30
|
-
subject.
|
70
|
+
subject.batches.must_equal batches
|
31
71
|
end
|
32
72
|
end
|
33
73
|
|
@@ -44,7 +84,7 @@ describe Esendex do
|
|
44
84
|
end
|
45
85
|
end
|
46
86
|
|
47
|
-
describe '#
|
87
|
+
describe '#users' do
|
48
88
|
let(:user) { Object.new }
|
49
89
|
|
50
90
|
it 'returns a new Users instance' do
|
@@ -53,7 +93,7 @@ describe Esendex do
|
|
53
93
|
.with(credentials)
|
54
94
|
.returns(user)
|
55
95
|
|
56
|
-
subject.
|
96
|
+
subject.users.must_equal user
|
57
97
|
end
|
58
98
|
end
|
59
99
|
end
|