Last active
December 18, 2017 18:21
-
-
Save rfoel/fe1862fc408f556bd921eaed5652a75e to your computer and use it in GitHub Desktop.
Check a list of registrations ID or a single one
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
require 'net/http' | |
require 'uri' | |
require 'json' | |
json_file = File.open('rids.json', 'r:bom|utf-8') | |
read_json = json_file.read | |
hashed_json = JSON.parse(read_json) | |
output = File.open('output','w') | |
hashed_json.each_with_index do |rid, index| | |
puts "checking #{index} of #{hashed_json.length}" | |
uri = URI.parse 'https://fcm.googleapis.com/fcm/send' | |
request = Net::HTTP::Post.new uri, 'Content-Type': 'application/json' | |
request['authorization'] = 'key=AIzaSyAu039pqDfcNXwRT2pukdmbs_hm_vzBiEg' | |
request.body = { | |
registration_ids: [rid["registration_id"]] | |
}.to_json | |
req_options = {use_ssl: uri.scheme == 'https'} | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request request | |
end | |
res = JSON.parse response.body | |
puts res['success'] == 0 ? "nok" : "ok" | |
resp = res['success'] == 0 ? "#{rid["id"]}," : "" | |
output << resp | |
end | |
output.close |
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
require 'net/http' | |
require 'uri' | |
require 'json' | |
# ruby check_single.rb YOUR_RID_HERE | |
uri = URI.parse 'https://fcm.googleapis.com/fcm/send' | |
request = Net::HTTP::Post.new uri, 'Content-Type': 'application/json' | |
request['authorization'] = 'key=AIzaSyAu039pqDfcNXwRT2pukdmbs_hm_vzBiEg' | |
request.body = { | |
registration_ids: [ARGV[0]] | |
}.to_json | |
req_options = {use_ssl: uri.scheme == 'https'} | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request request | |
end | |
res = JSON.parse response.body | |
puts res['success'] == 0 ? "nok" : "ok" |
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
[ | |
{ | |
"registration_id": | |
"dxMe3d7uOBY:APA91bEw_UnRr2sCYgFYndO1Aa-9N_FAbK-3tCqgYx6SBBS3ZsCf5FvTpUB0hH9HTAatRuQ5OjOFEC34U53p1EqIQGUjppdhoPkuvPMnYzASi-Ma0dGorQGsvZgM1VV3VzNpp74a2hWR" | |
}, | |
{ | |
"registration_id": | |
"cozlc_CNKsc:APA91bGafES_hw4IOLDKcjA1AN83dfzguUBeiwHdjZMLF3G2UmH3aDWBsZ36LuDCBUVC4DJY4ab57OfhxbSEgKtHOvNwlc2nFRmBWKl0uZCC3p8Du2m182WWvrHpvJ3190Z9UPIbqv-j" | |
}, | |
{ | |
"registration_id": | |
"eGsmzU6TMWg:APA91bE6p0D7HjNIPgdhW_x9XjquQ9f3GyTLzjP463gbVsodRLhhCyw-7T09NWHHXxpWOgVX564Rv-R24ppgrUu5L1GOg_YM1u6nsm9lybtiD81ATHALUTtypPXVuClFm2YATxwWu4Ai" | |
}, | |
{ | |
"registration_id": | |
"fAagMBo-1H0:APA91bHdYTx2TaexlBoMlrH4zqq1l6kUFfAf4O204O7DF5BskgbcI8Q9c_5scqMDb1ssPFb4hsdlU7jjuUl_Q2naFxiwyY42n3Q2iLNtuNEp6S9DjiQw9bdiD4hEfCuIYcZK7TvW_MY_" | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment