Created
September 9, 2017 14:47
-
-
Save brunofrank/9a135700a5d0be11fa87ecbfdd504119 to your computer and use it in GitHub Desktop.
Class to make a push to OneSignal API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OneSignal | |
APP_ID = 'ONE_SIGNAL_APP_ID' | |
API_KEY = 'ONE_SIGNAL_APP_KEY' | |
def initialize(title, body, data, players) | |
@title, @body, @data, @players = title, body, data, players | |
end | |
def perform | |
params = { | |
'app_id' => OneSignal::APP_ID, | |
'contents' => { 'en' => @body}, | |
'headings' => { 'en' => @title}, | |
'data' => @data, | |
'include_player_ids' => @players | |
} | |
uri = URI.parse('https://onesignal.com/api/v1/notifications') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json;charset=utf-8', 'Authorization' => "Basic #{OneSignal::API_KEY}") | |
request.body = params.as_json.to_json | |
response = http.request(request) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment