Last active
August 29, 2015 14:16
-
-
Save parabuzzle/ed890a65c4a0f9abb50a to your computer and use it in GitHub Desktop.
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 'httparty' | |
hipchat_token = ENV['HIPCHAT_TOKEN'] | |
hipchat_email = ENV['HIPCHAT_EMAIL'] | |
hipchat_api = ENV['HIPCHAT_API'] || 'api.hipchat.com' | |
url = "https://#{hipchat_api}/v2/user/#{hipchat_email}?auth_token=#{hipchat_token}" | |
user = JSON.parse HTTParty.get(url).body | |
message = `osascript -e 'tell application "iTunes" | |
set trackname to name of current track | |
set artistname to artist of current track | |
set albumname to album of current track | |
if artistname is null then | |
set artistshow to "" | |
else if artistname is "" then | |
set artistshow to "" | |
else | |
set artistshow to " | " & artistname & "" | |
end if | |
if albumname is null then | |
set albumshow to "" | |
else if albumname is "" then | |
set albumshow to "" | |
else | |
set albumshow to " - " & albumname & "" | |
end if | |
set output to "" & trackname & artistshow & albumshow | |
end tell'` | |
data = { | |
name: user['name'], | |
mention_name: user['mention_name'], | |
email: user['email'], | |
presence: { | |
show: user['presence']['show'], | |
status: message | |
} | |
} | |
HTTParty.put( | |
url, | |
body: data.to_json, | |
headers: { 'Content-Type' => 'application/json' } | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment