Class: RubyPushNotifications::FCM::FCMResponse

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

Overview

This class encapsulates a response received from the FCM 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) ⇒ FCMResponse

Initializes the FCMResponse and runs response parsing

Parameters:

  • code (Integer)

    . The HTTP status code received

  • body (String)

    . The response body received.

Raises:

  • MalformedFCMJsonError if code == 400 Bad Request

  • FCMAuthError if code == 401 Unauthorized

  • FCMInternalError if code == 5xx

  • UnexpectedFCMResponseError if code != 200



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

def initialize(code, body)
  case code
  when 200
    parse_response body
  when 400
    raise MalformedFCMJSONError, body
  when 401
    raise FCMAuthError, body
  when 500..599
    raise FCMInternalError, body
  else
    raise UnexpectedFCMResponseError, code
  end
end

Instance Attribute Details

#canonical_idsInteger (readonly)

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

Returns:



20
21
22
# File 'lib/ruby-push-notifications/fcm/fcm_response.rb', line 20

def canonical_ids
  @canonical_ids
end

#failedInteger (readonly)

Returns the number of failed notifications.

Returns:

  • (Integer)

    the number of failed notifications



16
17
18
# File 'lib/ruby-push-notifications/fcm/fcm_response.rb', line 16

def failed
  @failed
end

#resultsArray (readonly) Also known as: individual_results

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

Returns:

  • (Array)

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



24
25
26
# File 'lib/ruby-push-notifications/fcm/fcm_response.rb', line 24

def results
  @results
end

#successInteger (readonly)

Returns the number of successfully sent notifications.

Returns:

  • (Integer)

    the number of successfully sent notifications



13
14
15
# File 'lib/ruby-push-notifications/fcm/fcm_response.rb', line 13

def success
  @success
end

Instance Method Details

#==(other) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/ruby-push-notifications/fcm/fcm_response.rb', line 50

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