smster_ruby 1.1.6 → 1.2.0

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: 0c4917706290984b73b76a3cbfb9412bf567f0f7
4
- data.tar.gz: 2f967e091ad1c9d830b3e27d8a6a3a7aa33b72cf
3
+ metadata.gz: e770a6687fb2f4649423933c1c992c7a85c47f1c
4
+ data.tar.gz: 2f4f85bb85ae13db5d1568cfc31747cc79112c15
5
5
  SHA512:
6
- metadata.gz: 578c2e9aec36f46c532b954336f3730bdf71d4450ea2f42ba206e870df42e1fc43190d716ec9a828ef7b2d9656ca3ebc3b90f3c801759bf5f54848407507a90c
7
- data.tar.gz: f67f0038010cca55a589a470b09c639b57daac964d3918f9bcd8359f28252c8b4b3ffe75f8626eafc7e4794024865fad53c65e2381658184ac9a82fd7a67cb9b
6
+ metadata.gz: 75a4f23915602850b4224dd43662cdccd1cfe38124527d12bae3fcfb6b448df261918b43e8bacae3a0d4b4ffbe70f0d30550ccb061f73c78f80ae696d517f378
7
+ data.tar.gz: b1673ef9142e0a62f2ce48358568d90a02f4031abec65a91b64a9259ec03ce7b73e7118dda44e67400739e58e4d8a6bcb90880614a3d0dd70d562f1460073ee7
@@ -1,13 +1,16 @@
1
1
  module Smster
2
2
  class Configuration
3
3
  attr_accessor :nexmo_key, :nexmo_sekret,
4
- :smsru_api_id, :clickatell_authorization_code
4
+ :smsru_api_id, :clickatell_authorization_code,
5
+ :smsru_uslugi_login, :smsru_uslugi_pwd
5
6
 
6
7
  def initialize
7
8
  @nexmo_key = ''
8
9
  @nexmo_sekret = ''
9
10
  @clickatell_authorization_code = ''
10
11
  @smsru_api_id = ''
12
+ @smsru_uslugi_login = ''
13
+ @smsru_uslugi_pwd = ''
11
14
  end
12
15
  end
13
16
  end
@@ -2,8 +2,6 @@ class Sms::Clickatell < SmsLayer
2
2
  attr_accessor :unicode, :clickatell_auth_code
3
3
 
4
4
  def clickatell_auth_code
5
- config = Smster.configuration
6
-
7
5
  @clickatell_auth_code = config.clickatell_authorization_code
8
6
  end
9
7
 
@@ -7,8 +7,6 @@ class Sms::Nexmo < SmsLayer
7
7
  end
8
8
 
9
9
  def send_request
10
- config = Smster.configuration
11
-
12
10
  RestClient.post(
13
11
  'https://rest.nexmo.com/sms/json',
14
12
  text: text,
@@ -0,0 +1,57 @@
1
+ class Sms::SmsUslugi < SmsLayer
2
+ attr_accessor :onlydelivery, :use_alfasource, :flash,
3
+ :date_time_send, :discount_id
4
+
5
+ private
6
+
7
+ def modify_params
8
+ self.to = to.gsub(/\D/, '')
9
+ end
10
+
11
+ def send_request
12
+ RestClient.post("#{base_url}/sendSms.php", options)
13
+ end
14
+
15
+ def assign_attrs_by(response)
16
+ json_response = JSON.parse(response)
17
+
18
+ self.status_message = json_response['descr']
19
+ self.api_message_id = json_response['smsid']
20
+ self.cost = json_response['priceOfSending']
21
+ end
22
+
23
+ def base_url
24
+ 'https://lcab.sms-uslugi.ru/lcabApi'
25
+ end
26
+
27
+ def options
28
+ opts = [auth_options, msg_options, additional_options]
29
+
30
+ opts.inject(&:merge)
31
+ end
32
+
33
+ def auth_options
34
+ {
35
+ login: config.smsru_uslugi_login,
36
+ password: config.smsru_uslugi_pwd
37
+ }
38
+ end
39
+
40
+ def msg_options
41
+ {
42
+ txt: text,
43
+ to: to,
44
+ source: name
45
+ }
46
+ end
47
+
48
+ def additional_options
49
+ {
50
+ onlydelivery: onlydelivery,
51
+ use_alfasource: use_alfasource,
52
+ flash: flash,
53
+ dateTimeSend: date_time_send,
54
+ discountID: discount_id
55
+ }
56
+ end
57
+ end
@@ -2,8 +2,6 @@ class Sms::Smsru < SmsLayer
2
2
  attr_accessor :test, :smsru_api_id
3
3
 
4
4
  def smsru_api_id
5
- config = Smster.configuration
6
-
7
5
  @smsru_api_id = config.smsru_api_id
8
6
  end
9
7
 
@@ -18,4 +18,8 @@ class SmsLayer < Sms
18
18
  response = send_request
19
19
  assign_attrs_by(response)
20
20
  end
21
+
22
+ def config
23
+ Smster.configuration
24
+ end
21
25
  end
data/lib/smster.rb CHANGED
@@ -5,6 +5,7 @@ require 'smster/sms_layer'
5
5
  require 'smster/sms/smsru'
6
6
  require 'smster/sms/nexmo'
7
7
  require 'smster/sms/clickatell'
8
+ require 'smster/sms/sms_uslugi'
8
9
 
9
10
  module Smster
10
11
  attr_accessor :configuration
@@ -0,0 +1,35 @@
1
+ require './test/test_helper'
2
+
3
+ class SmsUslugiTest < Minitest::Test
4
+ def test_should_send
5
+ sms = Sms::SmsUslugi.send_sms(to: @to, text: @text)
6
+
7
+ assert_equal @statuses[:sent], sms.status
8
+ end
9
+
10
+ def test_should_assign_cost
11
+ sms = Sms::SmsUslugi.send_sms(to: @to, text: @text)
12
+
13
+ assert_equal true, sms.cost.to_f > 0
14
+ end
15
+
16
+ private
17
+
18
+ def stub_send_request
19
+ body = generate_send_request_body
20
+
21
+ stub_request(:post, 'https://lcab.sms-uslugi.ru/lcabApi/sendSms.php')
22
+ .to_return(status: 200, body: body, headers: {})
23
+ end
24
+
25
+ def generate_send_request_body
26
+ {
27
+ code: 1,
28
+ descr: 'Success',
29
+ smsid: '966a995b775db12f701b75e4b11c10d5',
30
+ colsmsOfSending: 1,
31
+ priceOfSending: '0.67',
32
+ colAbonentSend: 1
33
+ }.to_json
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smster_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - doniv
@@ -23,10 +23,12 @@ files:
23
23
  - lib/smster/sms.rb
24
24
  - lib/smster/sms/clickatell.rb
25
25
  - lib/smster/sms/nexmo.rb
26
+ - lib/smster/sms/sms_uslugi.rb
26
27
  - lib/smster/sms/smsru.rb
27
28
  - lib/smster/sms_layer.rb
28
29
  - test/clickatell_test.rb
29
30
  - test/nexmo_test.rb
31
+ - test/sms_uslugi_test.rb
30
32
  - test/smsru_test.rb
31
33
  - test/test_helper.rb
32
34
  homepage: https://github.com/IlyaDonskikh/smster_ruby
@@ -56,5 +58,6 @@ summary: SMS service
56
58
  test_files:
57
59
  - test/clickatell_test.rb
58
60
  - test/nexmo_test.rb
61
+ - test/sms_uslugi_test.rb
59
62
  - test/smsru_test.rb
60
63
  - test/test_helper.rb