Module: OneSignal

Defined in:
lib/onesignal.rb,
lib/onesignal/icons.rb,
lib/onesignal/client.rb,
lib/onesignal/filter.rb,
lib/onesignal/sounds.rb,
lib/onesignal/buttons.rb,
lib/onesignal/segment.rb,
lib/onesignal/version.rb,
lib/onesignal/auto_map.rb,
lib/onesignal/commands.rb,
lib/onesignal/responses.rb,
lib/onesignal/attachments.rb,
lib/onesignal/notification.rb,
lib/onesignal/configuration.rb,
lib/onesignal/included_targets.rb,
lib/onesignal/responses/player.rb,
lib/onesignal/commands/csv_export.rb,
lib/onesignal/responses/csv_export.rb,
lib/onesignal/commands/base_command.rb,
lib/onesignal/commands/fetch_player.rb,
lib/onesignal/notification/contents.rb,
lib/onesignal/notification/headings.rb,
lib/onesignal/commands/delete_player.rb,
lib/onesignal/commands/fetch_players.rb,
lib/onesignal/responses/notification.rb,
lib/onesignal/responses/base_response.rb,
lib/onesignal/commands/fetch_notification.rb,
lib/onesignal/commands/create_notification.rb,
lib/onesignal/commands/fetch_notifications.rb

Defined Under Namespace

Modules: AutoMap, Commands, Responses Classes: Attachments, Buttons, Client, Configuration, Filter, Icons, IncludedTargets, InvalidError, Notification, Segment, Sounds

Constant Summary collapse

VERSION =
'0.6.0'
API_VERSION =
'v1'

Class Method Summary collapse

Class Method Details

.configObject



83
84
85
# File 'lib/onesignal.rb', line 83

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object Also known as: define

Yields:



12
13
14
# File 'lib/onesignal.rb', line 12

def configure
  yield config
end

.csv_export(params = {}) ⇒ Object



76
77
78
79
80
81
# File 'lib/onesignal.rb', line 76

def csv_export params = {}
  return unless OneSignal.config.active

  fetched = Commands::CsvExport.call params
  Responses::CsvExport.from_json fetched.body
end

.delete_player(player_id) ⇒ Object



62
63
64
65
66
67
# File 'lib/onesignal.rb', line 62

def delete_player player_id
  return unless OneSignal.config.active

  fetched = Commands::DeletePlayer.call player_id
  Responses::Player.from_json fetched.body
end

.fetch_notification(notification_id) ⇒ Object



23
24
25
26
27
28
# 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) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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) ⇒ Object



55
56
57
58
59
60
# 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_playersObject



69
70
71
72
73
74
# File 'lib/onesignal.rb', line 69

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) ⇒ Object



16
17
18
19
20
21
# 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