Class: Pntfr::Session::GcmResponse
- Inherits:
-
BaseResponse
- Object
- BaseResponse
- Pntfr::Session::GcmResponse
- Defined in:
- lib/pntfr/session/gcm_response.rb
Instance Method Summary collapse
- #bad_sender_account? ⇒ Boolean
- #error ⇒ Object
- #error? ⇒ Boolean
- #failure ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(json) ⇒ GcmResponse
constructor
A new instance of GcmResponse.
- #msg_sent? ⇒ Boolean
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(json) ⇒ GcmResponse
Returns a new instance of GcmResponse.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pntfr/session/gcm_response.rb', line 10 def initialize json @raw= json @status_code= @raw[:status_code] @response= @raw[:response] @body= @raw[:body] if success? @parsed_body= JSON.parse(@body) @body_result= @parsed_body['results'].first end end |
Instance Method Details
#bad_sender_account? ⇒ Boolean
23 24 25 |
# File 'lib/pntfr/session/gcm_response.rb', line 23 def bad_sender_account? @status_code == 401 end |
#error ⇒ Object
35 36 37 38 39 |
# File 'lib/pntfr/session/gcm_response.rb', line 35 def error if error? @body_result['error'] end end |
#error? ⇒ Boolean
32 33 34 |
# File 'lib/pntfr/session/gcm_response.rb', line 32 def error? success? and !msg_sent? and @body_result.has_key?('error') end |
#failure ⇒ Object
40 41 42 |
# File 'lib/pntfr/session/gcm_response.rb', line 40 def failure "#{@body}->#{@response}" end |
#failure? ⇒ Boolean
26 27 28 |
# File 'lib/pntfr/session/gcm_response.rb', line 26 def failure? @status_code == 400 or @status_code >= 500 end |
#msg_sent? ⇒ Boolean
29 30 31 |
# File 'lib/pntfr/session/gcm_response.rb', line 29 def msg_sent? success? && @parsed_body['success'] == 1 end |
#success? ⇒ Boolean
20 21 22 |
# File 'lib/pntfr/session/gcm_response.rb', line 20 def success? @status_code == 200 end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/pntfr/session/gcm_response.rb', line 43 def to_s @raw.to_s end |