From 1343f95d0e25c9d290884f99fb890ad2e4b6dd2b Mon Sep 17 00:00:00 2001 From: alediaz84 Date: Wed, 2 Nov 2016 13:57:11 -0300 Subject: [PATCH] Return invalid registration ids --- lib/gcm.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/gcm.rb b/lib/gcm.rb index f7be05c..8b5f623 100644 --- a/lib/gcm.rb +++ b/lib/gcm.rb @@ -133,6 +133,7 @@ def build_response(response, registration_ids = []) body = JSON.parse(body) unless body.empty? response_hash[:canonical_ids] = build_canonical_ids(body, registration_ids) unless registration_ids.empty? response_hash[:not_registered_ids] = build_not_registered_ids(body, registration_ids) unless registration_ids.empty? + response_hash[:invalid_registration_ids] = build_invalid_registration_ids(body, registration_ids) unless registration_ids.empty? when 400 response_hash[:response] = 'Only applies for JSON requests. Indicates that the request could not be parsed as JSON, or it contained invalid fields.' when 401 @@ -169,6 +170,18 @@ def build_not_registered_ids(body, registration_id) not_registered_ids end + def build_invalid_registration_ids(body, registration_id) + invalid_registration_ids = [] + unless body.empty? + if body['failure'] > 0 + body['results'].each_with_index do |result, index| + invalid_registration_ids << registration_id[index] if is_invalid_registration?(result) + end + end + end + invalid_registration_ids + end + def has_canonical_id?(result) !result['registration_id'].nil? end @@ -176,4 +189,8 @@ def has_canonical_id?(result) def is_not_registered?(result) result['error'] == 'NotRegistered' end + + def is_invalid_registration?(result) + result['error'] == 'InvalidRegistration' + end end