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

Parameters:

  • code (Integer)

    . The HTTP status code received

  • body (String)

    . The response body received.

Raises:

  • MalformedGCMJsonError if code == 400 Bad Request

  • GCMAuthError if code == 401 Unauthorized

  • GCMInternalError if code == 5xx

  • UnexpectedGCMResponseError if code != 200



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

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)

Returns the number of received canonical IDS (developer.android.com/google/gcm/server-ref.html#table4).

Returns:



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

def canonical_ids
  @canonical_ids
end

#failedInteger (readonly)

Returns the number of failed notifications.

Returns:

  • (Integer)

    the number of failed notifications



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

def failed
  @failed
end

#resultsArray (readonly) Also known as: individual_results

Returns Array of a GCMResult for every receiver of the notification sent indicating the result of the operation.

Returns:

  • (Array)

    Array of a GCMResult for every receiver of the notification sent indicating the result of the operation.



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

def results
  @results
end

#successInteger (readonly)

Returns the number of successfully sent notifications.

Returns:

  • (Integer)

    the number of successfully sent notifications



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

def success
  @success
end

Instance Method Details

#==(other) ⇒ Object



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

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