multi_sms 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/multi_sms/providers/sms_provider.rb +3 -3
- data/lib/multi_sms/version.rb +1 -1
- data/lib/multi_sms.rb +5 -1
- data/spec/multi_sms_spec.rb +38 -13
- metadata +3 -3
data/lib/multi_sms/version.rb
CHANGED
data/lib/multi_sms.rb
CHANGED
@@ -13,6 +13,7 @@ end
|
|
13
13
|
|
14
14
|
module MultiSms
|
15
15
|
|
16
|
+
class ConfigError < RuntimeError; end
|
16
17
|
# When the authentication can't be done
|
17
18
|
class AuthError < RuntimeError; end
|
18
19
|
# Raised when the API server isn't working
|
@@ -41,7 +42,7 @@ module MultiSms
|
|
41
42
|
#
|
42
43
|
# Example:
|
43
44
|
# MultiSms.config do |c|
|
44
|
-
# c.
|
45
|
+
# c.default_provider = "Elk"
|
45
46
|
# end
|
46
47
|
#
|
47
48
|
# MultiSms.config.foo # => :bar
|
@@ -51,7 +52,9 @@ module MultiSms
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def send(country_code, parameters)
|
55
|
+
raise ConfigError, "MultiSms needs a default provider configured." unless config.default_provider.instance_of?(String)
|
54
56
|
verify_parameters(parameters, [:from, :message, :to])
|
57
|
+
|
55
58
|
provider = get_provider country_code
|
56
59
|
provider.send(parameters)
|
57
60
|
end
|
@@ -67,6 +70,7 @@ module MultiSms
|
|
67
70
|
def get_provider(country_code)
|
68
71
|
name = config.providers[country_code.to_s]
|
69
72
|
name = config.default_provider unless name
|
73
|
+
|
70
74
|
provider = "Providers::#{name}".split('::').inject(Object) {|o,c| o.const_get c}
|
71
75
|
provider.new
|
72
76
|
end
|
data/spec/multi_sms_spec.rb
CHANGED
@@ -1,24 +1,49 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe MultiSms do
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
config
|
4
|
+
context "with a default provider" do
|
5
|
+
before do
|
6
|
+
MultiSms.config do |config|
|
7
|
+
config.providers = {"46" => "Elk", "47" => "Twilio"}
|
8
|
+
config.default_provider = "Twilio"
|
9
|
+
end
|
7
10
|
end
|
8
|
-
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
it "should raise and exception if #to is missing" do
|
13
|
+
expect{MultiSms.send 46, from: "fake", message: "fake"}.to raise_error(MultiSms::MissingParameter)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise and exception if #from is missing" do
|
17
|
+
expect{MultiSms.send 46, to: "fake", message: "fake"}.to raise_error(MultiSms::MissingParameter)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise and exception if #message is missing" do
|
21
|
+
expect{MultiSms.send 46, to: "fake", from: "fake"}.to raise_error(MultiSms::MissingParameter)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should respond to providers" do
|
25
|
+
MultiSms.providers.should eql ["Clickatell", "Elk", "Twilio"]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should get provider based on swedish country code" do
|
29
|
+
provider = MultiSms.get_provider 46
|
30
|
+
provider.should be_an_instance_of Providers::Elk
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get provider based on norweigan country code" do
|
34
|
+
provider = MultiSms.get_provider 47
|
35
|
+
provider.should be_an_instance_of Providers::Twilio
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not pick default_provider for unconfigured country codes" do
|
39
|
+
provider = MultiSms.get_provider 45
|
40
|
+
provider.should be_an_instance_of Providers::Twilio
|
41
|
+
end
|
13
42
|
|
14
|
-
it "should get provider based on swedish country code" do
|
15
|
-
provider = MultiSms.get_provider 46
|
16
|
-
provider.should be_an_instance_of Providers::Elk
|
17
43
|
end
|
18
44
|
|
19
|
-
it "should
|
20
|
-
|
21
|
-
provider.should be_an_instance_of Providers::Twilio
|
45
|
+
it "should raise and exception if no default provider is configured" do
|
46
|
+
expect{MultiSms.send 46, to: "fake", from: "fake", message: "fake"}.to raise_error(MultiSms::ConfigError)
|
22
47
|
end
|
23
48
|
|
24
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -230,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
230
230
|
version: '0'
|
231
231
|
segments:
|
232
232
|
- 0
|
233
|
-
hash:
|
233
|
+
hash: 2945269217158432553
|
234
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
235
|
none: false
|
236
236
|
requirements:
|
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
239
|
version: '0'
|
240
240
|
segments:
|
241
241
|
- 0
|
242
|
-
hash:
|
242
|
+
hash: 2945269217158432553
|
243
243
|
requirements: []
|
244
244
|
rubyforge_project: multi_sms
|
245
245
|
rubygems_version: 1.8.24
|