Guest User

Untitled

a guest
Jan 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. colleges.rb
  2.  
  3. def send_notif
  4. validate_field_tag(params[:alert], colleges_path)
  5. edit_notification('college')
  6. push_notifications('college')
  7. end
  8.  
  9.  
  10. application.rb
  11.  
  12. def push_notifications(section)
  13. apple_devices = APN::Device.all
  14. notif_message = ApnNotificationMessage.find_by_section(section)
  15.  
  16. apple_devices.each do |dev|
  17. notification = APN::Notification.create(:badge => 0, :sound => true, :alert => notif_message.body, :custom_properties => {"section" => notif_message.section}, :device_id => dev.id)
  18. notification.device = dev
  19. APN::Notification.send_notifications
  20. notification.destroy
  21. end
  22.  
  23. android_devices = C2dmDevice.all
  24. #logger.info android_devices.inspect
  25. notif = C2dmNotification.find_by_section(section)
  26. #logger.info notif.inspect
  27. android_devices.each do |device|
  28. speedyC2DM = SpeedyC2DM::API.new(C2DM_EMAIL, C2DM_PASSWORD)
  29. options = {
  30. :registration_id => device.dev_identifier,
  31. :message => notif.message,
  32. :section => notif.section,
  33. :extra_data => 42,
  34. :collapse_key => "collapse-key"
  35. }
  36. responce = speedyC2DM.send_notification(options)
  37. logger.info responce.inspect # <----------------------------------
  38. end
  39. end
  40.  
  41.  
  42.  
  43. speedy_c2dm_ex.rb
  44.  
  45.  
  46. module SpeedyC2DM
  47. class API
  48.  
  49. def requestObject(options)
  50. payload = {}
  51. payload[:registration_id] = options.delete(:registration_id)
  52. payload[:collapse_key] = options.delete(:collapse_key)
  53. options.each {|key, value| payload["data.#{key}"] = value}
  54. Rails::logger.info("HELLO")
  55.  
  56. Typhoeus::Request.new(PUSH_URL, {
  57. :disable_ssl_peer_verification => true, # <----------------------------------
  58. :method => :post,
  59. :params => payload,
  60. :headers => {
  61. 'Authorization' => "GoogleLogin auth=#{@auth_token}"
  62. }
  63. })
  64. end
  65.  
  66. end
  67.  
  68. end
Add Comment
Please, Sign In to add comment