class OrangePushSMS::Message

Constants

BASE_URL

Public Class Methods

new(options = {}) click to toggle source
# File lib/orange_push_sms/message.rb, line 9
def initialize(options = {})
  @recipients = options.fetch(:recipients, [])
  @content    = options.fetch(:content, '')
  @signature  = options.fetch(:signature, 'Aphia')
  @subject    = options.fetch(:subject, '')
end

Public Instance Methods

config() click to toggle source
# File lib/orange_push_sms/message.rb, line 16
def config
  OrangePushSMS.configuration
end
digest() click to toggle source
# 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}#{timestamp}"
end
send() click to toggle source
# File lib/orange_push_sms/message.rb, line 47
def send
  uri = "#{BASE_URL}?token=#{config.token}&key=#{digest}&timestamp=#{timestamp}"
  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() click to toggle source
# File lib/orange_push_sms/message.rb, line 20
def timestamp
  @timestamp ||= Time.now.to_i
end
to_xml() click to toggle source
# 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