Skip to content

Instantly share code, notes, and snippets.

@parabuzzle
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parabuzzle/ed890a65c4a0f9abb50a to your computer and use it in GitHub Desktop.
Save parabuzzle/ed890a65c4a0f9abb50a to your computer and use it in GitHub Desktop.
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