burstsms 0.1.1
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 +5 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENCE +20 -0
- data/README.md +128 -0
- data/Rakefile +6 -0
- data/burstsms.gemspec +27 -0
- data/lib/burstsms.rb +37 -0
- data/lib/burstsms/api.rb +78 -0
- data/lib/burstsms/lists_add.rb +30 -0
- data/lib/burstsms/lists_add_recipient.rb +34 -0
- data/lib/burstsms/lists_delete.rb +28 -0
- data/lib/burstsms/lists_delete_recipient.rb +29 -0
- data/lib/burstsms/lists_get.rb +38 -0
- data/lib/burstsms/lists_get_recipients.rb +42 -0
- data/lib/burstsms/lists_get_unsubscribed.rb +42 -0
- data/lib/burstsms/message_responses.rb +41 -0
- data/lib/burstsms/messages_add.rb +39 -0
- data/lib/burstsms/messages_get.rb +44 -0
- data/lib/burstsms/messages_multiple.rb +32 -0
- data/lib/burstsms/version.rb +3 -0
- data/spec/burst_sms_spec.rb +171 -0
- data/spec/contact_lists_spec.rb +188 -0
- data/spec/fixtures/api_requests/lists_add.txt +10 -0
- data/spec/fixtures/api_requests/lists_add_recipient.txt +13 -0
- data/spec/fixtures/api_requests/lists_delete.txt +10 -0
- data/spec/fixtures/api_requests/lists_delete_recipient.txt +11 -0
- data/spec/fixtures/api_requests/lists_get.txt +11 -0
- data/spec/fixtures/api_requests/lists_get_recipients.txt +12 -0
- data/spec/fixtures/api_requests/lists_get_unsubscribed.txt +12 -0
- data/spec/fixtures/api_requests/message_responses.txt +12 -0
- data/spec/fixtures/api_requests/messages_add.txt +12 -0
- data/spec/fixtures/api_requests/messages_get.txt +11 -0
- data/spec/fixtures/api_requests/messages_multiple.txt +12 -0
- data/spec/fixtures/api_responses/generic_failure.txt +7 -0
- data/spec/fixtures/api_responses/lists_add_recipient_success.txt +11 -0
- data/spec/fixtures/api_responses/lists_add_success.txt +12 -0
- data/spec/fixtures/api_responses/lists_delete_recipient_success.txt +8 -0
- data/spec/fixtures/api_responses/lists_delete_success.txt +8 -0
- data/spec/fixtures/api_responses/lists_get_recipients_success.txt +33 -0
- data/spec/fixtures/api_responses/lists_get_success.txt +19 -0
- data/spec/fixtures/api_responses/lists_get_unsubscribed_success.txt +33 -0
- data/spec/fixtures/api_responses/message_responses_success.txt +16 -0
- data/spec/fixtures/api_responses/messages_add_success.txt +17 -0
- data/spec/fixtures/api_responses/messages_get_success.txt +53 -0
- data/spec/fixtures/api_responses/send_message_success.txt +14 -0
- data/spec/spec_helper.rb +36 -0
- metadata +173 -0
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe BurstSms do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@burst = BurstSms::API.new("79798797897", "x")
|
8
|
+
end
|
9
|
+
|
10
|
+
context "'contact-lists.get' - http://burstsms.com.au/api-documentation/contact-lists.get" do
|
11
|
+
it "Builds correct XML structure" do
|
12
|
+
@request_body = @burst.get_lists_body(0,50)
|
13
|
+
@nok_parsed = Nokogiri::XML(@request_body)
|
14
|
+
nodes = ['//request/key', '//request/secret', '//request/version', '//request/method', '//request/params/offset', '//request/params/limit']
|
15
|
+
nodes.each { |n| @nok_parsed.should have_xml(n)}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "Sends correct API request and parses XML response to ruby object" do
|
19
|
+
# This has the potential to fail in ruby-1.8 due to Hash ordering... or lack of it.
|
20
|
+
stub_request(:post, BurstSms::API_URL).with(:body => File.read('spec/fixtures/api_requests/lists_get.txt')).to_return(:status => 200, :body => File.read('spec/fixtures/api_responses/lists_get_success.txt'))
|
21
|
+
@response = @burst.get_lists()
|
22
|
+
@response.total.should == '2'
|
23
|
+
@response.lists.size.should == 2
|
24
|
+
@response.lists.first.id.should == "1"
|
25
|
+
@response.error.should == nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "Create error from failed response" do
|
29
|
+
stub_request(:post, BurstSms::API_URL).to_return(:status => 200, :body => File.read("spec/fixtures/api_responses/generic_failure.txt"))
|
30
|
+
@response = @burst.get_lists()
|
31
|
+
@response.total.should == nil
|
32
|
+
@response.error.should == 'Authentication failed - key: 797987, secret: x'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "'contact-lists.add' - http://burstsms.com.au/api-documentation/contact-lists.add" do
|
37
|
+
it "Builds correct XML structure" do
|
38
|
+
@request_body = @burst.add_list_body("some awesome list name")
|
39
|
+
@nok_parsed = Nokogiri::XML(@request_body)
|
40
|
+
nodes = ['//request/key', '//request/secret', '//request/version', '//request/method', '//request/params/name']
|
41
|
+
nodes.each { |n| @nok_parsed.should have_xml(n)}
|
42
|
+
end
|
43
|
+
|
44
|
+
it "Sends correct API request and parses XML response to ruby object" do
|
45
|
+
# This has the potential to fail in ruby-1.8 due to Hash ordering... or lack of it.
|
46
|
+
stub_request(:post, BurstSms::API_URL).with(:body => File.read('spec/fixtures/api_requests/lists_add.txt')).to_return(:status => 200, :body => File.read('spec/fixtures/api_responses/lists_add_success.txt'))
|
47
|
+
@response = @burst.add_list("some awesome list name")
|
48
|
+
@response.total.should == '1'
|
49
|
+
@response.list_id.should == '1211'
|
50
|
+
@response.error.should == nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "Create error from failed response" do
|
54
|
+
stub_request(:post, BurstSms::API_URL).to_return(:status => 200, :body => File.read("spec/fixtures/api_responses/generic_failure.txt"))
|
55
|
+
@response = @burst.add_list("some awesome list name")
|
56
|
+
@response.total.should == nil
|
57
|
+
@response.error.should == 'Authentication failed - key: 797987, secret: x'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "'contact-lists.delete' - http://burstsms.com.au/api-documentation/contact-lists.delete" do
|
62
|
+
it "Builds correct XML structure" do
|
63
|
+
@request_body = @burst.delete_list_body("123")
|
64
|
+
@nok_parsed = Nokogiri::XML(@request_body)
|
65
|
+
nodes = ['//request/key', '//request/secret', '//request/version', '//request/method', '//request/params/id']
|
66
|
+
nodes.each { |n| @nok_parsed.should have_xml(n)}
|
67
|
+
end
|
68
|
+
|
69
|
+
it "Sends correct API request and parses XML response to ruby object" do
|
70
|
+
# This has the potential to fail in ruby-1.8 due to Hash ordering... or lack of it.
|
71
|
+
stub_request(:post, BurstSms::API_URL).with(:body => File.read('spec/fixtures/api_requests/lists_delete.txt')).to_return(:status => 200, :body => File.read('spec/fixtures/api_responses/lists_delete_success.txt'))
|
72
|
+
@response = @burst.delete_list("123")
|
73
|
+
@response.total.should == '1'
|
74
|
+
@response.response.should == 'DELETED'
|
75
|
+
@response.error.should == nil
|
76
|
+
end
|
77
|
+
|
78
|
+
it "Create error from failed response" do
|
79
|
+
stub_request(:post, BurstSms::API_URL).to_return(:status => 200, :body => File.read("spec/fixtures/api_responses/generic_failure.txt"))
|
80
|
+
@response = @burst.delete_list("123")
|
81
|
+
@response.total.should == nil
|
82
|
+
@response.error.should == 'Authentication failed - key: 797987, secret: x'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "'contact-lists.get-recipients' - http://burstsms.com.au/api-documentation/contact-lists.get-recipients" do
|
87
|
+
it "Builds correct XML structure" do
|
88
|
+
@request_body = @burst.get_list_recipients_body("123", 0, 50)
|
89
|
+
@nok_parsed = Nokogiri::XML(@request_body)
|
90
|
+
nodes = ['//request/key', '//request/secret', '//request/version', '//request/method', '//request/params/id', '//request/params/offset', '//request/params/limit']
|
91
|
+
nodes.each { |n| @nok_parsed.should have_xml(n)}
|
92
|
+
end
|
93
|
+
|
94
|
+
it "Sends correct API request and parses XML response to ruby object" do
|
95
|
+
# This has the potential to fail in ruby-1.8 due to Hash ordering... or lack of it.
|
96
|
+
stub_request(:post, BurstSms::API_URL).with(:body => File.read('spec/fixtures/api_requests/lists_get_recipients.txt')).to_return(:status => 200, :body => File.read('spec/fixtures/api_responses/lists_get_recipients_success.txt'))
|
97
|
+
@response = @burst.get_list_recipients("123")
|
98
|
+
@response.total.should == '3'
|
99
|
+
@response.recipients.size.should == 3
|
100
|
+
@response.recipients.first.lastname.should == 'Doe'
|
101
|
+
@response.error.should == nil
|
102
|
+
end
|
103
|
+
|
104
|
+
it "Create error from failed response" do
|
105
|
+
stub_request(:post, BurstSms::API_URL).to_return(:status => 200, :body => File.read("spec/fixtures/api_responses/generic_failure.txt"))
|
106
|
+
@response = @burst.get_list_recipients("123")
|
107
|
+
@response.total.should == nil
|
108
|
+
@response.error.should == 'Authentication failed - key: 797987, secret: x'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "'contact-lists.get-unsubscribed' - http://burstsms.com.au/api-documentation/contact-lists.get-unsubscribed" do
|
113
|
+
it "Builds correct XML structure" do
|
114
|
+
@request_body = @burst.get_list_unsubscribed_body("123", 0, 50)
|
115
|
+
@nok_parsed = Nokogiri::XML(@request_body)
|
116
|
+
nodes = ['//request/key', '//request/secret', '//request/version', '//request/method', '//request/params/id', '//request/params/offset', '//request/params/limit']
|
117
|
+
nodes.each { |n| @nok_parsed.should have_xml(n)}
|
118
|
+
end
|
119
|
+
|
120
|
+
it "Sends correct API request and parses XML response to ruby object" do
|
121
|
+
# This has the potential to fail in ruby-1.8 due to Hash ordering... or lack of it.
|
122
|
+
stub_request(:post, BurstSms::API_URL).with(:body => File.read('spec/fixtures/api_requests/lists_get_unsubscribed.txt')).to_return(:status => 200, :body => File.read('spec/fixtures/api_responses/lists_get_unsubscribed_success.txt'))
|
123
|
+
@response = @burst.get_list_unsubscribed("123")
|
124
|
+
@response.total.should == '3'
|
125
|
+
@response.recipients.size.should == 3
|
126
|
+
@response.recipients.first.lastname.should == 'Doe'
|
127
|
+
@response.error.should == nil
|
128
|
+
end
|
129
|
+
|
130
|
+
it "Create error from failed response" do
|
131
|
+
stub_request(:post, BurstSms::API_URL).to_return(:status => 200, :body => File.read("spec/fixtures/api_responses/generic_failure.txt"))
|
132
|
+
@response = @burst.get_list_unsubscribed("123")
|
133
|
+
@response.total.should == nil
|
134
|
+
@response.error.should == 'Authentication failed - key: 797987, secret: x'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "'contact-lists.add-recipient' - http://burstsms.com.au/api-documentation/contact-lists.add-recipient" do
|
139
|
+
it "Builds correct XML structure" do
|
140
|
+
@request_body = @burst.add_list_recipient_body("123", '61412123123', :firstname => 'Bob', :lastname => 'Smith')
|
141
|
+
@nok_parsed = Nokogiri::XML(@request_body)
|
142
|
+
nodes = ['//request/key', '//request/secret', '//request/version', '//request/method', '//request/params/list_id', '//request/params/mobile', '//request/params/firstname', '//request/params/lastname']
|
143
|
+
nodes.each { |n| @nok_parsed.should have_xml(n)}
|
144
|
+
end
|
145
|
+
|
146
|
+
it "Sends correct API request and parses XML response to ruby object" do
|
147
|
+
# This has the potential to fail in ruby-1.8 due to Hash ordering... or lack of it.
|
148
|
+
stub_request(:post, BurstSms::API_URL).with(:body => File.read('spec/fixtures/api_requests/lists_add_recipient.txt')).to_return(:status => 200, :body => File.read('spec/fixtures/api_responses/lists_add_recipient_success.txt'))
|
149
|
+
@response = @burst.add_list_recipient("123", '61412123123', :firstname => 'Bob', :lastname => 'Smith')
|
150
|
+
@response.total.should == '1'
|
151
|
+
@response.result.should == 'ADDED'
|
152
|
+
@response.error.should == nil
|
153
|
+
end
|
154
|
+
|
155
|
+
it "Create error from failed response" do
|
156
|
+
stub_request(:post, BurstSms::API_URL).to_return(:status => 200, :body => File.read("spec/fixtures/api_responses/generic_failure.txt"))
|
157
|
+
@response = @burst.add_list_recipient("123", '61412123123', :firstname => 'Bob', :lastname => 'Smith')
|
158
|
+
@response.total.should == nil
|
159
|
+
@response.error.should == 'Authentication failed - key: 797987, secret: x'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "'contact-lists.delete-recipient' - http://burstsms.com.au/api-documentation/contact-lists.delete-recipient" do
|
164
|
+
it "Builds correct XML structure" do
|
165
|
+
@request_body = @burst.delete_list_recipient_body("123", '61412123123')
|
166
|
+
@nok_parsed = Nokogiri::XML(@request_body)
|
167
|
+
nodes = ['//request/key', '//request/secret', '//request/version', '//request/method', '//request/params/list_id', '//request/params/mobile']
|
168
|
+
nodes.each { |n| @nok_parsed.should have_xml(n)}
|
169
|
+
end
|
170
|
+
|
171
|
+
it "Sends correct API request and parses XML response to ruby object" do
|
172
|
+
# This has the potential to fail in ruby-1.8 due to Hash ordering... or lack of it.
|
173
|
+
stub_request(:post, BurstSms::API_URL).with(:body => File.read('spec/fixtures/api_requests/lists_delete_recipient.txt')).to_return(:status => 200, :body => File.read('spec/fixtures/api_responses/lists_delete_recipient_success.txt'))
|
174
|
+
@response = @burst.delete_list_recipient("123", '61412123123')
|
175
|
+
@response.total.should == '1'
|
176
|
+
@response.result.should == 'DELETED'
|
177
|
+
@response.error.should == nil
|
178
|
+
end
|
179
|
+
|
180
|
+
it "Create error from failed response" do
|
181
|
+
stub_request(:post, BurstSms::API_URL).to_return(:status => 200, :body => File.read("spec/fixtures/api_responses/generic_failure.txt"))
|
182
|
+
@response = @burst.delete_list_recipient("123", '61412123123')
|
183
|
+
@response.total.should == nil
|
184
|
+
@response.error.should == 'Authentication failed - key: 797987, secret: x'
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
request=<?xml version="1.0"?>
|
2
|
+
<request>
|
3
|
+
<version>0.3</version>
|
4
|
+
<key>79798797897</key>
|
5
|
+
<secret>x</secret>
|
6
|
+
<method>contact-lists.add-recipient</method>
|
7
|
+
<params>
|
8
|
+
<mobile>61412123123</mobile>
|
9
|
+
<list_id>123</list_id>
|
10
|
+
<firstname>Bob</firstname>
|
11
|
+
<lastname>Smith</lastname>
|
12
|
+
</params>
|
13
|
+
</request>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
request=<?xml version="1.0"?>
|
2
|
+
<request>
|
3
|
+
<version>0.3</version>
|
4
|
+
<key>79798797897</key>
|
5
|
+
<secret>x</secret>
|
6
|
+
<method>contact-lists.get-unsubscribed</method>
|
7
|
+
<params>
|
8
|
+
<offset>0</offset>
|
9
|
+
<limit>50</limit>
|
10
|
+
<id>123</id>
|
11
|
+
</params>
|
12
|
+
</request>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
request=<?xml version="1.0"?>
|
2
|
+
<request>
|
3
|
+
<version>0.3</version>
|
4
|
+
<key>79798797897</key>
|
5
|
+
<secret>x</secret>
|
6
|
+
<method>messages.responses</method>
|
7
|
+
<params>
|
8
|
+
<offset>0</offset>
|
9
|
+
<limit>50</limit>
|
10
|
+
<message_id>123</message_id>
|
11
|
+
</params>
|
12
|
+
</request>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
request=<?xml version="1.0"?>
|
2
|
+
<request>
|
3
|
+
<version>0.3</version>
|
4
|
+
<key>79798797897</key>
|
5
|
+
<secret>x</secret>
|
6
|
+
<method>messages.add</method>
|
7
|
+
<params>
|
8
|
+
<caller_id>6147779990</caller_id>
|
9
|
+
<message>sms%20txt%0A%20of%20words%20and%20such%3A%2F</message>
|
10
|
+
<list_id>1075</list_id>
|
11
|
+
</params>
|
12
|
+
</request>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
request=<?xml version="1.0"?>
|
2
|
+
<request>
|
3
|
+
<version>0.3</version>
|
4
|
+
<key>79798797897</key>
|
5
|
+
<secret>x</secret>
|
6
|
+
<method>messages.multiple</method>
|
7
|
+
<params>
|
8
|
+
<caller_id>6147779990</caller_id>
|
9
|
+
<mobile>61490900900,61490900910,61414899766,61403855445,61487000777</mobile>
|
10
|
+
<message>sms%20txt%0A%20of%20words%20and%20such%3A%2F</message>
|
11
|
+
</params>
|
12
|
+
</request>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<xml>
|
3
|
+
<method>contact-lists.add</method>
|
4
|
+
<total>1</total>
|
5
|
+
<time>2009-12-11 01:47:57 GMT</time>
|
6
|
+
<timestamp>1260496077 GMT</timestamp>
|
7
|
+
<data>
|
8
|
+
<name>New List</name>
|
9
|
+
<recipient_count>0</recipient_count>
|
10
|
+
<id>1211</id>
|
11
|
+
</data>
|
12
|
+
</xml>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<xml>
|
3
|
+
<method>contact-lists.get-recipients</method>
|
4
|
+
<total>3</total>
|
5
|
+
<time>2009-12-21 23:05:02 GMT</time>
|
6
|
+
<timestamp>1261436702 GMT</timestamp>
|
7
|
+
<dataset>
|
8
|
+
<data>
|
9
|
+
<mobile>61404800800</mobile>
|
10
|
+
<firstname>John</firstname>
|
11
|
+
<lastname>Doe</lastname>
|
12
|
+
<datetime_entry>2009-12-11 00:34:23</datetime_entry>
|
13
|
+
<dest_country>AU</dest_country>
|
14
|
+
<bounce_count>0</bounce_count>
|
15
|
+
</data>
|
16
|
+
<data>
|
17
|
+
<mobile>61404600600</mobile>
|
18
|
+
<firstname>Jane</firstname>
|
19
|
+
<lastname>Doe</lastname>
|
20
|
+
<datetime_entry>2009-11-26 13:10:56</datetime_entry>
|
21
|
+
<dest_country>AU</dest_country>
|
22
|
+
<bounce_count>0</bounce_count>
|
23
|
+
</data>
|
24
|
+
<data>
|
25
|
+
<mobile>61404300300</mobile>
|
26
|
+
<firstname>Jim</firstname>
|
27
|
+
<lastname>Citizen</lastname>
|
28
|
+
<datetime_entry>2009-11-26 13:11:11</datetime_entry>
|
29
|
+
<dest_country>AU</dest_country>
|
30
|
+
<bounce_count>0</bounce_count>
|
31
|
+
</data>
|
32
|
+
</dataset>
|
33
|
+
</xml>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<xml>
|
3
|
+
<method>contact-lists.get</method>
|
4
|
+
<total>2</total>
|
5
|
+
<time>2009-12-11 02:47:22 GMT</time>
|
6
|
+
<timestamp>1260499642 GMT</timestamp>
|
7
|
+
<dataset>
|
8
|
+
<data>
|
9
|
+
<id>1</id>
|
10
|
+
<name>My SMS List</name>
|
11
|
+
<recipient_count>3</recipient_count>
|
12
|
+
</data>
|
13
|
+
<data>
|
14
|
+
<id>2</id>
|
15
|
+
<name>My SMS List 2</name>
|
16
|
+
<recipient_count>9</recipient_count>
|
17
|
+
</data>
|
18
|
+
</dataset>
|
19
|
+
</xml>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<xml>
|
3
|
+
<method>contact-lists.get-unsubscribed</method>
|
4
|
+
<total>3</total>
|
5
|
+
<time>2009-12-21 23:05:02 GMT</time>
|
6
|
+
<timestamp>1261436702 GMT</timestamp>
|
7
|
+
<dataset>
|
8
|
+
<data>
|
9
|
+
<mobile>61404800800</mobile>
|
10
|
+
<firstname>John</firstname>
|
11
|
+
<lastname>Doe</lastname>
|
12
|
+
<datetime_entry>2009-12-11 00:34:23</datetime_entry>
|
13
|
+
<dest_country>AU</dest_country>
|
14
|
+
<bounce_count>0</bounce_count>
|
15
|
+
</data>
|
16
|
+
<data>
|
17
|
+
<mobile>61404600600</mobile>
|
18
|
+
<firstname>Jane</firstname>
|
19
|
+
<lastname>Doe</lastname>
|
20
|
+
<datetime_entry>2009-11-26 13:10:56</datetime_entry>
|
21
|
+
<dest_country>AU</dest_country>
|
22
|
+
<bounce_count>0</bounce_count>
|
23
|
+
</data>
|
24
|
+
<data>
|
25
|
+
<mobile>61404300300</mobile>
|
26
|
+
<firstname>Jim</firstname>
|
27
|
+
<lastname>Citizen</lastname>
|
28
|
+
<datetime_entry>2009-11-26 13:11:11</datetime_entry>
|
29
|
+
<dest_country>AU</dest_country>
|
30
|
+
<bounce_count>0</bounce_count>
|
31
|
+
</data>
|
32
|
+
</dataset>
|
33
|
+
</xml>
|