Class: Rpush::Daemon::Gcm::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/rpush/daemon/gcm/delivery.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results_data, registration_ids) ⇒ Results

Returns a new instance of Results


155
156
157
158
# File 'lib/rpush/daemon/gcm/delivery.rb', line 155

def initialize(results_data, registration_ids)
  @results_data = results_data
  @registration_ids = registration_ids
end

Instance Attribute Details

#failuresObject (readonly)

Returns the value of attribute failures


153
154
155
# File 'lib/rpush/daemon/gcm/delivery.rb', line 153

def failures
  @failures
end

#successesObject (readonly)

Returns the value of attribute successes


153
154
155
# File 'lib/rpush/daemon/gcm/delivery.rb', line 153

def successes
  @successes
end

Instance Method Details

#process(failure_partitions = {}) ⇒ Object

rubocop:disable Metrics/AbcSize


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/rpush/daemon/gcm/delivery.rb', line 160

def process(failure_partitions = {}) # rubocop:disable Metrics/AbcSize
  @successes = []
  @failures = Failures.new
  failure_partitions.each_key do |category|
    failures[category] = []
  end

  @results_data.each_with_index do |result, index|
    entry = {
      registration_id: @registration_ids[index],
      index: index
    }
    if result['message_id']
      entry[:canonical_id] = result['registration_id'] if result['registration_id'].present?
      successes << entry
    elsif result['error']
      entry[:error] = result['error']
      failures << entry
      failure_partitions.each do |category, error_states|
        failures[category] << entry if error_states.include?(result['error'])
      end
    end
  end
  failures.all_failed = failures.count == @registration_ids.count
end