mblox 0.4.1 → 0.4.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTcwM2ZhN2QyZDFjZjc3NDk5NDhmN2NkYTNiNGIyZDdlNzdkMjEwYQ==
4
+ Nzk1MWJlNGZlNzNhZWU2YTQ3OTMxNDUzYmRiMTk1MDYyNGE5YmI2YQ==
5
5
  data.tar.gz: !binary |-
6
- MDQ3Yzc3ZWRhNGM3YWJlNGE3N2JjZjY3NTcyNWQ0MDUxYTZhNzQ4NA==
6
+ NmVmM2U3MTdhYWE3NDdkZGMwNjgzOGE3NTkxNjE3YTM3MTE0YWZiMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWIyMWI2YzEwYWFiNjYyZWMzYmRiODViZmRjYzMzODlkZTUwNDVhOTA5YTFm
10
- OWM3ZTk1OWYxMTE3NjEzZTkwZmNlMjQ0MzM0ZTg4NDFkYTQ3YWQwMTQ5MTE2
11
- YjFhZmFmZDRlOTI5YjliYTg3MzY1YTNkMjI4NWE4YmIyZmI4MmM=
9
+ NDhlYjI3ODQwNTI0MGM3MmE4YzdkZjczMmQ3ZTY5YzY0YTA0NzZhMjkwMDA4
10
+ MmJmNGNiYzk2NTk1Nzc5NjdlYmM4NTQyMDExZTk4ZTE1YTMwMjg5ZWU2ODE4
11
+ OGE1YzFjZjliZjdjMDhmMjBmYjQyNDhiM2MwZDljZGViMmU2NDA=
12
12
  data.tar.gz: !binary |-
13
- MWZlOWM0ZjhjY2QzYzZiY2U3YTgwZjRmNTM4OTY1NzAzM2MwOGMzZDkxMzM2
14
- Zjc4M2RkODY2M2MwYzU4OTJjMWVhYTk1Yzk2YzhjMGJhNzI2ODkxODY2MjU4
15
- MTNjN2U5ZjEwMDQwZWM3OWE2Y2UzM2Q4ZGI4OTc5ODE2OTFhYzg=
13
+ YzdiNDQ0MzI1MDA3MTYyN2NlZmNjYzdiNDQ0MDY2MGM4ODU4YTQ5MzFkYTIy
14
+ OTg3MDIzNmQzZTczNjJkNzg2ZDUzYzRiZjUxY2M5YWRmZDZiYmUzMmRkYmZj
15
+ MTYzNTA2NTBiMWJkZjAyMTQ0ZmI2ZDkzNTE4NTk1YmZkNTdlNDg=
data/lib/mblox.rb CHANGED
@@ -9,5 +9,8 @@ module Mblox
9
9
  def log *args
10
10
  self.config.logger.__send__(self.config.log_level, *args) if self.config.logger
11
11
  end
12
+ def is_a_five_digit_number?(_)
13
+ ((_.is_a?(Fixnum) || _.is_a?(String)) && 5 == _.to_i.to_s.size)
14
+ end
12
15
  end
13
16
  end
data/lib/mblox/sms.rb CHANGED
@@ -38,9 +38,13 @@ module Mblox
38
38
  @batch_id = batch_id.to_i unless batch_id.blank?
39
39
  end
40
40
 
41
- def send_from(_)
42
- raise InvalidSenderIdError, "You can only send from a 5-digit shortcode" unless ((_.is_a?(Fixnum) || _.is_a?(String)) && 5 == _.to_i.to_s.size)
43
- @sender_id = _.to_i.to_s
41
+ def send_from(sender_id, service_id=nil)
42
+ raise InvalidSenderIdError, "You can only send from a 5-digit shortcode" unless Mblox.is_a_five_digit_number?(sender_id)
43
+ @sender_id = sender_id.to_i.to_s
44
+ unless service_id.nil?
45
+ raise InvalidSenderIdError, "You can only send using a 5-digit service ID. Leave out the 2nd argument of send_from to use the globally configured '#{Mblox.config.service_id}'" unless Mblox.is_a_five_digit_number?(service_id)
46
+ @service_id = service_id.to_i.to_s
47
+ end
44
48
  end
45
49
 
46
50
  def send
@@ -75,7 +79,7 @@ module Mblox
75
79
  n.Subscriber do |s|
76
80
  s.SubscriberNumber(@phone)
77
81
  end
78
- n.ServiceId(Mblox.config.service_id)
82
+ n.ServiceId(@service_id || Mblox.config.service_id)
79
83
  end
80
84
  end
81
85
  end
data/lib/mblox/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mblox
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
data/mblox.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["iybetesh@gmail.com"]
11
11
  spec.description = "Send SMS messages"
12
12
  spec.summary = `cat README.md`
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/betesh/mblox/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
data/spec/sms_spec.rb CHANGED
@@ -189,24 +189,65 @@ describe Mblox::Sms do
189
189
  before(:each) do
190
190
  @sms = Mblox::Sms.new(TEST_NUMBER,'This message should come from shortcode 55555')
191
191
  end
192
- def raise_invalid_sender_id_error
193
- raise_error(Mblox::Sms::InvalidSenderIdError, 'You can only send from a 5-digit shortcode')
194
- end
195
- it "should not allow a 4-digit number" do
196
- expect{@sms.send_from(1234)}.to raise_invalid_sender_id_error
197
- end
198
- it "should not allow a 6-digit number" do
199
- expect{@sms.send_from(123456)}.to raise_invalid_sender_id_error
200
- end
201
- it "should not allow a blank string" do
202
- expect{@sms.send_from('')}.to raise_invalid_sender_id_error
192
+
193
+ describe "sender_id" do
194
+ def raise_invalid_sender_id_error
195
+ raise_error(Mblox::Sms::InvalidSenderIdError, 'You can only send from a 5-digit shortcode')
196
+ end
197
+ it "cannot be a 4-digit number" do
198
+ expect{@sms.send_from(1234)}.to raise_invalid_sender_id_error
199
+ end
200
+ it "cannot be a 6-digit number" do
201
+ expect{@sms.send_from(123456)}.to raise_invalid_sender_id_error
202
+ end
203
+ it "cannot be a blank string" do
204
+ expect{@sms.send_from('')}.to raise_invalid_sender_id_error
205
+ end
206
+ it "cannot be a float" do
207
+ expect{@sms.send_from(12345.6)}.to raise_invalid_sender_id_error
208
+ end
209
+ it "cannot be nil" do
210
+ expect{@sms.send_from(nil)}.to raise_invalid_sender_id_error
211
+ end
203
212
  end
204
- it "should not allow a float" do
205
- expect{@sms.send_from(12345.6)}.to raise_invalid_sender_id_error
213
+
214
+ describe "service_id" do
215
+ def raise_invalid_service_id
216
+ raise_error(Mblox::Sms::InvalidSenderIdError, "You can only send using a 5-digit service ID. Leave out the 2nd argument of send_from to use the globally configured '#{Mblox.config.service_id}'")
217
+ end
218
+ it "cannot be a 4-digit number" do
219
+ expect{@sms.send_from(Mblox.config.sender_id, 1234)}.to raise_invalid_service_id
220
+ end
221
+ it "cannot be a 6-digit number" do
222
+ expect{@sms.send_from(Mblox.config.sender_id, 123456)}.to raise_invalid_service_id
223
+ end
224
+ it "cannot be a blank string" do
225
+ expect{@sms.send_from(Mblox.config.sender_id, '')}.to raise_invalid_service_id
226
+ end
227
+ it "cannot be a float" do
228
+ expect{@sms.send_from(Mblox.config.sender_id, 12345.6)}.to raise_invalid_service_id
229
+ end
230
+ it "can be nil" do
231
+ expect{@sms.send_from(Mblox.config.sender_id, nil)}.to_not raise_error
232
+ end
206
233
  end
207
- it "should send from the value" do
234
+
235
+ it "should send from the specified sender_id" do
236
+ @sms.instance_variable_get("@sender_id").should be_nil
208
237
  expect{@sms.send_from(55555)}.to_not raise_error
209
238
  @sms.send.first.ok?.should be_true
239
+ @sms.instance_variable_get("@sender_id").should == "55555"
240
+ end
241
+
242
+ it "should send from the specified sender_id and service_id" do
243
+ @sms.instance_variable_get("@service_id").should be_nil
244
+ expect{@sms.send_from(55555, 44444)}.to_not raise_error
245
+ response = @sms.send.first
246
+ response.should_not be_ok
247
+ response.request.should be_ok
248
+ response.result.should be_ok
249
+ response.subscriber_result.should == Mblox::SmsResponse::Result.new(10, "MsipRejectCode=63 Invalid ServiceId:2e Do not retry:2e")
250
+ @sms.instance_variable_get("@service_id").should == "44444"
210
251
  end
211
252
  end
212
253
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mblox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Betesh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,7 +150,7 @@ files:
150
150
  - spec/sms_response_spec.rb
151
151
  - spec/sms_spec.rb
152
152
  - spec/spec_helper.rb
153
- homepage: ''
153
+ homepage: https://github.com/betesh/mblox/
154
154
  licenses:
155
155
  - MIT
156
156
  metadata: {}