Class: RubyPushNotifications::GCM::GCMResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-push-notifications/gcm/gcm_response.rb

Overview

This class encapsulates a response received from the GCM service and helps parsing and understanding the received meesages/codes.

Author:

  • Carlos Alonso

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, body) ⇒ GCMResponse

Initializes the GCMResponse and runs response parsing

Raises:

  • MalformedGCMJsonError if code == 400 Bad Request

  • GCMAuthError if code == 401 Unauthorized

  • GCMInternalError if code == 5xx

  • UnexpectedGCMResponseError if code != 200


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby-push-notifications/gcm/gcm_response.rb', line 33

def initialize(code, body)
  case code
  when 200
    parse_response body
  when 400
    raise MalformedGCMJSONError, body
  when 401
    raise GCMAuthError, body
  when 500..599
    raise GCMInternalError, body
  else
    raise UnexpectedGCMResponseError, code
  end
end

Instance Attribute Details

#canonical_idsInteger (readonly)


19
20
21
# File 'lib/ruby-push-notifications/gcm/gcm_response.rb', line 19

def canonical_ids
  @canonical_ids
end

#failedInteger (readonly)


15
16
17
# File 'lib/ruby-push-notifications/gcm/gcm_response.rb', line 15

def failed
  @failed
end

#resultsArray (readonly)


23
24
25
# File 'lib/ruby-push-notifications/gcm/gcm_response.rb', line 23

def results
  @results
end

#successInteger (readonly)


12
13
14
# File 'lib/ruby-push-notifications/gcm/gcm_response.rb', line 12

def success
  @success
end

Instance Method Details

#==(other) ⇒ Object


48
49
50
51
52
53
54
# File 'lib/ruby-push-notifications/gcm/gcm_response.rb', line 48

def ==(other)
  (other.is_a?(GCMResponse) &&
    success == other.success &&
    failed == other.failed &&
    canonical_ids == other.canonical_ids &&
    results == other.results) || super(other)
end