Class: Firebase::Admin::Messaging::TopicManagementResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase/admin/messaging/topic_management_response.rb

Overview

A response received from a topic management operation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ TopicManagementResponse

Parameters:

  • response (Faraday::Response)

    The response received from the api.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/firebase/admin/messaging/topic_management_response.rb', line 19

def initialize(response)
  unless response.body.is_a?(Hash) && response.body["results"].is_a?(Array)
    raise Error.new("Unexpected topic management response", response)
  end

  @success_count = 0
  @failure_count = 0
  @errors = []

  results = response.body["results"]
  results.each_with_index do |result, i|
    if (reason = result["error"])
      @failure_count += 1
      @errors << ErrorInfo.new(index: i, reason: reason)
    else
      @success_count += 1
    end
  end
end

Instance Attribute Details

#errorsArray<ErrorInfo> (readonly)

Returns An array of ErrorInfo objects (possibly empty).

Returns:



13
14
15
# File 'lib/firebase/admin/messaging/topic_management_response.rb', line 13

def errors
  @errors
end

#failure_countInteger (readonly)

Returns The number of tokens that could not be subscribed or unsubscribed due to errors.

Returns:

  • (Integer)

    The number of tokens that could not be subscribed or unsubscribed due to errors.



10
11
12
# File 'lib/firebase/admin/messaging/topic_management_response.rb', line 10

def failure_count
  @failure_count
end

#success_countInteger (readonly)

Returns The number of tokens successfully subscribed or unsubscribed.

Returns:

  • (Integer)

    The number of tokens successfully subscribed or unsubscribed.



7
8
9
# File 'lib/firebase/admin/messaging/topic_management_response.rb', line 7

def success_count
  @success_count
end