Created
February 1, 2016 06:11
-
-
Save oojikoo-gist/f43491f23fa838f98072 to your computer and use it in GitHub Desktop.
rails: huston.rb
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
# Houston | |
# https://github.com/nomad/houston | |
# Local and Remote Notification Programming Guide - The Feedback Service | |
# https://goo.gl/vEhEJE | |
require 'houston' | |
APN = Houston::Client.development | |
APN.certificate = File.read("development.pem") | |
# APN = Houston::Client.production | |
# APN.certificate = File.read("production.pem") | |
devices = APN.unregistered_devices | |
# devices = [{:token=>"86bfff30 b8e3e0a4 d6829cca d9e5204e 333c57cd 5b17d189 06412b87 8b07496f", :timestamp=>1453961808}] | |
if devices.any? | |
directory = "./feedback" | |
Dir.mkdir(directory) if !Dir.exist?(directory) | |
file_name = Time.now.strftime("%Y-%m-%d") | |
# ./feedback/2016-01-28.txt | |
file_path = File.join(directory, "#{file_name}.txt") | |
File.open(file_path, "a") do |file| | |
devices.each do |feedback| | |
# 2016-01-28 15:16:48 +0900, 86bfff30 b8e3e0a4 d6829cca d9e5204e 333c57cd 5b17d189 06412b87 8b07496f | |
file.puts "#{Time.at(feedback[:timestamp])}, #{feedback[:token]}" | |
end | |
end | |
puts "+ #{devices.length} feedback" | |
else | |
puts "No feedback available" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment