Class: OrangePushSMS::Message
- Inherits:
-
Object
- Object
- OrangePushSMS::Message
- Defined in:
- lib/orange_push_sms/message.rb
Constant Summary collapse
- BASE_URL =
'https://api.orangesmspro.sn:8443/api/xml'
Instance Method Summary collapse
- #config ⇒ Object
- #digest ⇒ Object
-
#initialize(options = {}) ⇒ Message
constructor
A new instance of Message.
- #send ⇒ Object
- #timestamp ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Message
Returns a new instance of Message.
9 10 11 12 13 14 |
# File 'lib/orange_push_sms/message.rb', line 9 def initialize( = {}) @recipients = .fetch(:recipients, []) @content = .fetch(:content, '') @signature = .fetch(:signature, 'Aphia') @subject = .fetch(:subject, '') end |
Instance Method Details
#config ⇒ Object
16 17 18 |
# File 'lib/orange_push_sms/message.rb', line 16 def config OrangePushSMS.configuration end |
#digest ⇒ Object
24 25 26 27 28 29 |
# File 'lib/orange_push_sms/message.rb', line 24 def digest d = OpenSSL::Digest.new('sha1') OpenSSL::HMAC.hexdigest d, config.secret, "#{config.token}#{to_xml}#{}" end |
#send ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/orange_push_sms/message.rb', line 47 def send uri = "#{BASE_URL}?token=#{config.token}&key=#{digest}×tamp=#{}" ctx = OpenSSL::SSL::SSLContext.new ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE xml = Nokogiri::XML HTTP.basic_auth(user: config.user, pass: config.token) .post(uri, body: to_xml, ssl_context: ctx) puts xml end |
#timestamp ⇒ Object
20 21 22 |
# File 'lib/orange_push_sms/message.rb', line 20 def @timestamp ||= Time.now.to_i end |
#to_xml ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/orange_push_sms/message.rb', line 31 def to_xml @builder ||= Nokogiri::XML::Builder.new do |xml| xml.session do xml.type 1 xml.content @content xml.recipients do @recipients.each do |recipient| xml.recipient recipient end end xml.signature @signature xml.subject @subject end end.to_xml end |