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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/README.md +22 -3
  4. data/Rakefile +8 -2
  5. data/bin/xednese +16 -0
  6. data/lib/xednese.rb +36 -9
  7. data/lib/xednese/account.rb +37 -0
  8. data/lib/xednese/account/dispatcher.rb +30 -0
  9. data/lib/xednese/account/messages.rb +47 -0
  10. data/lib/xednese/accounts.rb +14 -6
  11. data/lib/xednese/batch.rb +68 -0
  12. data/lib/xednese/batches.rb +33 -0
  13. data/lib/xednese/client.rb +46 -0
  14. data/lib/xednese/messages.rb +24 -0
  15. data/lib/xednese/requests/account.rb +17 -0
  16. data/lib/xednese/requests/batch.rb +17 -0
  17. data/lib/xednese/requests/messages.rb +1 -1
  18. data/lib/xednese/responses/batch.rb +20 -0
  19. data/lib/xednese/responses/batches.rb +15 -0
  20. data/lib/xednese/responses/status.rb +22 -0
  21. data/lib/xednese/users.rb +3 -8
  22. data/lib/xednese/version.rb +1 -1
  23. data/scenarios/accounts/getting_all_accounts.rb +37 -0
  24. data/scenarios/accounts/getting_an_account.rb +29 -0
  25. data/scenarios/helper.rb +113 -0
  26. data/spec/helper.rb +3 -3
  27. data/spec/xednese/{dispatcher_spec.rb → account/dispatcher_spec.rb} +5 -4
  28. data/spec/xednese/account/messages_spec.rb +56 -0
  29. data/spec/xednese/account_spec.rb +93 -0
  30. data/spec/xednese/accounts_spec.rb +19 -14
  31. data/spec/xednese/batch_spec.rb +121 -0
  32. data/spec/xednese/batches_spec.rb +70 -0
  33. data/spec/xednese/client_spec.rb +76 -2
  34. data/spec/xednese/messages_spec.rb +25 -1
  35. data/spec/xednese/requests/account_spec.rb +20 -0
  36. data/spec/xednese/requests/batch_spec.rb +20 -0
  37. data/spec/xednese/requests/messages_spec.rb +1 -1
  38. data/spec/xednese/responses/account_spec.rb +1 -1
  39. data/spec/xednese/responses/accounts_spec.rb +1 -1
  40. data/spec/xednese/responses/batch_spec.rb +83 -0
  41. data/spec/xednese/responses/batches_spec.rb +95 -0
  42. data/spec/xednese/responses/message_dispatcher_headers_spec.rb +1 -1
  43. data/spec/xednese/responses/message_header_spec.rb +1 -1
  44. data/spec/xednese/responses/message_headers_spec.rb +1 -1
  45. data/spec/xednese/responses/status_spec.rb +55 -0
  46. data/spec/xednese/users_spec.rb +1 -12
  47. data/spec/xednese_spec.rb +52 -12
  48. metadata +58 -8
  49. data/lib/xednese/dispatcher.rb +0 -20
