sms_center 0.0.10 → 0.0.11

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29b1fc9ac93ae5bf364dc8e7147236c730cc3289135cd48b7bbe61304dbb6752
4
- data.tar.gz: 9163f5f318f9d9898720fb103f5ad6836290f8ce4661c67e40f8da9842196c5f
3
+ metadata.gz: fb43bb2ad685588a16addd09b0a34bfd6b4245bfc64ae2ad3d328132e95b0415
4
+ data.tar.gz: 376fd549f16e8a71de281868efe54d136c1d2c4c2f00784673c8390a4defb00b
5
5
  SHA512:
6
- metadata.gz: 4995fe0c43be0df124dc5f0c903f2b8ecad5f0e28be93a801b83dabd2a63077e2060a809bd2929a44d24098c74f345f6c8e2ae52da7f1c79faae82d5d8b58e2a
7
- data.tar.gz: ddd3541214964d036d65e2ce335cecddf6ba8d8ff16f5ac4e9802bc4b95641b31cddd182d6473a2b35f5dd693e7a4bb23cc008e8d4842a8ae729076894349516
6
+ metadata.gz: d2891fab8d4039f998d27bcc2894c3b0fb4742cbd79ab994d3246078cdad19318c0b7d33acda0aa2e5625f44d20fe3cd6520058592d49f86357415acc5cd36f5
7
+ data.tar.gz: a5954cae36a37a388695c88baad154bf90eb992288f46c043c80b1a7ddc6df46b5726d0349cc749ca72d03ba27537e2bff28361fad6bf482086626870ba8a093
data/lib/sms_center.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  class SmsCenter
2
- autoload :Infobip, 'sms_center/infobip'
3
- autoload :Nexmo, 'sms_center/nexmo'
4
- autoload :Twilio, 'sms_center/twilio'
5
- autoload :Telerivet, 'sms_center/telerivet'
2
+ autoload :Infobip, 'sms_center/infobip'
3
+ autoload :Nexmo, 'sms_center/nexmo'
4
+ autoload :Twilio, 'sms_center/twilio'
5
+ autoload :Telerivet, 'sms_center/telerivet'
6
+ autoload :Plivo, 'sms_center/plivo'
6
7
 
7
8
  @@platforms = nil
8
9
  @@platform_by_country = nil
@@ -37,12 +38,10 @@ class SmsCenter
37
38
  end
38
39
 
39
40
  def initialize(content, to_number, options = {})
40
- platform_by_country = SmsCenter.platform_by_country
41
41
  country = options[:country]
42
42
  platform = options[:platform]
43
43
 
44
- f_platform = country.present? ? platform_by_country[country.downcase.to_sym] : platform_by_country[:default]
45
- f_platform = platform.downcase.capitalize if platform.present?
44
+ f_platform = platform.present? ? platform.downcase.capitalize : platform_by_country(country, to_number)
46
45
 
47
46
  from_number = SmsCenter.root_number_by_platform[f_platform.to_sym]
48
47
  @request = SmsCenter.const_get(f_platform, false).new(content, to_number, from_number, @@keys)
@@ -51,4 +50,22 @@ class SmsCenter
51
50
  def send
52
51
  HTTPClient.new.post_async(@request.api_url, @request.body, @request.headers)
53
52
  end
53
+
54
+ def send_and_wait
55
+ HTTPClient.new.post(@request.api_url, @request.body, @request.headers)
56
+ end
57
+
58
+ private
59
+ def platform_by_country(country, to_number)
60
+ platform_by_country = SmsCenter.platform_by_country
61
+ platform = platform_by_country[country.downcase.to_sym]
62
+ if platform.is_a?(Hash)
63
+ phone = Phonelib.parse(to_number, country.downcase.to_sym)
64
+ platform_by_carrier = platform[phone.carrier.to_sym]
65
+ platform = platform_by_carrier.present? ? platform_by_carrier : platform[:default]
66
+ elsif platform.nil?
67
+ platform = platform_by_country[:default]
68
+ end
69
+ platform.downcase.capitalize
70
+ end
54
71
  end
@@ -0,0 +1,15 @@
1
+ class SmsCenter::Plivo
2
+ attr_reader :api_url, :body, :headers
3
+ def initialize(content, to_number, from_number, keys)
4
+ base64key = Base64.strict_encode64("#{keys[:PLIVO_ACCOUNT_SID]}:#{keys[:PLIVO_AUTH_TOKEN]}")
5
+ @api_url = "https://api.plivo.com/v1/Account/#{keys[:PLIVO_ACCOUNT_SID]}/Message/"
6
+ @headers = {
7
+ 'Authorization' => "Basic #{base64key}"
8
+ }
9
+ @body = {
10
+ src: from_number,
11
+ dst: to_number,
12
+ text: content
13
+ }
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_center
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
  - Deleveree
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: phonelib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: A simple tool to using SMS third party
28
42
  email:
29
43
  executables: []
@@ -33,6 +47,7 @@ files:
33
47
  - lib/sms_center.rb
34
48
  - lib/sms_center/infobip.rb
35
49
  - lib/sms_center/nexmo.rb
50
+ - lib/sms_center/plivo.rb
36
51
  - lib/sms_center/telerivet.rb
37
52
  - lib/sms_center/twilio.rb
38
53
  homepage: https://github.com/deliveree/sms_center
@@ -53,7 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
68
  - !ruby/object:Gem::Version
54
69
  version: '0'
55
70
  requirements: []
56
- rubygems_version: 3.0.8
71
+ rubyforge_project:
72
+ rubygems_version: 2.7.6
57
73
  signing_key:
58
74
  specification_version: 4
59
75
  summary: Deliveree!