elk 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2794c48c93bfb328ac04cb5d91e5342810dbc001
4
- data.tar.gz: 6aa4c6506326eb8b54d0c3b4d7069e212be7382c
3
+ metadata.gz: cec2cf51647b89d4639431b5e6cad98a4eb1c3ac
4
+ data.tar.gz: 311eb1055230e2545f94fa5e194ff99d6815fdaf
5
5
  SHA512:
6
- metadata.gz: c18b3adef719bf84274a1015460eb93b06108c08ab48efc34598ac571c0330ecf8ecbbeb706ec464608b62739114e6ea79709d3ee876a44cc95a05b8c7d958b8
7
- data.tar.gz: 3b1543b1366eec044563a67e5579e8c76125957b419967cebeac0194160b9b7a81c7f6d13c330fa002f50955a9cab331214415d8b676c3634388d1cccedc82b4
6
+ metadata.gz: e34f77bae51ddfefbb3750df28fa56fe89910a081a6ff872775d2a928dccabca2be5b44ec0ae28e27b5014496825303ace5eb1b9ffe48bdd95a1913f08c925b1
7
+ data.tar.gz: 93c31cf0651316835a997c01ccb688e7b5c1ee6f5321a9ffeeecbfa51ea4758498632e4a1491a921d375db74884f84f74730b7466d8acc78c88de1537c32f847
data/lib/elk/sms.rb CHANGED
@@ -13,7 +13,7 @@ module Elk
13
13
  @to = parameters[:to]
14
14
  @message = parameters[:message]
15
15
  @message_id = parameters[:id]
16
- @created_at = Time.parse(parameters[:created])
16
+ @created_at = Time.parse(parameters[:created]) if parameters[:created]
17
17
  @loaded_at = Time.now
18
18
  @direction = parameters[:direction]
19
19
  @status = parameters[:status]
@@ -38,21 +38,36 @@ module Elk
38
38
  def send(parameters)
39
39
  verify_parameters(parameters, [:from, :message, :to])
40
40
 
41
+ parameters[:to] = Array(parameters[:to]).join(',')
42
+
41
43
  # Warn if the from string will be capped by the sms gateway
42
44
  if parameters[:from] && parameters[:from].match(/^(\w{11,})$/)
43
45
  warn "SMS 'from' value #{parameters[:from]} will be capped at 11 chars"
44
46
  end
45
47
 
46
48
  response = Elk.post('/SMS', parameters)
47
- self.new(Elk.parse_json(response.body))
49
+ parsed_response = Elk.parse_json(response.body)
50
+
51
+ if multiple_recipients?(parameters[:to])
52
+ instantiate_multiple(parsed_response)
53
+ else
54
+ self.new(parsed_response)
55
+ end
48
56
  end
49
57
 
50
58
  # Get outgoing and incomming messages. Limited by the API to 100 latest
51
59
  def all
52
60
  response = Elk.get('/SMS')
53
- Elk.parse_json(response.body)[:data].collect do |n|
54
- self.new(n)
55
- end
61
+ instantiate_multiple(Elk.parse_json(response.body)[:data])
62
+ end
63
+
64
+ private
65
+ def instantiate_multiple(multiple)
66
+ multiple.collect { |n| self.new(n) }
67
+ end
68
+
69
+ def multiple_recipients?(to)
70
+ to.split(',').length > 1
56
71
  end
57
72
  end
58
73
  end
data/lib/elk/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Elk
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
data/spec/elk_spec.rb CHANGED
@@ -192,6 +192,44 @@ describe Elk do
192
192
  sms.status.should == 'delivered'
193
193
  end
194
194
 
195
+
196
+ context 'when sending a SMS to multiple recipients' do
197
+ before do
198
+ stub_request(:post, "https://USERNAME:PASSWORD@api.46elks.com/a1/SMS").
199
+ with(:body => {"from" => "+46761042247", :message => "Your order #171 has now been sent!", :to => "+46704508449,+46704508449"},
200
+ :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/x-www-form-urlencoded'}).
201
+ to_return(fixture('sends_a_sms_to_multiple_recipients.txt'))
202
+
203
+ configure_elk
204
+ end
205
+
206
+ it "sends the SMS when passing `to` as comma separated string" do
207
+ smses = Elk::SMS.send(:from => '+46761042247',
208
+ :to => '+46704508449,+46704508449',
209
+ :message => 'Your order #171 has now been sent!')
210
+
211
+ smses.size.should == 2
212
+ smses[0].class.should == Elk::SMS
213
+ smses[0].to.should == "+46704508449"
214
+
215
+ smses[0].message_id.should == "sb326c7a214f9f4abc90a11bd36d6abc3"
216
+ smses[1].message_id.should == "s47a89d6cc51d8db395d45ae7e16e86b7"
217
+ end
218
+
219
+ it "sends the SMS when passing `to` as array" do
220
+ smses = Elk::SMS.send(:from => '+46761042247',
221
+ :to => ['+46704508449', '+46704508449'],
222
+ :message => 'Your order #171 has now been sent!')
223
+
224
+ smses.size.should == 2
225
+ smses[0].class.should == Elk::SMS
226
+ smses[0].to.should == "+46704508449"
227
+
228
+ smses[0].message_id.should == "sb326c7a214f9f4abc90a11bd36d6abc3"
229
+ smses[1].message_id.should == "s47a89d6cc51d8db395d45ae7e16e86b7"
230
+ end
231
+ end
232
+
195
233
  it 'gets SMS-history' do
196
234
  stub_request(:get, "https://USERNAME:PASSWORD@api.46elks.com/a1/SMS").
197
235
  with(:headers => {'Accept'=>'application/json'}).
@@ -0,0 +1,8 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/0.7.67
3
+ Date: Tue, 05 Jul 2011 15:32:45 GMT
4
+ Content-Type: application/json
5
+ Connection: keep-alive
6
+ Content-Length: 135
7
+
8
+ [{"to": "+46704508449", "id": "sb326c7a214f9f4abc90a11bd36d6abc3"}, { "to": "+46704508449", "id": "s47a89d6cc51d8db395d45ae7e16e86b7"}]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Eckerstroem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-06 00:00:00.000000000 Z
11
+ date: 2013-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -107,6 +107,7 @@ files:
107
107
  - spec/fixtures/reloads_a_number.txt
108
108
  - spec/fixtures/reloads_a_sms.txt
109
109
  - spec/fixtures/sends_a_sms.txt
110
+ - spec/fixtures/sends_a_sms_to_multiple_recipients.txt
110
111
  - spec/fixtures/sends_a_sms_with_long_sender.txt
111
112
  - spec/fixtures/server_error.txt
112
113
  - spec/fixtures/sms_history.txt