@@ -0,0 +1,93 @@
1
+ require 'helper'
2
+
3
+ describe Esendex::Account do
4
+ let(:response) { mock }
5
+ let(:credentials) { dummy_credentials }
6
+ subject { Esendex::Account.new(credentials, response) }
7
+
8
+ [:id, :reference, :address, :messages_remaining,
9
+ :type, :expires_on, :role].each do |value|
10
+ describe "##{value}" do
11
+ before {
12
+ @value = mock
13
+ response.expects(value).returns(@value)
14
+ }
15
+
16
+ it "returns the #{value} from the response" do
17
+ subject.send(value).must_equal @value
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '#label' do
23
+ let(:label) { mock }
24
+ before { response.expects(:label).returns(label) }
25
+
26
+ it 'returns the label from the response' do
27
+ subject.label.must_equal label
28
+ end
29
+ end
30
+
31
+ describe '#label=' do
32
+ let(:id) { "587329572387275372" }
33
+ let(:new_label) { "this is my account" }
34
+ let(:request) { mock }
35
+
36
+ before {
37
+ subject
38
+ .expects(:id)
39
+ .returns(id)
40
+
41
+ Esendex::Requests::Account
42
+ .expects(:new)
43
+ .with(label: new_label)
44
+ .returns(request)
45
+
46
+ Esendex::Client
47
+ .expects(:put)
48
+ .with(credentials, "v1.0/accounts/#{id}", request)
49
+ .yields(200)
50
+ }
51
+
52
+ it 'sets the label for the account' do
53
+ (subject.label = new_label).must_equal new_label
54
+ end
55
+
56
+ it 'makes #label return the new label' do
57
+ subject.label = new_label
58
+ subject.label.must_equal new_label
59
+ end
60
+ end
61
+
62
+ describe '#dispatcher' do
63
+ let(:reference) { mock }
64
+ let(:dispatcher) { mock }
65
+
66
+ it 'returns a new Dispatcher instance' do
67
+ subject.expects(:reference).returns(reference)
68
+
69
+ Esendex::Account::Dispatcher
70
+ .expects(:new)
71
+ .with(credentials, reference)
72
+ .returns(dispatcher)
73
+
74
+ subject.dispatcher.must_equal dispatcher
75
+ end
76
+ end
77
+
78
+ describe '#messages' do
79
+ let(:reference) { mock }
80
+ let(:messages) { mock }
81
+
82
+ it 'returns a new Messages instance' do
83
+ subject.expects(:reference).returns(reference)
84
+
85
+ Esendex::Account::Messages
86
+ .expects(:new)
87
+ .with(credentials, reference)
88
+ .returns(messages)
89
+
90
+ subject.messages.must_equal messages
91
+ end
92
+ end
93
+ end
@@ -1,19 +1,14 @@
1
- require_relative '../helper'
1
+ require 'helper'
2
2
 
3
3
  describe Esendex::Accounts do
4
- let(:credentials) { Esendex::Credentials.new('user', 'pass', 'ref') }
4
+ let(:credentials) { dummy_credentials }
5
5
  subject { Esendex::Accounts.new(credentials) }
6
6
 
7
- describe '#reference' do
8
- it 'returns the account reference' do
9
- subject.reference.must_equal credentials.account_reference
10
- end
11
- end
12
-
13
7
  describe '#each' do
14
8
  let(:data) { mock }
9
+ let(:data_list) { [mock, mock] }
10
+ let(:accounts) { stub(accounts: data_list) }
15
11
  let(:account_list) { [mock, mock] }
16
- let(:accounts) { stub(accounts: account_list) }
17
12
 
18
13
  before {
19
14
  Esendex::Client
@@ -29,7 +24,11 @@ describe Esendex::Accounts do
29
24
 
30
25
  accounts
31
26
  .expects(:accounts)
32
- .returns(account_list)
27
+ .returns(data_list)
28
+
29
+ data_list.zip(account_list).each do |d, a|
30
+ Esendex::Account.expects(:new).with(credentials, d).returns(a)
31
+ end
33
32
  }
34
33
 
35
34
  it 'retrieves all accounts' do
@@ -43,9 +42,10 @@ describe Esendex::Accounts do
43
42
  end
44
43
 
45
44
  describe '#get' do
46
- let(:id) { "heyohid" }
47
- let(:data) { mock }
48
- let(:account) { mock }
45
+ let(:id) { SecureRandom.uuid }
46
+ let(:data) { mock }
47
+ let(:response) { mock }
48
+ let(:account) { mock }
49
49
 
50
50
  before {
51
51
  Esendex::Client
@@ -57,10 +57,15 @@ describe Esendex::Accounts do
57
57
  Esendex::Responses::Account
58
58
  .expects(:deserialise)
59
59
  .with(data)
60
+ .returns(response)
61
+
62
+ Esendex::Account
63
+ .expects(:new)
64
+ .with(credentials, response)
60
65
  .returns(account)
61
66
  }
62
67
 
63
- it 'retrieves the specified accounts' do
68
+ it 'retrieves the specified account' do
64
69
  subject.get(id).must_equal account
65
70
  end
66
71
  end
