module OneSignal

Constants

API_VERSION
VERSION

Public Class Methods

config() click to toggle source
# File lib/onesignal.rb, line 76
def config
  @config ||= Configuration.new
end
configure() { |config| ... } click to toggle source
# File lib/onesignal.rb, line 12
def configure
  yield config
end
Also aliased as: define
csv_export(params = {}) click to toggle source
# File lib/onesignal.rb, line 69
def csv_export params = {}
  return unless OneSignal.config.active

  fetched = Commands::CsvExport.call params
  Responses::CsvExport.from_json fetched.body
end
define()
Alias for: configure
fetch_notification(notification_id) click to toggle source
# File lib/onesignal.rb, line 23
def fetch_notification notification_id
  return unless OneSignal.config.active

  fetched = Commands::FetchNotification.call notification_id
  Responses::Notification.from_json fetched.body
end
fetch_notifications(page_limit: 50, page_offset: 0, kind: nil) click to toggle source
# File lib/onesignal.rb, line 30
def fetch_notifications(page_limit: 50, page_offset: 0, kind: nil)
  return unless OneSignal.config.active

  Enumerator.new() do |yielder|
    limit = page_limit
    offset = page_offset

    fetched = Commands::FetchNotifications.call limit, offset, kind
    parsed = JSON.parse(fetched.body)

    total_count = parsed["total_count"]
    max_pages = (total_count / limit.to_f).ceil

    loop do
      parsed['notifications'].each do |notification|
        yielder << Responses::Notification.from_json(notification)
      end
      offset += 1
      break if offset >= max_pages
      fetched = Commands::FetchNotifications.call limit, offset*limit, kind
      parsed = JSON.parse(fetched.body)
    end
  end
end
fetch_player(player_id) click to toggle source
# File lib/onesignal.rb, line 55
def fetch_player player_id
  return unless OneSignal.config.active

  fetched = Commands::FetchPlayer.call player_id
  Responses::Player.from_json fetched.body
end
fetch_players() click to toggle source
# File lib/onesignal.rb, line 62
def fetch_players
  return unless OneSignal.config.active

  fetched = Commands::FetchPlayers.call
  JSON.parse(fetched.body)['players'].map { |player| Responses::Player.from_json player }
end
send_notification(notification) click to toggle source
# File lib/onesignal.rb, line 16
def send_notification notification
  return unless OneSignal.config.active

  created = Commands::CreateNotification.call notification
  fetch_notification(JSON.parse(created.body)['id'])
end