Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- colleges.rb
- def send_notif
- validate_field_tag(params[:alert], colleges_path)
- edit_notification('college')
- push_notifications('college')
- end
- application.rb
- def push_notifications(section)
- apple_devices = APN::Device.all
- notif_message = ApnNotificationMessage.find_by_section(section)
- apple_devices.each do |dev|
- notification = APN::Notification.create(:badge => 0, :sound => true, :alert => notif_message.body, :custom_properties => {"section" => notif_message.section}, :device_id => dev.id)
- notification.device = dev
- APN::Notification.send_notifications
- notification.destroy
- end
- android_devices = C2dmDevice.all
- #logger.info android_devices.inspect
- notif = C2dmNotification.find_by_section(section)
- #logger.info notif.inspect
- android_devices.each do |device|
- speedyC2DM = SpeedyC2DM::API.new(C2DM_EMAIL, C2DM_PASSWORD)
- options = {
- :registration_id => device.dev_identifier,
- :message => notif.message,
- :section => notif.section,
- :extra_data => 42,
- :collapse_key => "collapse-key"
- }
- responce = speedyC2DM.send_notification(options)
- logger.info responce.inspect # <----------------------------------
- end
- end
- speedy_c2dm_ex.rb
- module SpeedyC2DM
- class API
- def requestObject(options)
- payload = {}
- payload[:registration_id] = options.delete(:registration_id)
- payload[:collapse_key] = options.delete(:collapse_key)
- options.each {|key, value| payload["data.#{key}"] = value}
- Rails::logger.info("HELLO")
- Typhoeus::Request.new(PUSH_URL, {
- :disable_ssl_peer_verification => true, # <----------------------------------
- :method => :post,
- :params => payload,
- :headers => {
- 'Authorization' => "GoogleLogin auth=#{@auth_token}"
- }
- })
- end
- end
- end
Add Comment
Please, Sign In to add comment