@@ -0,0 +1,121 @@
1
+ require 'helper'
2
+
3
+ describe Esendex::Batch do
4
+ let(:credentials) { dummy_credentials }
5
+ let(:response) { mock }
6
+ subject { Esendex::Batch.new(credentials, response) }
7
+
8
+ [:id, :created_at, :batch_size, :persisted_batch_size,
9
+ :account_reference, :created_by, :name].each do |thing|
10
+ describe "##{thing}" do
11
+ before {
12
+ @value = mock
13
+ response.expects(thing).returns(@value)
14
+ }
15
+
16
+ it "returns the #{thing} from the response" do
17
+ subject.send(thing).must_equal @value
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '#status' do
23
+ let(:status) { mock(acknowledged: 0,
24
+ authorisation_failed: 0,
25
+ connecting: 0,
26
+ delivered: 0,
27
+ failed: 0,
28
+ partially_delivered: 0,
29
+ rejected: 0,
30
+ scheduled: 0,
31
+ sent: 0,
32
+ submitted: 0,
33
+ validity_period_expired: 0,
34
+ cancelled: 1) }
35
+
36
+ before {
37
+ response.expects(:status).returns(status)
38
+ }
39
+
40
+ it 'returns the status that is set to 1' do
41
+ subject.status.must_equal :cancelled
42
+ end
43
+ end
44
+
45
+ describe '#name=' do
46
+ let(:id) { SecureRandom.uuid }
47
+ let(:new_name) { "this is my batch" }
48
+ let(:request) { mock }
49
+
50
+ before {
51
+ subject
52
+ .expects(:id)
53
+ .returns(id)
54
+
55
+ Esendex::Requests::Batch
56
+ .expects(:new)
57
+ .with(name: new_name)
58
+ .returns(request)
59
+
60
+ Esendex::Client
61
+ .expects(:put)
62
+ .with(credentials, "v1.1/messagebatches/#{id}", request)
63
+ .yields(204)
64
+ }
65
+
66
+ it 'sets the name of the batch' do
67
+ (subject.name = new_name).must_equal new_name
68
+ end
69
+
70
+ it 'makes #name return the new name' do
71
+ subject.name = new_name
72
+ subject.name.must_equal new_name
73
+ end
74
+ end
75
+
76
+ describe '#cancel!' do
77
+ let(:id) { SecureRandom.uuid }
78
+ let(:request) { mock }
79
+
80
+ before {
81
+ subject.expects(:id).returns(id)
82
+
83
+ Esendex::Client
84
+ .expects(:delete)
85
+ .with(credentials, "v1.1/messagebatches/#{id}/schedule")
86
+ .yields(204)
87
+ }
88
+
89
+ it 'cancels the message batch' do
90
+ subject.cancel!
91
+ end
92
+ end
93
+
94
+ describe '#messages' do
95
+ let(:id) { SecureRandom.uuid }
96
+ let(:xml) { mock }
97
+ let(:first_message) { mock }
98
+ let(:parsed_messages) { stub(message_headers: [first_message]) }
99
+
100
+ before {
101
+ subject.expects(:id).returns(id)
102
+
103
+ Esendex::Client
104
+ .expects(:get)
105
+ .with(credentials, "v1.0/messagebatches/#{id}/messages",
106
+ startIndex: 0, count: 25)
107
+ .yields(200, xml)
108
+ .returns(parsed_messages.message_headers)
109
+
110
+ Esendex::Responses::MessageHeaders
111
+ .expects(:deserialise)
112
+ .with(xml)
113
+ .returns(parsed_messages)
114
+ }
115
+
116
+ it 'returns the messages in the batch' do
117
+ messages = subject.messages
118
+ messages.first.must_equal first_message
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,70 @@
1
+ require 'helper'
2
+
3
+ describe Esendex::Batches do
4
+ let(:credentials) { dummy_credentials }
5
+ subject { Esendex::Batches.new(credentials) }
6
+
7
+ describe '#each' do
8
+ let(:data) { mock }
9
+ let(:data_list) { [mock, mock] }
10
+ let(:batches) { stub(batches: data_list) }
11
+ let(:batch_list) { [mock, mock] }
12
+
13
+ before {
14
+ Esendex::Client
15
+ .expects(:get)
16
+ .with(credentials, 'v1.1/messagebatches')
17
+ .yields(200, data)
18
+ .returns(batch_list)
19
+
20
+ Esendex::Responses::Batches
21
+ .expects(:deserialise)
22
+ .with(data)
23
+ .returns(batches)
24
+
25
+ batches.expects(:batches).returns(data_list)
26
+
27
+ data_list.zip(batch_list).each do |d, b|
28
+ Esendex::Batch.expects(:new).with(credentials, d).returns(b)
29
+ end
30
+ }
31
+
32
+ it 'retrieves all batches' do
33
+ returned_batches = []
34
+ subject.each do |batch|
35
+ returned_batches << batch
36
+ end
37
+
38
+ returned_batches.must_equal batch_list
39
+ end
40
+ end
41
+
42
+ describe '#get' do
43
+ let(:id) { SecureRandom.uuid }
44
+ let(:data) { mock }
45
+ let(:response) { mock }
46
+ let(:batch) { mock }
47
+
48
+ before {
49
+ Esendex::Client
50
+ .expects(:get)
51
+ .with(credentials, "v1.1/messagebatches/#{id}")
52
+ .yields(200, data)
53
+ .returns(batch)
54
+
55
+ Esendex::Responses::Batch
56
+ .expects(:deserialise)
57
+ .with(data)
58
+ .returns(response)
59
+
60
+ Esendex::Batch
61
+ .expects(:new)
62
+ .with(credentials, response)
63
+ .returns(batch)
64
+ }
65
+
66
+ it 'retrieves the specified message batch' do
67
+ subject.get(id).must_equal batch
68
+ end
69
+ end
70
+ end
@@ -1,4 +1,4 @@
1
- require_relative '../helper'
1
+ require 'helper'
2
2
 
