Created
August 20, 2014 18:02
-
-
Save F-3r/d03bfe4300156ec4f8ea to your computer and use it in GitHub Desktop.
Dirty ruby script for testing Google Cloud Messaging clients
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
#!/bin/env ruby | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
api_key = ENV['KEY'] | |
uri = URI('https://android.googleapis.com/gcm/send') | |
msg = ARGV.shift | |
ids = ARGV | |
abort "Usage: KEY=<your-api-key> gcm-test <message> (<id>)+" if api_key.nil? || ids.empty? | |
request = Net::HTTP::Post.new(uri) | |
request['Authorization'] = "Key=#{api_key}" | |
request['Content-Type'] = 'application/json' | |
request.body = { registration_ids: ids, data: { message: msg } }.to_json | |
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
http.request request | |
end | |
puts "headers: \n\n" | |
response.header.each_header {|key,value| puts "#{key} = #{value}" } | |
puts "\n\nbody: \n\n" | |
puts response.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment