orange_push_sms 0.0.1 → 1.0.0

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
  SHA1:
3
- metadata.gz: f69a3e1e7c1117911542f46a7fbf3363d115a185
4
- data.tar.gz: 4b87844d5c4a3ad74d1717956a1c8036fde51a9f
3
+ metadata.gz: 2e23e086a46a98a23227b0ff26fba3a11a252b9e
4
+ data.tar.gz: bdab4d718b9a142cd8e641c7cd210eb97957bede
5
5
  SHA512:
6
- metadata.gz: d50cef004a27be03c919b90ea3f160dd214da4661a3d37c782fb056767e1ed3538aeeeeb352f5f5fd7c9ebf726f6fabe35f01807a56092c9658c1f2d72b26f46
7
- data.tar.gz: d1a8ca2167f810ec6e07f8d559d50d3e09ddddcb8365437d2045af9de8d8daff45471d9a818220a74ed79f283632315c2cc1d45bcf067d904dd5b6579c7ab1bb
6
+ metadata.gz: 4c12acac855ac70c577eb0e5d382f49f787f939fae596257efafa969a99a07e2618651b0e6a02a00c32a980ec7435ff1915cb766e9a5ea40f2f4a6c289b63b0c
7
+ data.tar.gz: a3cc2f55caa9ecf6c1d66845b299609125bcf75227d1f4e8fc39d5835987b2a9af2c1b647daa341e2170c71b8c02687fbbcec2d1f5dd218d553b3749dccc9778
data/README.md CHANGED
@@ -18,21 +18,26 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install orange_push_sms
20
20
 
21
- ## Usage
21
+ ## Configuration
22
22
 
23
- To send an SMS to single recipient use:
23
+ In config/initializers create a file orange_push_sms.rb:
24
24
 
25
25
  ```ruby
26
- message = OrangePushSMS::Message.new msisdn: '22177XXXXXXX', wording: 'Your message here', tpoa: 'SENDER', is_xml: true
27
- message.send #returns true if successful
26
+ OrangePushSMS.configure do |config|
27
+ config.user = 'LOGIN'
28
+ config.token = 'TOKEN'
29
+ config.secret = 'API KEY'
30
+ end
28
31
  ```
29
- To multiple recipients
32
+
33
+ ## Usage
34
+
35
+ To send an SMS :
30
36
 
31
37
  ```ruby
32
- message = OrangePushSMS::Message.new numbers: ['22177XXXXXXX', '22177YYYYYYY', '22176ZZZZZZZ'], wording: "Sending to multiple recipients", tpoa: 'SENDER'
33
- message.send
38
+ message = OrangePushSMS::Message.new recipients: ['22177XXXXXXX'], content: 'Your message here', signature: 'SENDER', subject: 'Subject'
39
+ message.send #returns true if successful
34
40
  ```
35
-
36
41
  ## Contributing
37
42
 
38
43
  1. Fork it ( https://github.com/divinwind/orange_push_sms/fork )
@@ -1,12 +1,12 @@
1
1
  module OrangePushSMS
2
2
  class Configuration
3
3
 
4
- attr_accessor :login
5
- attr_accessor :pass
4
+ attr_accessor :user, :token, :secret
6
5
 
7
6
  def initialize
8
- @login = ''
9
- @pass = ''
7
+ @user = ''
8
+ @token = ''
9
+ @secret = ''
10
10
  end
11
11
  end
12
12
  end
@@ -4,69 +4,53 @@ require 'http'
4
4
  module OrangePushSMS
5
5
  class Message
6
6
 
7
- BASE_URL = 'https://gsm.orange.sn/push_flux/http.php'
8
- BASE_URL_XML = 'http://213.154.64.47/push_flux/xml.php'
7
+ BASE_URL = 'https://api.orangesmspro.sn:8443/api/xml'
9
8
 
10
9
  def initialize(options = {})
11
- @msisdn = options.fetch(:msisdn, '221770000000')
12
- @wording = options.fetch(:wording, '')
13
- @tpoa = options.fetch(:tpoa, 'Aphia')
14
- @numbers = options.fetch(:numbers, [])
15
- @is_xml = options.has_key?(:is_xml) and options.delete(:is_xml)
16
- @campaign = 'TESTPUSH'
10
+ @recipients = options.fetch(:recipients, [])
11
+ @content = options.fetch(:content, '')
12
+ @signature = options.fetch(:signature, 'Aphia')
13
+ @subject = options.fetch(:subject, '')
17
14
  end
18
15
 
19
- def send
20
- if @is_xml or @numbers.size > 0
21
- xml = Nokogiri::XML HTTP.post( BASE_URL_XML, form: {xml: to_xml}).to_s
22
- xml.xpath("//STATUS_CODE").first.text == "100"
23
- else
24
- !(/Return:1/ =~ HTTP.get(BASE_URL, params: to_h).to_s).nil?
25
- end
16
+ def config
17
+ OrangePushSMS.configuration
18
+ end
19
+
20
+ def timestamp
21
+ @timestamp ||= Time.now.to_i
26
22
  end
27
23
 
28
- def to_h
29
- pass = Digest::MD5.hexdigest(OrangePushSMS.configuration.pass)
30
- {login: OrangePushSMS.configuration.login,
31
- pass: pass,
32
- tpoa: @tpoa,
33
- msisdn: @msisdn,
34
- wording: @wording,
35
- campaign: @campaign}
24
+ def digest
25
+ d = OpenSSL::Digest.new('sha1')
26
+ OpenSSL::HMAC.hexdigest d,
27
+ config.secret,
28
+ "#{config.token}#{to_xml}#{timestamp}"
36
29
  end
37
30
 
38
31
  def to_xml
39
- pass = Digest::MD5.hexdigest(OrangePushSMS.configuration.pass)
40
- builder = Nokogiri::XML::Builder.new do |xml|
41
- xml.SESSION(login: OrangePushSMS.configuration.login, pass: pass) do
42
- xml.CREATE do
43
- xml.CAMPAIGN(type: '3') do
44
- xml.NAME @campaign
45
- xml.START DateTime.now.strftime('%Y-%m-%d-%H-%M')
46
- xml.END DateTime.now.strftime('%Y-%m-%d-%H-%M')
47
- xml.TPOA @tpoa
48
- if @numbers.size > 0
49
- xml.GEN do
50
- xml.WORDING @wording
51
- xml.NUMBERS do
52
- @numbers.each do |number|
53
- xml.NUMBER number
54
- end
55
- end
56
- end
57
- else
58
- xml.PERSO do
59
- xml.MESSAGE do
60
- xml.NUMBER @msisdn
61
- xml.WORDING @wording
62
- end
63
- end
64
- end
32
+ @builder ||= Nokogiri::XML::Builder.new do |xml|
33
+ xml.session do
34
+ xml.type 1
35
+ xml.content @content
36
+ xml.recipients do
37
+ @recipients.each do |recipient|
38
+ xml.recipient recipient
65
39
  end
66
40
  end
41
+ xml.signature @signature
42
+ xml.subject @subject
67
43
  end
68
- end
69
- builder.to_xml
44
+ end.to_xml
45
+ end
46
+
47
+ def send
48
+ uri = "#{BASE_URL}?token=#{config.token}&key=#{digest}&timestamp=#{timestamp}"
49
+ ctx = OpenSSL::SSL::SSLContext.new
50
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
51
+ xml = Nokogiri::XML HTTP.basic_auth(user: config.user, pass: config.token)
52
+ .post(uri, body: to_xml, ssl_context: ctx)
53
+ puts xml
70
54
  end
71
55
  end
72
56
  end
@@ -1,3 +1,3 @@
1
1
  module OrangePushSMS
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orange_push_sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mustafa Sall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-26 00:00:00.000000000 Z
11
+ date: 2016-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.4.6
122
+ rubygems_version: 2.6.2
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Une gem pour envoyer des sms via l'api d'orange sénégal