Create a gist now

Instantly share code, notes, and snippets.

@fra3il /0.rb Secret
Last active Jan 29, 2016

What would you like to do?
[WP/1475] Houston 을 이용한 Feedback service 맛보기
# 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