Class: GCM::Response
- Inherits:
-
Object
- Object
- GCM::Response
- Defined in:
- lib/mercurius/gcm/response.rb
Instance Attribute Summary collapse
-
#http_response ⇒ Object
readonly
Returns the value of attribute http_response.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
- #error ⇒ Object
- #fail? ⇒ Boolean
-
#initialize(http_response, tokens = []) ⇒ Response
constructor
A new instance of Response.
- #results ⇒ Object
- #retry_after ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(http_response, tokens = []) ⇒ Response
5 6 7 8 |
# File 'lib/mercurius/gcm/response.rb', line 5 def initialize(http_response, tokens = []) @http_response = http_response @tokens = tokens end |
Instance Attribute Details
#http_response ⇒ Object (readonly)
Returns the value of attribute http_response.
3 4 5 |
# File 'lib/mercurius/gcm/response.rb', line 3 def http_response @http_response end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
3 4 5 |
# File 'lib/mercurius/gcm/response.rb', line 3 def tokens @tokens end |
Instance Method Details
#error ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mercurius/gcm/response.rb', line 32 def error case status when 401 'Authentication error with GCM. Check the server whitelist and the validity of your project key.' when 400 'Invalid JSON was sent to GCM.' when 500..599 'GCM Internal server error.' else nil end end |
#fail? ⇒ Boolean
18 19 20 |
# File 'lib/mercurius/gcm/response.rb', line 18 def fail? !success? end |
#results ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/mercurius/gcm/response.rb', line 22 def results @_results ||= begin results = to_h.fetch 'results', [] results.map!.with_index do |attributes, i| GCM::Result.new attributes, tokens[i] end ResultCollection.new(results) end end |
#retry_after ⇒ Object
45 46 47 |
# File 'lib/mercurius/gcm/response.rb', line 45 def retry_after http_response.headers['Retry-After'] end |
#status ⇒ Object
10 11 12 |
# File 'lib/mercurius/gcm/response.rb', line 10 def status http_response.status end |
#success? ⇒ Boolean
14 15 16 |
# File 'lib/mercurius/gcm/response.rb', line 14 def success? http_response.success? end |
#to_h ⇒ Object
49 50 51 52 53 |
# File 'lib/mercurius/gcm/response.rb', line 49 def to_h JSON.parse http_response.body rescue JSON::ParserError {} end |