Skip to content

Instantly share code, notes, and snippets.

@Yengas
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save Yengas/9601386 to your computer and use it in GitHub Desktop.

Select an option

Save Yengas/9601386 to your computer and use it in GitHub Desktop.
Example of GCM HTTP send in Ruby
#encoding: utf-8
require 'net/http'
require 'json'
require 'openssl'
GOOGLE_API_KEY = "xxxxx";
GOOGLE_PROJECT_NUMBER = "xxxx";
data = { 'message' => 'Deneme' };
to = ["put", "keys", "in", "this", "array"];
headers = {
'project_id' => GOOGLE_PROJECT_NUMBER,
'Authorization' => 'key=' + GOOGLE_API_KEY,
'Content-Type' => 'application/json'
};
uri = URI("https://android.googleapis.com/gcm/send");
http = Net::HTTP.new(uri.host, uri.port);
http.use_ssl = true;
http.verify_mode = OpenSSL::SSL::VERIFY_NONE;
post = Net::HTTP::Post.new(uri.path, headers);
post.body = { 'data' => data, 'registration_ids' => to }.to_json;
response = http.request(post);
puts response.body
puts response.code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment