Class: TinySong

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pias.rb

Constant Summary collapse

API_KEY =
"a7a9aeb495388ed7bcd8086fa414a775"

Instance Method Summary collapse

Constructor Details

#initializeTinySong

Returns a new instance of TinySong.



8
9
# File 'lib/pias.rb', line 8

def initialize
end

Instance Method Details

#play_songObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pias.rb', line 11

def play_song
  return 'Please enter a song' if ARGV.count == 0

  song = ARGV.join "+"

  params= {:query => {:format => "json", :key => API_KEY}}
  response=self.class.get("http://tinysong.com/a/#{song}", params)
  url=response.parsed_response.delete("\\")

  if url =~ /tinysong\.com/
    puts "Play it again Sam #{url}"
    `open #{url}`      
  else 
    puts "Error accessing API, try again later."
  end
end