1

The idea is to have 2 separate calls using the code below with different application id to push to different app. And I wish to do this on ruby on rails.

However, when i insert this code into ruby on rails:

auth_hash = { auth: '55555-5555', application: '1234zxcvb' }
Pushwoosh.PushNotification.new(auth_hash).notify_devices(message, devices, other_options)

This error comes out:

undefined method `PushNotification' for Pushwoosh:Module

btw, I dont to use the initializer example as it only works to push to ONE app. I want to push to TWO different app using pushwoosh.

Axil
  • 3,606
  • 10
  • 62
  • 136

2 Answers2

1

This implementation is working. Need to use 'Pushwoosh::PushNotification.new' instead of 'Pushwoosh.PushNotification.new'

def notify_app1
     auth_hash = { auth: 'your_auth_key', application: 'app-id-2' }
     Pushwoosh::PushNotification.new(auth_hash).notify_all('', {})
end

def notify_app2
     auth_hash = { auth: 'your_auth_key', application: 'app-id-2' }
     Pushwoosh::PushNotification.new(auth_hash).notify_all('', {})
end
Alif Jamaluddin
  • 518
  • 4
  • 17
0

According to gem readme you can only use Pushwoosh.configure in Rails application and not Pushwoosh.PushNotification.new. But you can initialize Pushwoosh each time you want to send push notification. For example:

def configure_pushwoosh(app_id, auth_token)
  Pushwoosh.configure do |config|
    config.application = app_id
    config.auth = auth_token
  end
end

configure_pushwoosh('55555-5555', '1234zxcvb')
Pushwoosh.notify_devices(message, devices, other_options)

configure_pushwoosh('11111-1111', 'asda1231231')
Pushwoosh.notify_devices(message, devices, other_options)
Maxim Pontyushenko
  • 2,983
  • 2
  • 25
  • 36
  • Hello @Maxim Could you please tell me what type of object goes to the devices param? Is it an array of device tokens like: [ '1232341234123', 123412341234 ] ? -Thank you – jlstr Apr 14 '16 at 01:25
  • 1
    @Jose Yes, array of strings. For example: `["edjQ5DF9nWQ:APA91bH3qZ6DqD2OIQNQ5eET7cxdXtEu2CnZluBg4ZZo7hdJZuHdC3xf6pRVA9OhsUme4gqqN32K-dHb7pqFKjAM0j9aqzNGxbSJEl1QtCbAZ94cTxuDDxUhyloDIJ7i6S9A7HJHRsOq"]` – Maxim Pontyushenko Apr 14 '16 at 08:36