Sha256: 7d516167447bcb41dfc10df703ab424a632c29e2e1be4a3b497d0a8a3bcd4845
Contents?: true
Size: 926 Bytes
Versions: 7
Compression:
Stored size: 926 Bytes
Contents
module FwtPushNotificationServer module Notifier class GCM < Notifier::Base def notify_once(message, device_tokens, payload = nil) @device_tokens = device_tokens.is_a?(Array) ? device_tokens : [device_tokens] @gcm = ::GCM.new(FwtPushNotificationServer.gcm_api_key) @registration_ids = [] @payload = { :data => { :message => message } } @device_tokens.each do |device| @registration_ids << device.token if @registration_ids.count == 1000 send_batch end end send_batch end private def send_batch response = @gcm.send_notification(@registration_ids, @payload) body = JSON.parse(response.fetch(:body, "{}")) results = body.fetch("results", []) results.each_with_index do |result, idx| if result["error"] @device_tokens[idx].update_attribute('is_valid', false) end end @registration_ids = [] end end end end
Version data entries
7 entries across 7 versions & 1 rubygems