deliveree_sms 0.0.2 → 0.0.3

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
  SHA256:
3
- metadata.gz: 2397f4b6c435eed27aa995394c98aa468286b53582b28f959403b141079bee12
4
- data.tar.gz: e552cd9a492309a86bfa32fabe0f65e625317d77aeb36a091156e5f5f18267c7
3
+ metadata.gz: 40f6a1f32971c6c44ba097c474790b0af1f14fe8a6db4a5c7e6c8c04e6c72a7b
4
+ data.tar.gz: 340b9d45d7861861e446136a297cf7dc1696e6249610224a3fbd777e4d86a449
5
5
  SHA512:
6
- metadata.gz: 844b6070ac13ecb31ab498526c9fba681536c7dac076b1eea5504131211e57cef6f51a3e2877c49b98304af936e1d7a9992a694e24088b5152aa573af09c9c01
7
- data.tar.gz: d0b09ff88b54ba2711efdbe97182a0a96ca900c0eb93f0ee1010fa41574c46b41cb85f35278a73d77688c6aca09d548b33b9ca0ef18ff9a025a869d4637dcd93
6
+ metadata.gz: fd7316bf299e259d775ab907b83c2a06628121afa6681f7973c9aaecec739bb3dc976b45f801dced3955cceb95dfd0d868b6437d90727961125ba61100fd94a3
7
+ data.tar.gz: a15231868f72d3536b3f41744938e1cbef9fcc4e560f1f33315687582257261ea5c872ce757c8030812d9f8b5248cb7fdb0a03ba66a1362b37d9440343774f32
data/lib/deliveree_sms.rb CHANGED
@@ -1,7 +1,49 @@
1
- module DelivereeSms
2
- class Sms
3
- def hi
4
- puts 'Hello again'
5
- end
1
+ class DelivereeSms
2
+ autoload :Infobip, 'deliveree_sms/infobip'
3
+ autoload :Nexmo, 'deliveree_sms/nexmo'
4
+ autoload :Twilio, 'deliveree_sms/twilio'
5
+ autoload :Telerivet, 'deliveree_sms/telerivet'
6
+
7
+ @@platforms = nil
8
+ @@platform_by_country = nil
9
+ @@keys = nil
10
+
11
+ def self.configure
12
+ yield self
13
+ end
14
+
15
+ def self.platform_by_country=(platform_by_country)
16
+ @@platform_by_country = platform_by_country
17
+ end
18
+
19
+ def self.root_number_by_platform=(root_number_by_platform)
20
+ @@root_number_by_platform = root_number_by_platform
21
+ end
22
+
23
+ def self.keys=(keys)
24
+ @@keys = keys
25
+ end
26
+
27
+ def self.platform_by_country
28
+ @@platform_by_country
29
+ end
30
+
31
+ def self.keys
32
+ @@keys
33
+ end
34
+
35
+ def self.root_number_by_platform
36
+ @@root_number_by_platform
37
+ end
38
+
39
+ def initialize(content, to_number, country)
40
+ platform_by_country = DelivereeSms.platform_by_country
41
+ platform = platform_by_country[country.downcase.to_sym] || platform_by_country[:default]
42
+ from_number = DelivereeSms.root_number_by_platform[platform.to_sym]
43
+ @adapter = DelivereeSms.const_get(platform, false).new(content, to_number, from_number, @@keys)
44
+ end
45
+
46
+ def send
47
+ RestClient.post(@adapter.api_url, @adapter.body, @adapter.headers)
6
48
  end
7
49
  end
@@ -0,0 +1,16 @@
1
+ class DelivereeSms::Infobip
2
+ attr_reader :api_url, :body, :headers
3
+ def initialize(content, to_number, from_number, keys)
4
+ api_key = keys[:INFOBIP_API_KEY]
5
+ @api_url = 'https://5mzkg.api.infobip.com/sms/2/text/single'
6
+ @headers = {
7
+ 'Authorization' => "App #{api_key}",
8
+ 'Content-Type' => 'application/json'
9
+ }
10
+ @body = {
11
+ "to": to_number,
12
+ "text": content,
13
+ }
14
+ @body["from_number"] = from_number if from_number
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ class DelivereeSms::Nexmo
2
+ attr_reader :api_url, :body, :headers
3
+ def initialize(content, to_number, from_number, keys)
4
+ base64key = Base64.strict_encode64("#{keys[:NEXMO_API_KEY]}:#{keys[:NEXMO_API_SECRET]}")
5
+ @api_url = 'https://rest.nexmo.com/sms/json'
6
+ @headers = {
7
+ 'Content-Type' => 'application/json'
8
+ }
9
+ @body = {
10
+ api_key: keys[:NEXMO_API_KEY],
11
+ api_secret: keys[:NEXMO_API_SECRET],
12
+ to: to_number,
13
+ text: content,
14
+ from: from_number
15
+ }
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ class DelivereeSms::Telerivet
2
+ attr_reader :api_url, :body, :headers
3
+ def initialize(content, to_number, from_number, keys)
4
+ base64key = Base64.strict_encode64("#{keys[:TELERIVET_API_KEY]}:")
5
+ @api_url = "https://api.telerivet.com/v1/projects/#{keys[:TELERIVET_PROJECT_ID]}/messages/send"
6
+ @headers = {
7
+ 'Authorization' => "Basic #{base64key}",
8
+ 'Content-Type' => 'application/json'
9
+ }
10
+ @body = {
11
+ "content": content,
12
+ "to_number": to_number
13
+ }
14
+ @body["from_number"] = from_number if from_number
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ class DelivereeSms::Twilio
2
+ attr_reader :api_url, :body, :headers
3
+ def initialize(content, to_number, from_number, keys)
4
+ base64key = Base64.strict_encode64("#{keys[:TWILIO_ACCOUNT_SID]}:#{keys[:TWILIO_AUTH_TOKEN]}")
5
+ @api_url = "https://api.twilio.com/2010-04-01/Accounts/#{keys[:TWILIO_ACCOUNT_SID]}/Messages.json?"
6
+ @headers = {
7
+ 'Authorization' => "Basic #{base64key}",
8
+ 'Content-Type' => 'application/x-www-form-urlencoded'
9
+ }
10
+ @body = {
11
+ From: from_number,
12
+ To: to_number,
13
+ Body: content
14
+ }
15
+ binding.pry
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deliveree_sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deleveree
@@ -17,6 +17,10 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/deliveree_sms.rb
20
+ - lib/deliveree_sms/infobip.rb
21
+ - lib/deliveree_sms/nexmo.rb
22
+ - lib/deliveree_sms/telerivet.rb
23
+ - lib/deliveree_sms/twilio.rb
20
24
  homepage: https://rubygems.org/gems/deliveree_sms
21
25
  licenses: []
22
26
  metadata: {}
@@ -35,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
35
39
  - !ruby/object:Gem::Version
36
40
  version: '0'
37
41
  requirements: []
38
- rubyforge_project:
39
- rubygems_version: 2.7.8
42
+ rubygems_version: 3.0.6
40
43
  signing_key:
41
44
  specification_version: 4
42
45
  summary: Deliveree!