3
3
  describe Esendex::Client do
4
4
  subject { Esendex::Client }
@@ -39,6 +39,38 @@ describe Esendex::Client do
39
39
  body.must_equal expected_body
40
40
  end
41
41
  end
42
+ describe '.get' do
43
+ let(:credentials) { dummy_credentials }
44
+ let(:path) { "some/url/path" }
45
+
46
+ let(:expected_code) { 418 }
47
+ let(:expected_body) { "Hi I'm a body" }
48
+
49
+ let(:uri) { mock }
50
+ let(:http) { mock }
51
+ let(:get_request) { mock }
52
+
53
+ before {
54
+ subject.expects(:url).with(path).returns(uri)
55
+
56
+ subject
57
+ .expects(:execute)
58
+ .with(credentials, get_request)
59
+ .returns([expected_code, expected_body])
60
+
61
+ Net::HTTP::Delete.expects(:new).with(uri).returns(get_request)
62
+ }
63
+
64
+ it 'returns the expected status code' do
65
+ code, _ = subject.delete(credentials, path)
66
+ code.must_equal expected_code
67
+ end
68
+
69
+ it 'returns the expected body' do
70
+ _, body = subject.delete(credentials, path)
71
+ body.must_equal expected_body
72
+ end
73
+ end
42
74
 
43
75
  describe '.post' do
44
76
  let(:credentials) { dummy_credentials }
@@ -83,11 +115,53 @@ describe Esendex::Client do
83
115
  end
84
116
  end
85
117
 
118
+ describe '.put' do
119
+ let(:credentials) { dummy_credentials }
120
+
121
+ let(:path) { "some/url/path?query=yah" }
122
+
123
+ let(:expected_code) { 418 }
124
+ let(:expected_body) { "Hi I'm a body" }
125
+
126
+ let(:xml) { "</xml>" }
127
+ let(:serialisable_object) { stub(serialise: xml) }
128
+ let(:post_request) { mock }
129
+
130
+ before {
131
+ subject
132
+ .expects(:execute)
133
+ .with(credentials, post_request)
134
+ .returns([expected_code, expected_body])
135
+
136
+ Net::HTTP::Put
137
+ .expects(:new)
138
+ .with(subject::ROOT + path)
139
+ .returns(post_request)
140
+
141
+ post_request
142
+ .expects(:body=)
143
+ .with(xml)
144
+
145
+ post_request
146
+ .expects(:content_type=)
147
+ .with('application/xml')
148
+ }
149
+
150
+ it 'returns the expected status code' do
151
+ code, _ = subject.put(credentials, path, serialisable_object)
152
+ code.must_equal expected_code
153
+ end
154
+
155
+ it 'returns the expected body' do
156
+ _, body = subject.put(credentials, path, serialisable_object)
157
+ body.must_equal expected_body
158
+ end
159
+ end
86
160
 
87
161
  describe '.execute' do
88
162
  let(:username) { 'myusername' }
89
163
  let(:password) { 'mypassword' }
90
- let(:credentials) { Esendex::Credentials.new(username, password, 'EX00') }
164
+ let(:credentials) { Esendex::Credentials.new(username, password) }
91
165
 
92
166
  let(:expected_code) { 418 }
93
167
  let(:expected_body) { "Hi I'm a body" }