sms_kit 1.3.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.
- checksums.yaml +15 -0
- data/README.md +118 -0
- data/Rakefile +9 -0
- data/lib/sms_kit.rb +15 -0
- data/lib/sms_kit/config.rb +43 -0
- data/lib/sms_kit/delivery.rb +13 -0
- data/lib/sms_kit/http.rb +28 -0
- data/lib/sms_kit/logging.rb +27 -0
- data/lib/sms_kit/provider.rb +25 -0
- data/lib/sms_kit/providers.rb +3 -0
- data/lib/sms_kit/providers/central_ict.rb +46 -0
- data/lib/sms_kit/providers/mobi_web.rb +54 -0
- data/lib/sms_kit/providers/mobimex.rb +56 -0
- data/lib/sms_kit/providers/sms_trade.rb +77 -0
- data/lib/sms_kit/railtie.rb +7 -0
- data/lib/sms_kit/utils.rb +13 -0
- data/lib/sms_kit/version.rb +3 -0
- data/test/central_ict_test.rb +40 -0
- data/test/config_test.rb +34 -0
- data/test/delivery_test.rb +21 -0
- data/test/fixtures/vcr_cassettes/central_ict/failure.yml +33 -0
- data/test/fixtures/vcr_cassettes/central_ict/success.yml +33 -0
- data/test/fixtures/vcr_cassettes/mobi_web/failure.yml +32 -0
- data/test/fixtures/vcr_cassettes/mobi_web/quick_deliver.yml +32 -0
- data/test/fixtures/vcr_cassettes/mobi_web/success.yml +32 -0
- data/test/fixtures/vcr_cassettes/mobimex/failure.yml +24 -0
- data/test/fixtures/vcr_cassettes/mobimex/success.yml +25 -0
- data/test/fixtures/vcr_cassettes/sms_trade/failure.yml +32 -0
- data/test/fixtures/vcr_cassettes/sms_trade/success.yml +34 -0
- data/test/fixtures/vcr_cassettes/stub_provider/success.yml +22 -0
- data/test/helper.rb +30 -0
- data/test/http_test.rb +22 -0
- data/test/logging_test.rb +21 -0
- data/test/mobi_web_test.rb +46 -0
- data/test/mobimex_test.rb +40 -0
- data/test/provider_test.rb +49 -0
- data/test/sms_trade_test.rb +44 -0
- data/test/utils_test.rb +12 -0
- metadata +187 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'sms_kit/provider'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module SmsKit
|
5
|
+
class SmsTrade < Provider
|
6
|
+
|
7
|
+
ROUTE_BASIC = 'Basic'.freeze
|
8
|
+
ROUTE_GOLD = 'gold'.freeze
|
9
|
+
ROUTE_DIRECT = 'direct'.freeze
|
10
|
+
|
11
|
+
HTTP_ENDPOINT = "https://gateway.smstrade.de/"
|
12
|
+
|
13
|
+
ERROR_CODES = {
|
14
|
+
10 => 'Receiver number not valid',
|
15
|
+
20 => 'Sender number not valid',
|
16
|
+
30 => 'Message text not valid',
|
17
|
+
31 => 'Message type not valid',
|
18
|
+
40 => 'SMS route not valid',
|
19
|
+
50 => 'Identification failed',
|
20
|
+
60 => 'Not enough balance in account',
|
21
|
+
70 => 'Network does not support the route',
|
22
|
+
71 => 'Feature is not possible with the route',
|
23
|
+
80 => 'Handover to SMSC failed',
|
24
|
+
100 => 'SMS has been sent successfully'
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
def deliver
|
28
|
+
response = post URI.encode_www_form params
|
29
|
+
|
30
|
+
if 'ERROR_LOGIN' == response.body
|
31
|
+
raise DeliveryError, "Login failed (ERROR_LOGIN)"
|
32
|
+
end
|
33
|
+
|
34
|
+
parsed_response = response.body.split "\n"
|
35
|
+
status = parsed_response.shift
|
36
|
+
message_id = parsed_response.shift
|
37
|
+
|
38
|
+
if '100' == status
|
39
|
+
message_id.to_i
|
40
|
+
else
|
41
|
+
raise DeliveryError, "#{ERROR_CODES[status.to_i]} (#{status})"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def params
|
46
|
+
default_params.merge(params_from_data).tap do |p|
|
47
|
+
p[:message_id] ||= 1
|
48
|
+
p[:message] ||= data[:text]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def param_names
|
53
|
+
[
|
54
|
+
:message, :to, :from, :route, :dlr, :message_id,
|
55
|
+
:debug, :cost, :count, :response, :ref, :concat, :senddata
|
56
|
+
]
|
57
|
+
end
|
58
|
+
|
59
|
+
def default_params
|
60
|
+
{
|
61
|
+
key: config.gateway_key,
|
62
|
+
from: config.sender,
|
63
|
+
route: config.route,
|
64
|
+
concat: 1,
|
65
|
+
dlr: 1
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def params_from_data
|
70
|
+
data.select { |k, _| param_names.include? k.to_sym }
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
register sms_trade: SmsTrade
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'sms_kit/providers/central_ict'
|
3
|
+
|
4
|
+
SmsKit::CentralICT.configure do |config|
|
5
|
+
config.username = 'user'
|
6
|
+
config.password = 'pass'
|
7
|
+
config.sender = 123456
|
8
|
+
end
|
9
|
+
|
10
|
+
module SmsKit
|
11
|
+
class CentralICTTest < MiniTest::Test
|
12
|
+
|
13
|
+
def text_message
|
14
|
+
{ text: 'foo bar', to: 12345 }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_params
|
18
|
+
message = CentralICT.new text_message
|
19
|
+
assert_equal text_message[:to], message.params[:dst]
|
20
|
+
assert_equal CentralICT.config.sender, message.params[:src]
|
21
|
+
assert_equal text_message[:text], message.params[:body]
|
22
|
+
assert_equal 'message_sender', message.params[:call]
|
23
|
+
assert_equal 'SMS', message.params[:type]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_deliver
|
27
|
+
VCR.use_cassette 'central_ict/success' do
|
28
|
+
assert CentralICT.deliver text_message
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_deliver_fails
|
33
|
+
VCR.use_cassette 'central_ict/failure' do
|
34
|
+
error = assert_raises(SmsKit::DeliveryError) { CentralICT.deliver }
|
35
|
+
assert_match %r{Delivery failed}, error.message
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/test/config_test.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestProvider
|
4
|
+
include SmsKit::Config
|
5
|
+
end
|
6
|
+
|
7
|
+
class ConfigTest < MiniTest::Test
|
8
|
+
|
9
|
+
def test_config
|
10
|
+
TestProvider.config.username = 'foo'
|
11
|
+
TestProvider.config.password = 'bar'
|
12
|
+
TestProvider.config.sender = 12345
|
13
|
+
|
14
|
+
assert_equal 'foo', TestProvider.config.username
|
15
|
+
assert_equal 'bar', TestProvider.config.password
|
16
|
+
assert_equal 12345, TestProvider.config.sender
|
17
|
+
|
18
|
+
instance = TestProvider.new
|
19
|
+
assert_equal 'foo', instance.config.username
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_configure
|
23
|
+
TestProvider.configure do |config|
|
24
|
+
config.username = 'foo'
|
25
|
+
config.password = 'bar'
|
26
|
+
config.sender = 12345
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_equal 'foo', TestProvider.config.username
|
30
|
+
assert_equal 'bar', TestProvider.config.password
|
31
|
+
assert_equal 12345, TestProvider.config.sender
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class DeliveryTest < MiniTest::Test
|
4
|
+
|
5
|
+
def test_delivery
|
6
|
+
VCR.use_cassette 'mobi_web/quick_deliver' do
|
7
|
+
result = SmsKit.deliver :mobi_web, to: 123456789, text: 'hello world'
|
8
|
+
assert 123, result.to_i
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_to_sms
|
13
|
+
VCR.use_cassette 'stub_provider/success', match_requests_on: [ :uri, :body ] do
|
14
|
+
object = StubSms.new
|
15
|
+
|
16
|
+
result = SmsKit.deliver :stub_provider, object
|
17
|
+
assert 123, result.to_i
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.de.centralict.net/controller/cgi/?body&call=message_sender&dst&pin=&src=123456&subject=&type=SMS&uid=
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SmsKit 1.0.0
|
12
|
+
Authorization:
|
13
|
+
- Basic dXNlcjpwYXNz
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code:
|
17
|
+
message:
|
18
|
+
headers: {}
|
19
|
+
body:
|
20
|
+
encoding: US-ASCII
|
21
|
+
string: |
|
22
|
+
initiatorNumber=
|
23
|
+
initiatorCountry=
|
24
|
+
initiatorArea=
|
25
|
+
initiatorRate=0
|
26
|
+
calleeNumber=
|
27
|
+
calleeCountry=
|
28
|
+
calleeArea=
|
29
|
+
calleeRate=0.12
|
30
|
+
sent=0
|
31
|
+
http_version:
|
32
|
+
recorded_at: Thu, 06 Feb 2014 22:16:51 GMT
|
33
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api.de.centralict.net/controller/cgi/?body=foo+bar&call=message_sender&dst=12345&pin=&src=123456&subject=&type=SMS&uid=
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SmsKit 1.0.0
|
12
|
+
Authorization:
|
13
|
+
- Basic dXNlcjpwYXNz
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code:
|
17
|
+
message:
|
18
|
+
headers: {}
|
19
|
+
body:
|
20
|
+
encoding: US-ASCII
|
21
|
+
string: |
|
22
|
+
initiatorNumber=491707304849
|
23
|
+
initiatorCountry=DE
|
24
|
+
initiatorArea=MOBILE
|
25
|
+
initiatorRate=0
|
26
|
+
calleeNumber=491707304849
|
27
|
+
calleeCountry=DE
|
28
|
+
calleeArea=MOBILE
|
29
|
+
calleeRate=0.12
|
30
|
+
sent=1
|
31
|
+
http_version:
|
32
|
+
recorded_at: Thu, 06 Feb 2014 22:16:51 GMT
|
33
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api2.solutions4mobiles.com/bulksms/bulksend.go?charset=8&msgtext=&originator=123456&password=pass&phone=&showDLR=1&username=user
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.8.8
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message:
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Thu, 09 Jan 2014 22:23:56 GMT
|
19
|
+
server:
|
20
|
+
- Apache
|
21
|
+
content-length:
|
22
|
+
- '8'
|
23
|
+
connection:
|
24
|
+
- close
|
25
|
+
content-type:
|
26
|
+
- text/html
|
27
|
+
body:
|
28
|
+
encoding: US-ASCII
|
29
|
+
string: ERROR100
|
30
|
+
http_version:
|
31
|
+
recorded_at: Thu, 09 Jan 2014 22:23:55 GMT
|
32
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api2.solutions4mobiles.com/bulksms/bulksend.go?charset=8&msgtext=hello+world&originator=123456&password=pass&phone=123456789&showDLR=1&username=user
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SmsKit 1.0.0
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message:
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Thu, 09 Jan 2014 22:54:02 GMT
|
19
|
+
server:
|
20
|
+
- Apache
|
21
|
+
content-length:
|
22
|
+
- '5'
|
23
|
+
connection:
|
24
|
+
- close
|
25
|
+
content-type:
|
26
|
+
- text/html
|
27
|
+
body:
|
28
|
+
encoding: US-ASCII
|
29
|
+
string: OK123
|
30
|
+
http_version:
|
31
|
+
recorded_at: Fri, 10 Jan 2014 01:07:45 GMT
|
32
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api2.solutions4mobiles.com/bulksms/bulksend.go?charset=8&msgtext=foo+bar&originator=123456&password=pass&phone=12345&showDLR=1&username=user
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.8.8
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message:
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Thu, 09 Jan 2014 22:54:02 GMT
|
19
|
+
server:
|
20
|
+
- Apache
|
21
|
+
content-length:
|
22
|
+
- '5'
|
23
|
+
connection:
|
24
|
+
- close
|
25
|
+
content-type:
|
26
|
+
- text/html
|
27
|
+
body:
|
28
|
+
encoding: US-ASCII
|
29
|
+
string: OK123
|
30
|
+
http_version:
|
31
|
+
recorded_at: Thu, 09 Jan 2014 22:54:01 GMT
|
32
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://gate.quadra-mm.com/feed/http.asp
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ! '{"user":"user","pass":"pass","dlr":0,"xml":"json","from_number":123456,"number":null,"message":null,"idd":0,"im":0,"route":"","type":"text"}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SmsKit 1.0.0
|
12
|
+
Content-Type:
|
13
|
+
- application/json
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message:
|
18
|
+
headers: {}
|
19
|
+
body:
|
20
|
+
encoding: UTF-8
|
21
|
+
string: '0'
|
22
|
+
http_version:
|
23
|
+
recorded_at: Thu, 06 Feb 2014 04:33:20 GMT
|
24
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://gate.quadra-mm.com/feed/http.asp
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ! '{"user":"user","pass":"pass","dlr":0,"xml":"json","from_number":123456,"number":12345,"message":"foo
|
9
|
+
bar","idd":0,"im":0,"route":"","type":"text"}'
|
10
|
+
headers:
|
11
|
+
User-Agent:
|
12
|
+
- SmsKit 1.0.0
|
13
|
+
Content-Type:
|
14
|
+
- application/json
|
15
|
+
response:
|
16
|
+
status:
|
17
|
+
code: 200
|
18
|
+
message:
|
19
|
+
headers: {}
|
20
|
+
body:
|
21
|
+
encoding: UTF-8
|
22
|
+
string: ! '{"procedure":"SMS Feed","result":1,"description":"DONE: SMS is in the send queue."}'
|
23
|
+
http_version:
|
24
|
+
recorded_at: Thu, 06 Feb 2014 04:33:20 GMT
|
25
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://gateway.smstrade.de/
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: message&to&from=123456&route=Basic&dlr=1&message_id=1
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- SmsKit 1.0.1
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message:
|
16
|
+
headers:
|
17
|
+
content-type:
|
18
|
+
- text/html; charset=ISO-8859-1
|
19
|
+
connection:
|
20
|
+
- close
|
21
|
+
transfer-encoding:
|
22
|
+
- chunked
|
23
|
+
date:
|
24
|
+
- Wed, 10 Dec 2014 12:33:44 GMT
|
25
|
+
server:
|
26
|
+
- lighttpd/1.4.28
|
27
|
+
body:
|
28
|
+
encoding: UTF-8
|
29
|
+
string: '10'
|
30
|
+
http_version:
|
31
|
+
recorded_at: Wed, 10 Dec 2014 12:33:44 GMT
|
32
|
+
recorded_with: VCR 2.9.3
|