Class: OneSignal::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/onesignal/client.rb

Defined Under Namespace

Classes: ApiError

Instance Method Summary collapse

Constructor Details

#initialize(app_id, api_key, api_url) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/onesignal/client.rb', line 9

def initialize app_id, api_key, api_url
  @app_id = app_id
  @api_key = api_key
  @api_url = api_url
  @conn = ::Faraday.new(url: api_url) do |faraday|
    # faraday.response :logger do |logger|
    #   logger.filter(/(api_key=)(\w+)/, '\1[REMOVED]')
    #   logger.filter(/(Basic )(\w+)/, '\1[REMOVED]')
    # end
    faraday.adapter Faraday.default_adapter
  end
end

Instance Method Details

#create_notification(notification) ⇒ Object



22
23
24
# File 'lib/onesignal/client.rb', line 22

def create_notification notification
  post 'notifications', notification
end

#csv_export(extra_fields: nil, last_active_since: nil, segment_name: nil) ⇒ Object



48
49
50
51
52
53
# File 'lib/onesignal/client.rb', line 48

def csv_export extra_fields: nil, last_active_since: nil, segment_name: nil
  post "players/csv_export?app_id=#{@app_id}", 
    extra_fields: extra_fields, 
    last_active_since: last_active_since&.to_i&.to_s, 
    segment_name: segment_name
end

#delete_player(player_id) ⇒ Object



44
45
46
# File 'lib/onesignal/client.rb', line 44

def delete_player player_id
  delete "players/#{player_id}"
end

#fetch_notification(notification_id) ⇒ Object



26
27
28
# File 'lib/onesignal/client.rb', line 26

def fetch_notification notification_id
  get "notifications/#{notification_id}"
end

#fetch_notifications(page_limit: 50, page_offset: 0, kind: nil) ⇒ Object



30
31
32
33
34
# File 'lib/onesignal/client.rb', line 30

def fetch_notifications page_limit: 50, page_offset: 0, kind: nil
  url = "notifications?limit=#{page_limit}&offset=#{page_offset}"
  url = kind ? "#{url}&kind=#{kind}" : url
  get url
end

#fetch_player(player_id) ⇒ Object



40
41
42
# File 'lib/onesignal/client.rb', line 40

def fetch_player player_id
  get "players/#{player_id}"
end

#fetch_playersObject



36
37
38
# File 'lib/onesignal/client.rb', line 36

def fetch_players
  get 'players'
end