class ADM::Notification

Attributes

message[R]
registration_id[R]

Public Class Methods

new(registration_id, message) click to toggle source
# File lib/adm/notification.rb, line 4
def initialize registration_id, message
  if message.is_a?(ADM::Message)
    @message = message
  else
    @message = ADM::Message.new(message)
  end

  @registration_id = registration_id
end

Public Instance Methods

error() click to toggle source
# File lib/adm/notification.rb, line 49
def error
  if !success?
    reesponse_json['reason']
  end
end
queue(hydra) click to toggle source
# File lib/adm/notification.rb, line 55
def queue hydra
  hydra.queue(self.request)
end
reesponse_json() click to toggle source
# File lib/adm/notification.rb, line 45
def reesponse_json
  MultiJson.load(response.body) if response.headers['Content-type'] == 'application/json'
end
request() click to toggle source
# File lib/adm/notification.rb, line 18
def request
  @request ||= Typhoeus::Request.new(
    "https://api.amazon.com/messaging/registrations/#{registration_id}/messages",
    method: :post,
    body: message.compile,
    headers: {
      :Accept                 => :'application/json',
      :'Content-Type'         => :'application/json',
      :'X-Amzn-Type-Version'  => :'com.amazon.device.messaging.ADMMessage@1.0',
      :'X-Amzn-Accept-Type'   => :'com.amazon.device.messaging.ADMSendResult@1.0',
      :Authorization          => "Bearer #{token}"
    }
  )
end
response() click to toggle source
# File lib/adm/notification.rb, line 41
def response
  request.response
end
send() click to toggle source
# File lib/adm/notification.rb, line 33
def send
  request.run
end
success?() click to toggle source
# File lib/adm/notification.rb, line 37
def success?
  response.success?
end
token() click to toggle source
# File lib/adm/notification.rb, line 14
def token
  ADM::AccessToken.get_token
end