Class: ADM::Notification
- Inherits:
-
Object
- Object
- ADM::Notification
- Defined in:
- lib/adm/notification.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#registration_id ⇒ Object
readonly
Returns the value of attribute registration_id.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(registration_id, message) ⇒ Notification
constructor
A new instance of Notification.
- #queue(hydra) ⇒ Object
- #reesponse_json ⇒ Object
- #request ⇒ Object
- #response ⇒ Object
- #send ⇒ Object
- #success? ⇒ Boolean
- #token ⇒ Object
Constructor Details
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
2 3 4 |
# File 'lib/adm/notification.rb', line 2 def @message end |
#registration_id ⇒ Object (readonly)
Returns the value of attribute registration_id.
2 3 4 |
# File 'lib/adm/notification.rb', line 2 def registration_id @registration_id end |
Instance Method Details
#error ⇒ Object
49 50 51 52 53 |
# File 'lib/adm/notification.rb', line 49 def error if !success? reesponse_json['reason'] end end |
#queue(hydra) ⇒ Object
55 56 57 |
# File 'lib/adm/notification.rb', line 55 def queue hydra hydra.queue(self.request) end |
#reesponse_json ⇒ Object
45 46 47 |
# File 'lib/adm/notification.rb', line 45 def reesponse_json MultiJson.load(response.body) if response.headers['Content-type'] == 'application/json' end |
#request ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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: .compile, headers: { :Accept => :'application/json', :'Content-Type' => :'application/json', :'X-Amzn-Type-Version' => :'[email protected]', :'X-Amzn-Accept-Type' => :'[email protected]', :Authorization => "Bearer #{token}" } ) end |
#response ⇒ Object
41 42 43 |
# File 'lib/adm/notification.rb', line 41 def response request.response end |
#send ⇒ Object
33 34 35 |
# File 'lib/adm/notification.rb', line 33 def send request.run end |
#success? ⇒ Boolean
37 38 39 |
# File 'lib/adm/notification.rb', line 37 def success? response.success? end |
#token ⇒ Object
14 15 16 |
# File 'lib/adm/notification.rb', line 14 def token ADM::AccessToken.get_token end |