Skip to content

Instantly share code, notes, and snippets.

@jbasinger
Created July 1, 2015 20:38
Show Gist options
  • Save jbasinger/acca6dae4cb68a4108fb to your computer and use it in GitHub Desktop.
Save jbasinger/acca6dae4cb68a4108fb to your computer and use it in GitHub Desktop.
Ruby Ionic Push for Android
device_token = 'example_token'
ionic_private_key = 'your_ionic_private_key_here'
ionic_app_id = 'your_ionic_app_id_here'
form_data = {
'tokens' => [device_token],
'notification' => {
'alert' => "Hello Push World!",
'android' => {
'payload' => {
'url' => url,
'$state' => 'home'
}
}
}
}
puts form_data.inspect
uri = URI.parse('https://push.ionic.io/api/v1/push')
req = Net::HTTP::Post.new(uri.path)
req.basic_auth ionic_private_key, ''
req['Content-Type'] = 'application/json'
req['X-Ionic-Application-Id'] = ionic_app_id
req.body = form_data.to_json
puts req.inspect
resp = Net::HTTP.new(uri.host, uri.port)
resp.use_ssl = true
resp.start {|http|
res = http.request(req)
puts res.body
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment