smsified 0.1.5 → 0.1.6
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/lib/smsified/helpers.rb +26 -0
- data/lib/smsified/oneapi.rb +0 -26
- data/lib/smsified/subscriptions.rb +3 -3
- data/spec/smsified_spec.rb +21 -6
- metadata +3 -3
data/lib/smsified/helpers.rb
CHANGED
@@ -29,5 +29,31 @@ module Smsified
|
|
29
29
|
|
30
30
|
options
|
31
31
|
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Builds the necessary query string
|
35
|
+
def build_query_string(options)
|
36
|
+
options = camelcase_keys(options)
|
37
|
+
|
38
|
+
query = ''
|
39
|
+
|
40
|
+
options.each do |k,v|
|
41
|
+
if k == :address
|
42
|
+
if RUBY_VERSION.to_f == 1.9
|
43
|
+
if v.instance_of?(String)
|
44
|
+
v.each_line { |address| query += "#{ '&' if query != '' }address=#{CGI.escape address}" }
|
45
|
+
else
|
46
|
+
v.each { |address| query += "#{ '&' if query != '' }address=#{CGI.escape address}" }
|
47
|
+
end
|
48
|
+
else
|
49
|
+
v.each { |address| query += "#{ '&' if query != '' }address=#{CGI.escape address}" }
|
50
|
+
end
|
51
|
+
else
|
52
|
+
query += "#{ '&' if query != '' }#{k.to_s}=#{CGI.escape v}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
query
|
57
|
+
end
|
32
58
|
end
|
33
59
|
end
|
data/lib/smsified/oneapi.rb
CHANGED
@@ -87,31 +87,5 @@ module Smsified
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
##
|
94
|
-
# Builds the necessary query string
|
95
|
-
def build_query_string(options)
|
96
|
-
query = ''
|
97
|
-
|
98
|
-
options.each do |k,v|
|
99
|
-
if k == :address
|
100
|
-
if RUBY_VERSION.to_f == 1.9
|
101
|
-
if v.instance_of?(String)
|
102
|
-
v.each_line { |address| query += "#{ '&' if query != '' }address=#{CGI.escape address}" }
|
103
|
-
else
|
104
|
-
v.each { |address| query += "#{ '&' if query != '' }address=#{CGI.escape address}" }
|
105
|
-
end
|
106
|
-
else
|
107
|
-
v.each { |address| query += "#{ '&' if query != '' }address=#{CGI.escape address}" }
|
108
|
-
end
|
109
|
-
else
|
110
|
-
query += "#{ '&' if query != '' }#{k.to_s}=#{CGI.escape v}"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
query
|
115
|
-
end
|
116
90
|
end
|
117
91
|
end
|
@@ -64,7 +64,7 @@ module Smsified
|
|
64
64
|
def create_outbound_subscription(sender_address, options)
|
65
65
|
Response.new self.class.post("/smsmessaging/outbound/#{sender_address}/subscriptions",
|
66
66
|
:basic_auth => @auth,
|
67
|
-
:body =>
|
67
|
+
:body => build_query_string(options))
|
68
68
|
end
|
69
69
|
|
70
70
|
##
|
@@ -125,7 +125,7 @@ module Smsified
|
|
125
125
|
def update_inbound_subscription(subscription_id, options)
|
126
126
|
Response.new self.class.post("/smsmessaging/inbound/subscriptions/#{subscription_id}",
|
127
127
|
:basic_auth => @auth,
|
128
|
-
:body =>
|
128
|
+
:body => build_query_string(options))
|
129
129
|
end
|
130
130
|
|
131
131
|
##
|
@@ -142,7 +142,7 @@ module Smsified
|
|
142
142
|
def update_outbound_subscription(sender_address, options)
|
143
143
|
Response.new self.class.post("/smsmessaging/outbound/#{sender_address}/subscriptions",
|
144
144
|
:basic_auth => @auth,
|
145
|
-
:body =>
|
145
|
+
:body => build_query_string(options))
|
146
146
|
end
|
147
147
|
end
|
148
148
|
end
|
data/spec/smsified_spec.rb
CHANGED
@@ -12,27 +12,36 @@ describe "Smsified" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "Helpers" do
|
15
|
-
|
15
|
+
before(:all) do
|
16
16
|
class Foo
|
17
17
|
include Smsified::Helpers
|
18
18
|
|
19
|
-
attr_reader :keys
|
19
|
+
attr_reader :keys, :query_string
|
20
20
|
|
21
21
|
def initialize(hash)
|
22
22
|
@keys = camelcase_keys(hash)
|
23
|
+
@query_string = build_query_string(hash)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
@foo = Foo.new({ :destination_address => 'foo',
|
28
|
+
:notify_url => 'bar',
|
29
|
+
:client_correlator => 'baz',
|
30
|
+
:callback_data => 'donkey' })
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'Should camelcase the appropriate keys' do
|
34
|
+
camelcased_keys = @foo.keys
|
30
35
|
|
31
36
|
camelcased_keys[:destinationAddress].should eql 'foo'
|
32
37
|
camelcased_keys[:notifyURL].should eql 'bar'
|
33
38
|
camelcased_keys[:clientCorrelator].should eql 'baz'
|
34
39
|
camelcased_keys[:callbackData].should eql 'donkey'
|
35
40
|
end
|
41
|
+
|
42
|
+
it 'Should build a proper query string' do
|
43
|
+
@foo.query_string.should eql "destinationAddress=foo¬ifyURL=bar&clientCorrelator=baz&callbackData=donkey"
|
44
|
+
end
|
36
45
|
end
|
37
46
|
|
38
47
|
describe "OneAPI" do
|
@@ -109,6 +118,7 @@ describe "Smsified" do
|
|
109
118
|
it "Should send an SMS" do
|
110
119
|
response = @one_api.send_sms(:address => @address, :message => 'Hola from RSpec!', :sender_address => @sender_address)
|
111
120
|
response.data.should eql @message_sent
|
121
|
+
FakeWeb.last_request.body.should eql "message=Hola+from+RSpec%21&address=14155551212"
|
112
122
|
end
|
113
123
|
|
114
124
|
it "Should send an SMS to multiple destinations" do
|
@@ -116,6 +126,7 @@ describe "Smsified" do
|
|
116
126
|
:message => 'Hola from RSpec!',
|
117
127
|
:sender_address => @sender_address)
|
118
128
|
response.data.should eql @message_sent
|
129
|
+
FakeWeb.last_request.body.should eql "message=Hola+from+RSpec%21&address=14155551212&address=13035551212"
|
119
130
|
end
|
120
131
|
|
121
132
|
it "Should raise an error if you pass an unknown method name" do
|
@@ -267,12 +278,14 @@ describe "Smsified" do
|
|
267
278
|
result = @subscriptions.create_inbound_subscription('17177455076', :notify_url => 'http://foobar.com')
|
268
279
|
result.http.code.should eql '200'
|
269
280
|
result.data.should eql @inbound_subscription
|
281
|
+
FakeWeb.last_request.body.should eql "destinationAddress=17177455076¬ifyURL=http%3A%2F%2Ffoobar.com"
|
270
282
|
end
|
271
283
|
|
272
284
|
it 'Should create an outbound subscription' do
|
273
285
|
result = @subscriptions.create_outbound_subscription('17177455076', :notify_url => 'http://foobar.com')
|
274
286
|
result.http.code.should eql '200'
|
275
287
|
result.data.should eql @outbound_subscription
|
288
|
+
FakeWeb.last_request.body.should eql "notifyURL=http%3A%2F%2Ffoobar.com"
|
276
289
|
end
|
277
290
|
end
|
278
291
|
|
@@ -292,12 +305,14 @@ describe "Smsified" do
|
|
292
305
|
|
293
306
|
result.http.code.should eql '200'
|
294
307
|
result.data.should eql @inbound_subscription
|
308
|
+
FakeWeb.last_request.body.should eql "notifyURL=http%3A%2F%2Ffoobar1.com"
|
295
309
|
end
|
296
310
|
|
297
311
|
it 'Should update an outbound subscription' do
|
298
312
|
result = @subscriptions.update_outbound_subscription(@sender_address, :notify_url => 'http://foobar.com')
|
299
313
|
result.http.code.should eql '200'
|
300
314
|
result.data.should eql @outbound_subscription
|
315
|
+
FakeWeb.last_request.body.should eql "notifyURL=http%3A%2F%2Ffoobar.com"
|
301
316
|
end
|
302
317
|
end
|
303
318
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smsified
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Goecke
|