Created
September 11, 2016 16:59
-
-
Save benr75/04bd2dd4fb378ba49399026fc846949e to your computer and use it in GitHub Desktop.
# Script to send push notifications for each song in a Phish Setlist via an updateable Push Notification.
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
# Script to send push notifications for each song in a Phish Setlist via an updateable Push Notification. | |
# Place a config.yml in the same directory as the script and your push notification PEM file. | |
# | |
# Config Format: | |
# push_token: XXXXXXXXXXXXXX | |
# phish_api_key: XXXXXXXXXXXXXX | |
# push_mode: XXXXXXXXXXXXXX # development or production | |
require 'apnotic' | |
require 'phish_dot_net_client' | |
require 'awesome_print' | |
require 'yaml' | |
show_date = ARGV[0] | |
if show_date | |
script_config = YAML.load(File.read(File.expand_path('../config.yml', __FILE__))) | |
PhishDotNetClient.apikey = script_config["phish_api_key"] | |
the_show = PhishDotNetClient.shows_setlists_get :showdate => show_date | |
push_body = "" | |
if script_config["push_mode"] == "development" | |
connection = Apnotic::Connection.new(cert_path: "pushcert.pem", url: "https://api.development.push.apple.com:443") | |
else | |
connection = Apnotic::Connection.new(cert_path: "pushcert.pem") | |
end | |
token = script_config["push_token"] | |
notification = Apnotic::Notification.new(token) | |
notification.apns_id = SecureRandom.uuid | |
notification.apns_collapse_id = "Phish " + the_show[0]["showdate"] + ": " | |
notification.mutable_content = true | |
the_show[0]["setlistdata"].sets.each do |set_data| | |
set_name = set_data.name + ": " | |
set_data.songs.each do |song| | |
song_str = set_name + song.title | |
push_body = push_body + set_name + song.title + "\n" | |
set_name = "" | |
push_content = {'title' => song_str, 'body' => push_body} | |
puts push_content | |
notification.alert = push_content | |
response = connection.push(notification) | |
# read the response | |
puts "" | |
puts response.ok? # => true | |
puts response.status # => '200' | |
puts response.headers # => {":status"=>"200", "apns-id"=>"XXXX"} | |
puts response.body # => "" | |
puts "" | |
sleep(5) | |
end | |
end | |
connection.close | |
else | |
puts "Usage ruby send_push.rb SHOWDATE(Format:YYYY-MM-DD)" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment