This repository has been archived by the owner on Jan 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
require 'cgi' | ||
require 'net/http' | ||
require 'uri' | ||
|
||
module Grooveshark | ||
class TinySong | ||
VERSION = '0.0.1' | ||
end | ||
end | ||
|
||
VERSION = '0.0.1' | ||
BASE_URL = 'http://tinysong.com/' | ||
|
||
class << self | ||
|
||
# Returns a URL string with the first match of +search+. | ||
# | ||
# TinySong.first('Bad Brains') # => "http://tinysong.com/2Z5Q" | ||
def first(search, format = 'json') | ||
search = CGI.escape(search) | ||
request = URI.join(BASE_URL, '/a/', search, "?format=#{format}") | ||
sanitize_song_url(Net::HTTP.get(request)) | ||
end | ||
|
||
private | ||
|
||
# Remove any un-needed characters from +url+ (backslashes, quotes, etc.). | ||
# This is needed until the TinySong API is fixed to return a plain string. | ||
def sanitize_song_url(url) | ||
url.gsub!(/["]/, '') | ||
url.gsub!(/\\/, '') | ||
url | ||
end | ||
|
||
end # self | ||
|
||
end # TinySong | ||
end # Grooveshark |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def run_specs | ||
system('rake spec') | ||
end | ||
|
||
# Ctrl-\ | ||
Signal.trap('QUIT') do | ||
puts "\n--- Running all specs ---\n" | ||
run_specs | ||
end | ||
|
||
# Ctrl-C | ||
Signal.trap('INT') { abort("\n") } | ||
|
||
run_specs | ||
|
||
[ | ||
'lib/(.*/)?.*\.rb', | ||
'spec/(.*/)?.*_spec\.rb' | ||
].each do |pattern| | ||
watch(pattern) { |md| run_specs } | ||
end |