wearehunted 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ .document
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Grant Goodale (grant@moreblinktag.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = wearehunted
2
+
3
+ A ruby wrapper around the We Are Hunted API.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Grant Goodale (grant@moreblinktag.com). See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "wearehunted"
8
+ gem.summary = %Q{A Ruby wrapper around the We Are Hunted API.}
9
+ gem.description = %Q{A Ruby wrapper around the We Are Hunted API. See http://wearehunted.com/api for more information.}
10
+ gem.email = "ggoodale@gmail.com"
11
+ gem.homepage = "http://github.com/ggoodale/wearehunted"
12
+ gem.authors = ["ggoodale"]
13
+ gem.add_dependency "httparty", ">= 0"
14
+ gem.add_dependency "json", ">= 0"
15
+ gem.add_development_dependency "shoulda", ">= 0"
16
+ gem.add_development_dependency "fakeweb", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "wearehunted #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,136 @@
1
+ require "httparty"
2
+ require "json"
3
+
4
+ # A ruby wrapper around the We Are Hunted REST API. Borrows heavily from
5
+ # jnunemaker's Twitter gem, though simplified greatly due to the simpler API.
6
+ module WeAreHunted
7
+ include HTTParty
8
+ API_VERSION = 0
9
+ CHART_TYPES = :artists, :singles
10
+ CHART_PERIODS = 1, 7, 30
11
+
12
+ base_uri "wearehunted.com/api"
13
+ format :json
14
+
15
+ class WeAreHuntedError < StandardError
16
+ attr_reader :data
17
+ def initialize(data)
18
+ @data = data
19
+ super
20
+ end
21
+ end
22
+
23
+ class BadRequest < WeAreHuntedError; end
24
+ class RateLimitExceeded < WeAreHuntedError; end
25
+ class NotFound < WeAreHuntedError; end
26
+ class InformWeAreHunted < WeAreHuntedError; end
27
+ class Unavailable < WeAreHuntedError; end
28
+
29
+ # Retrieves suggested songs based on either a block of text or specific artist names.
30
+ # text: A block of text to search for known artist names.
31
+ # name: An artist name to use as a basis for suggestion. Multiple values can be passed in as an array.
32
+ # artist: The We Are Hunted artist IDs to use as a basis for suggestion. Multiple values can be passed in as an array. See WeAreHunted::artist
33
+ # emerging: If true, include emerging artists in the result set. defaults to false.
34
+ # provider: A provider to return urls for. Multiple values can be passed in as an array. Valid options are: image, youtube, myspace, spotify, grooveshark, last.fm, itunes
35
+ # allow_blanks: If true, return results that lack urls for one or more of the specified providers. defaults to false.
36
+ # include_seeds: If true, include the artists specified as seeds in the result set. defaults to false.
37
+ # count: The maximum number of tracks that should be returned.
38
+ #
39
+ def self.suggest(options = {})
40
+ options[:text] = URI.escape(options[:text]) if options[:text]
41
+ perform_get("/suggest/singles/#{query_string_from(options)}")["results"]
42
+ end
43
+
44
+ # Retrieves live chart data for the specified genre and type.
45
+ # name: The chart to retrieve. May be one of: rock, pop, folk, metal, alternative, electronic, punk, rap-hip-hop, twitter, remix
46
+ # type: The type of chart to retrieve. May be one of: :artists, :singles
47
+ # period: Specify the number of days covered by the chart. May be one of: 1, 7, 30.
48
+ # user: Retrieve a chart created by a specific user.
49
+ # count: The maximum number of tracks that should be returned.
50
+ # provider: A provider to return urls for. Multiple values can be passed in as an array. Valid options are: image, youtube, myspace, spotify, grooveshark, last.fm, itunes
51
+ # allow_blanks: If true, return results that lack urls for one or more of the specified providers. defaults to false.
52
+ #
53
+ def self.chart(options = {})
54
+ chart_path = ""
55
+ if options[:user]
56
+ chart_path << "/by/#{options.delete(:user)}/"
57
+ else
58
+
59
+ unless options[:type] && CHART_TYPES.include?(options[:type])
60
+ raise ArgumentError, ":type must be specified (one of artists, singles) when retrieving charts that aren't user-generated"
61
+ end
62
+
63
+ unless options[:period] && CHART_PERIODS.include?(options[:period])
64
+ raise ArgumentError, ":period must be specified (one of 1, 7, 30) when retrieving charts that aren't user-generated"
65
+ end
66
+
67
+ if options[:name]
68
+ chart_path << "/#{options.delete(:name)}"
69
+ end
70
+
71
+ chart_path << "/#{options.delete(:type)}/#{options.delete(:period)}/"
72
+ end
73
+
74
+ perform_get("/chart#{chart_path}#{query_string_from(options)}")["results"]
75
+ end
76
+
77
+ # Retrieves the We Are Hunted id for the specified artist(s).
78
+ # artists: One or more artist names to retrieve the id for.
79
+ #
80
+ # Returns: an array of artist ids
81
+ #
82
+ def self.artist(*artists)
83
+ raise ArgumentError, "Please specify one or more artist names" if artists.empty?
84
+
85
+ if artists.size == 1
86
+ options = {:text => artists[0]}
87
+ else
88
+ options = {:name => artists}
89
+ end
90
+
91
+ perform_get("/lookup/artist/#{query_string_from(options)}")["results"]
92
+ end
93
+
94
+ private
95
+
96
+ def self.perform_get(uri, options = {}) # :nodoc:
97
+ make_friendly(get(uri, options))
98
+ end
99
+
100
+ def self.make_friendly(response) # :nodoc:
101
+ raise_errors(response)
102
+ parse(response)
103
+ end
104
+
105
+
106
+ def self.raise_errors(response) # :nodoc:
107
+ case response.code.to_i
108
+ when 400
109
+ raise BadRequest, "(#{response.code}): #{response.message}"
110
+ when 404
111
+ raise NotFound, "(#{response.code}): #{response.message}"
112
+ when 500
113
+ raise InformWeAreHunted, "We Are Hunted had an internal error. Please let them know. (#{response.code}): #{response.message}"
114
+ when 502..503
115
+ raise Unavailable, "(#{response.code}): #{response.message}"
116
+ end
117
+ end
118
+
119
+ def self.parse(response) # :nodoc:
120
+ return '' if response.body == ''
121
+ JSON.parse(response.body)
122
+ end
123
+
124
+ def self.query_string_from(options) # :nodoc:
125
+ return "" if options.empty?
126
+ "?" << options.inject([]) do |collection, opt|
127
+ case opt[1]
128
+ when Array
129
+ opt[1].each {|val| collection << "#{opt[0]}=#{URI.escape(val.to_s)}"}
130
+ else
131
+ collection << "#{opt[0]}=#{URI.escape(opt[1].to_s)}"
132
+ end
133
+ collection
134
+ end * '&'
135
+ end
136
+ end
@@ -0,0 +1,5 @@
1
+ {
2
+ "results": [
3
+ 48031
4
+ ]
5
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "results": [
3
+ 3024,
4
+ 48452,
5
+ 48031
6
+ ]
7
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "results": [
3
+ 100008,
4
+ 48031
5
+ ]
6
+ }
@@ -0,0 +1,75 @@
1
+ {
2
+ "results":
3
+ [
4
+ {
5
+ "artist":"DELOREAN",
6
+ "track":"Stay close",
7
+ "links":
8
+ {
9
+ }
10
+ },
11
+ {
12
+ "artist":"Suckers",
13
+ "track":"Black Sheep",
14
+ "links":
15
+ {
16
+ }
17
+ },
18
+ {
19
+ "artist":"The Tallest Man On Earth",
20
+ "track":"Burden of Tomorrow",
21
+ "links":
22
+ {
23
+ }
24
+ },
25
+ {
26
+ "artist":"Here We Go Magic",
27
+ "track":"Collector",
28
+ "links":
29
+ {
30
+ }
31
+ },
32
+ {
33
+ "artist":"Yeasayer",
34
+ "track":"O.N.E.",
35
+ "links":
36
+ {
37
+ }
38
+ },
39
+ {
40
+ "artist":"Gotan project",
41
+ "track":"La Gloria",
42
+ "links":
43
+ {
44
+ }
45
+ },
46
+ {
47
+ "artist":"Broken Social Scene",
48
+ "track":"World Sick",
49
+ "links":
50
+ {
51
+ }
52
+ },
53
+ {
54
+ "artist":"The National",
55
+ "track":"Fake Empire",
56
+ "links":
57
+ {
58
+ }
59
+ },
60
+ {
61
+ "artist":"Laura Marling",
62
+ "track":"Devil's Spoke",
63
+ "links":
64
+ {
65
+ }
66
+ },
67
+ {
68
+ "artist":"Joker",
69
+ "track":"Tron",
70
+ "links":
71
+ {
72
+ }
73
+ }
74
+ ]
75
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "results":
3
+ [
4
+ {
5
+ "artist":"DELOREAN",
6
+ "track":"Stay close",
7
+ "links":
8
+ {
9
+ }
10
+ },
11
+ {
12
+ "artist":"Suckers",
13
+ "track":"Black Sheep",
14
+ "links":
15
+ {
16
+ }
17
+ },
18
+ {
19
+ "artist":"The Tallest Man On Earth",
20
+ "track":"Burden of Tomorrow",
21
+ "links":
22
+ {
23
+ }
24
+ },
25
+ {
26
+ "artist":"Here We Go Magic",
27
+ "track":"Collector",
28
+ "links":
29
+ {
30
+ }
31
+ },
32
+ {
33
+ "artist":"Yeasayer",
34
+ "track":"O.N.E.",
35
+ "links":
36
+ {
37
+ }
38
+ }
39
+ ]
40
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "results": [
3
+ {
4
+ "track": "Break Your Heart (feat. Ludacris)",
5
+ "links": {},
6
+ "artist": "Taio Cruz"
7
+ },
8
+ {
9
+ "track": "02 Emer Hush",
10
+ "links": {},
11
+ "artist": "At last an atlas"
12
+ },
13
+ {
14
+ "track": "Say You, Say Me",
15
+ "links": {},
16
+ "artist": "Lionel Richie"
17
+ },
18
+ {
19
+ "track": "Pina Colada Song",
20
+ "links": {},
21
+ "artist": "Rupert Holmes"
22
+ },
23
+ {
24
+ "track": "Mickey",
25
+ "links": {},
26
+ "artist": "Toni Basil"
27
+ },
28
+ {
29
+ "track": "just looking",
30
+ "links": {},
31
+ "artist": "Stereophonics"
32
+ },
33
+ {
34
+ "track": "Lying In The Sun",
35
+ "links": {},
36
+ "artist": "Stereophonics"
37
+ },
38
+ {
39
+ "track": "Number One Enemy",
40
+ "links": {},
41
+ "artist": "Daisy Dares You"
42
+ },
43
+ {
44
+ "track": "Indiana",
45
+ "links": {},
46
+ "artist": "Jon McLaughlin"
47
+ },
48
+ {
49
+ "track": "I touch myself",
50
+ "links": {},
51
+ "artist": "Divinyls"
52
+ }
53
+ ]
54
+ }
@@ -0,0 +1,77 @@
1
+
2
+ {
3
+ "results":
4
+ [
5
+ {
6
+ "artist":"Burning Hearts",
7
+ "track":"Various Lives",
8
+ "links":
9
+ {
10
+ }
11
+ },
12
+ {
13
+ "artist":"Say Hi",
14
+ "track":"Oh Oh Oh Oh Oh Oh Oh Oh",
15
+ "links":
16
+ {
17
+ }
18
+ },
19
+ {
20
+ "artist":"At last an atlas",
21
+ "track":"02 Emer Hush",
22
+ "links":
23
+ {
24
+ }
25
+ },
26
+ {
27
+ "artist":"Lionel Richie",
28
+ "track":"Say You, Say Me",
29
+ "links":
30
+ {
31
+ }
32
+ },
33
+ {
34
+ "artist":"The Morning Benders",
35
+ "track":"lovefool (cardigans cover)",
36
+ "links":
37
+ {
38
+ }
39
+ },
40
+ {
41
+ "artist":"Rupert Holmes",
42
+ "track":"Pina Colada Song",
43
+ "links":
44
+ {
45
+ }
46
+ },
47
+ {
48
+ "artist":"Evripidis and his Tragedies",
49
+ "track":"All those summer parties",
50
+ "links":
51
+ {
52
+ }
53
+ },
54
+ {
55
+ "artist":"Junior Boys",
56
+ "track":"Dull To Pause",
57
+ "links":
58
+ {
59
+ }
60
+ },
61
+ {
62
+ "artist":"Phantods",
63
+ "track":"Lone Highway",
64
+ "links":
65
+ {
66
+ }
67
+ },
68
+ {
69
+ "artist":"Matt & Kim",
70
+ "track":"Daylight",
71
+ "links":
72
+ {
73
+ }
74
+ }
75
+ ]
76
+ }
77
+
@@ -0,0 +1,99 @@
1
+
2
+ {
3
+
4
+ "results":
5
+
6
+ [
7
+ {
8
+ "artist":"Say Hi",
9
+ "track":"Oh Oh Oh Oh Oh Oh Oh Oh",
10
+ "links":
11
+ {
12
+ "grooveshark":"http://listen.grooveshark.com/#/song/Oh Oh Oh Oh Oh Oh Oh Oh/22791511",
13
+ "itunes":null
14
+ }
15
+ },
16
+ {
17
+ "artist":"Lionel Richie",
18
+ "track":"Say You, Say Me",
19
+ "links":
20
+ {
21
+ "grooveshark":"http://listen.grooveshark.com/#/song/Say You, Say Me/21875588",
22
+ "itunes":null
23
+ }
24
+ },
25
+ {
26
+ "artist":"Rupert Holmes",
27
+ "track":"Pina Colada Song",
28
+ "links":
29
+ {
30
+ "grooveshark":"http://listen.grooveshark.com/#/song/Pina colada song/23353398",
31
+ "itunes":null
32
+ }
33
+ },
34
+ {
35
+ "artist":"Junior Boys",
36
+ "track":"Dull To Pause",
37
+ "links":
38
+ {
39
+ "grooveshark":"http://listen.grooveshark.com/#/song/Dull To Pause/21815380",
40
+ "itunes":null
41
+ }
42
+ },
43
+ {
44
+ "artist":"Matt & Kim",
45
+ "track":"Daylight",
46
+ "links":
47
+ {
48
+ "grooveshark":"http://listen.grooveshark.com/#/song/Daylight/21999515",
49
+ "itunes":null
50
+ }
51
+ },
52
+ {
53
+ "artist":"Stereophonics",
54
+ "track":"Dakota",
55
+ "links":
56
+ {
57
+ "grooveshark":"http://listen.grooveshark.com/#/song/Dakota/8818493",
58
+ "itunes":null
59
+ }
60
+ },
61
+ {
62
+ "artist":"Jon McLaughlin",
63
+ "track":"Indiana",
64
+ "links":
65
+ {
66
+ "grooveshark":"http://listen.grooveshark.com/#/song/Indiana/7352778",
67
+ "itunes":null
68
+ }
69
+ },
70
+ {
71
+ "artist":"Debbie Gibson",
72
+ "track":"Electric Youth",
73
+ "links":
74
+ {
75
+ "grooveshark":"http://listen.grooveshark.com/#/song/Electric Youth/700412",
76
+ "itunes":null
77
+ }
78
+ },
79
+ {
80
+ "artist":"The Morning Benders",
81
+ "track":"Wet Cement",
82
+ "links":
83
+ {
84
+ "grooveshark":"http://listen.grooveshark.com/#/song/Wet Cement/24535309",
85
+ "itunes":null
86
+ }
87
+ },
88
+ {
89
+ "artist":"The Morning Benders",
90
+ "track":"Excuses",
91
+ "links":
92
+ {
93
+ "grooveshark":"http://listen.grooveshark.com/#/song/Excuses/24535312",
94
+ "itunes":null
95
+ }
96
+ }
97
+ ]
98
+ }
99
+
@@ -0,0 +1,77 @@
1
+
2
+ {
3
+ "results":
4
+ [
5
+ {
6
+ "artist":"Say Hi",
7
+ "track":"Oh Oh Oh Oh Oh Oh Oh Oh",
8
+ "links":
9
+ {
10
+ }
11
+ },
12
+ {
13
+ "artist":"Burning Hearts",
14
+ "track":"Various Lives",
15
+ "links":
16
+ {
17
+ }
18
+ },
19
+ {
20
+ "artist":"At last an atlas",
21
+ "track":"02 Emer Hush",
22
+ "links":
23
+ {
24
+ }
25
+ },
26
+ {
27
+ "artist":"Lionel Richie",
28
+ "track":"Say You, Say Me",
29
+ "links":
30
+ {
31
+ }
32
+ },
33
+ {
34
+ "artist":"Passion Pit",
35
+ "track":"Little Secret (Nouveau!)",
36
+ "links":
37
+ {
38
+ }
39
+ },
40
+ {
41
+ "artist":"Rupert Holmes",
42
+ "track":"Pina Colada Song",
43
+ "links":
44
+ {
45
+ }
46
+ },
47
+ {
48
+ "artist":"Evripidis and his Tragedies",
49
+ "track":"All those summer parties",
50
+ "links":
51
+ {
52
+ }
53
+ },
54
+ {
55
+ "artist":"Junior Boys",
56
+ "track":"Dull To Pause",
57
+ "links":
58
+ {
59
+ }
60
+ },
61
+ {
62
+ "artist":"Phantods",
63
+ "track":"Lone Highway",
64
+ "links":
65
+ {
66
+ }
67
+ },
68
+ {
69
+ "artist":"Matt & Kim",
70
+ "track":"Daylight",
71
+ "links":
72
+ {
73
+ }
74
+ }
75
+ ]
76
+ }
77
+
@@ -0,0 +1,42 @@
1
+
2
+ {
3
+ "results":
4
+ [
5
+ {
6
+ "artist":"Say Hi",
7
+ "track":"Oh Oh Oh Oh Oh Oh Oh Oh",
8
+ "links":
9
+ {
10
+ }
11
+ },
12
+ {
13
+ "artist":"Burning Hearts",
14
+ "track":"Various Lives",
15
+ "links":
16
+ {
17
+ }
18
+ },
19
+ {
20
+ "artist":"At last an atlas",
21
+ "track":"02 Emer Hush",
22
+ "links":
23
+ {
24
+ }
25
+ },
26
+ {
27
+ "artist":"Lionel Richie",
28
+ "track":"Say You, Say Me",
29
+ "links":
30
+ {
31
+ }
32
+ },
33
+ {
34
+ "artist":"Passion Pit",
35
+ "track":"Little Secret (Nouveau!)",
36
+ "links":
37
+ {
38
+ }
39
+ }
40
+ ]
41
+ }
42
+
@@ -0,0 +1,95 @@
1
+ {
2
+ "results":
3
+ [
4
+ {
5
+ "artist":"DELOREAN",
6
+ "track":"Stay close",
7
+ "links":
8
+ {
9
+ "grooveshark":"http://listen.grooveshark.com/#/song/Stay close/24993632",
10
+ "itunes":null
11
+ }
12
+ },
13
+ {
14
+ "artist":"Suckers",
15
+ "track":"Black Sheep",
16
+ "links":
17
+ {
18
+ "grooveshark":"http://listen.grooveshark.com/#/song/Black Sheep/24993649",
19
+ "itunes":null
20
+ }
21
+ },
22
+ {
23
+ "artist":"The Tallest Man On Earth",
24
+ "track":"Burden of Tomorrow",
25
+ "links":
26
+ {
27
+ "grooveshark":"http://listen.grooveshark.com/#/song/Burden of Tomorrow/24663169",
28
+ "itunes":null
29
+ }
30
+ },
31
+ {
32
+ "artist":"Yeasayer",
33
+ "track":"O.N.E.",
34
+ "links":
35
+ {
36
+ "grooveshark":"http://listen.grooveshark.com/#/song/O.N.E./24578382",
37
+ "itunes":null
38
+ }
39
+ },
40
+ {
41
+ "artist":"Broken Social Scene",
42
+ "track":"World Sick",
43
+ "links":
44
+ {
45
+ "grooveshark":"http://listen.grooveshark.com/#/song/World Sick/24554717",
46
+ "itunes":null
47
+ }
48
+ },
49
+ {
50
+ "artist":"The National",
51
+ "track":"Fake Empire",
52
+ "links":
53
+ {
54
+ "grooveshark":"http://listen.grooveshark.com/#/song/Fake Empire/48028",
55
+ "itunes":null
56
+ }
57
+ },
58
+ {
59
+ "artist":"Laura Marling",
60
+ "track":"Devil's Spoke",
61
+ "links":
62
+ {
63
+ "grooveshark":"http://listen.grooveshark.com/#/song/Devil's Spoke/24879369",
64
+ "itunes":null
65
+ }
66
+ },
67
+ {
68
+ "artist":"The Bloody Beetroots",
69
+ "track":"31 Seconds to Die",
70
+ "links":
71
+ {
72
+ "grooveshark":"http://listen.grooveshark.com/#/song/31 Seconds to Die/25003738",
73
+ "itunes":null
74
+ }
75
+ },
76
+ {
77
+ "artist":"Titus Andronicus",
78
+ "track":"a more perfect union",
79
+ "links":
80
+ {
81
+ "grooveshark":"http://listen.grooveshark.com/#/song/A More Perfect Union/24833435",
82
+ "itunes":null
83
+ }
84
+ },
85
+ {
86
+ "artist":"Jedi Mind Tricks",
87
+ "track":"The Philosophy of Horror",
88
+ "links":
89
+ {
90
+ "grooveshark":"http://listen.grooveshark.com/#/song/The Philosophy Of Horror/872204",
91
+ "itunes":null
92
+ }
93
+ }
94
+ ]
95
+ }
data/test/helper.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'wearehunted'
9
+
10
+ class Test::Unit::TestCase
11
+ def stub_get(url, filename, status=nil)
12
+ options = {:body => fixture_file(filename)}
13
+ options.merge!({:status => status}) unless status.nil?
14
+ FakeWeb.register_uri(:get, url, options)
15
+ end
16
+
17
+ def fixture_file(filename)
18
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
19
+ File.read(file_path)
20
+ end
21
+ end
@@ -0,0 +1,105 @@
1
+ require 'helper'
2
+
3
+ class TestWearehunted < Test::Unit::TestCase
4
+ should "have a suggest method for retrieving artist suggestions" do
5
+ stub_get('http://wearehunted.com/api/suggest/singles/?name=Shakira', 'shakira_suggest.json')
6
+ suggestions = WeAreHunted.suggest(:name => "Shakira")
7
+ assert_equal 10, suggestions.size
8
+ first = suggestions.first
9
+ assert_equal 'Say Hi', first['artist']
10
+ end
11
+
12
+ context "has a suggest method that" do
13
+ should "accept multiple artist names" do
14
+ stub_get('http://wearehunted.com/api/suggest/singles/?name=Madonna&name=Shakira', 'madonna_shakira_suggest.json')
15
+ suggestions = WeAreHunted.suggest(:name => ["Madonna", "Shakira"])
16
+ assert_equal 10, suggestions.size
17
+ first = suggestions.first
18
+ assert_equal 'Burning Hearts', first['artist']
19
+ end
20
+
21
+ should "accept artist ids" do
22
+ stub_get('http://wearehunted.com/api/suggest/singles/?artist=3024&artist=48452&artist=48031', 'jennifer_lopez_shakira_suggest.json')
23
+ artist_ids = [3024, 48452, 48031]
24
+ suggestions = WeAreHunted.suggest(:artist => artist_ids)
25
+ assert_equal 10, suggestions.size
26
+ first = suggestions.first
27
+ assert_equal 'Taio Cruz', first['artist']
28
+ end
29
+
30
+ should "limit the number of results when requested" do
31
+ stub_get('http://wearehunted.com/api/suggest/singles/?name=Shakira&count=5', 'shakira_suggest_limited.json')
32
+ suggestions = WeAreHunted.suggest(:name => "Shakira", :count => 5)
33
+ assert_equal 5, suggestions.size
34
+ end
35
+
36
+ should "return links for requested providers" do
37
+ stub_get('http://wearehunted.com/api/suggest/singles/?name=Shakira&provider=itunes&provider=grooveshark', 'shakira_itunes_grooveshark.json')
38
+ suggestions = WeAreHunted.suggest(:name => "Shakira", :provider => ["itunes", "grooveshark"])
39
+ assert_equal 10, suggestions.size
40
+ first = suggestions.first
41
+ assert_equal 'Say Hi', first['artist']
42
+ providers = first['links']
43
+ assert_equal nil, providers['itunes']
44
+ assert_equal "http://listen.grooveshark.com/#/song/Oh Oh Oh Oh Oh Oh Oh Oh/22791511", providers["grooveshark"]
45
+ end
46
+ end
47
+
48
+ should "have a chart method for retrieving charts" do
49
+ stub_get('http://wearehunted.com/api/chart/singles/1/', 'default_daily_singles_chart.json')
50
+ chart = WeAreHunted.chart(:type => :singles, :period => 1)
51
+ assert_equal 10, chart.size
52
+ first = chart.first
53
+ assert_equal 'DELOREAN', first['artist']
54
+ end
55
+
56
+ context "has a chart method that" do
57
+ should "raise an exception if required parameters are missing" do
58
+ assert_raises(ArgumentError){WeAreHunted.chart(:name => "rock")}
59
+ assert_raises(ArgumentError){WeAreHunted.chart(:name => "rock", :type => :artists)}
60
+ assert_raises(ArgumentError){WeAreHunted.chart(:name => "rock", :type => :genres, :period => 7)}
61
+ assert_raises(ArgumentError){WeAreHunted.chart(:name => "rock", :type => :artists, :period => 14)}
62
+ end
63
+
64
+ should "limit the number of results when requested" do
65
+ stub_get('http://wearehunted.com/api/chart/singles/1/?count=5', 'default_daily_singles_chart_limited.json')
66
+ suggestions = WeAreHunted.chart(:type => :singles, :period => 1, :count => 5)
67
+ assert_equal 5, suggestions.size
68
+ end
69
+
70
+ should "return links for requested providers" do
71
+ stub_get('http://wearehunted.com/api/chart/singles/1/?provider=itunes&provider=grooveshark', 'twitter_daily_chart_itunes_grooveshark.json')
72
+ chart = WeAreHunted.chart(:type => :singles, :period => 1, :provider => ["itunes", "grooveshark"])
73
+ assert_equal 10, chart.size
74
+ first = chart.first
75
+ assert_equal 'DELOREAN', first['artist']
76
+ providers = first['links']
77
+ assert_equal nil, providers['itunes']
78
+ assert_equal "http://listen.grooveshark.com/#/song/Stay close/24993632", providers["grooveshark"]
79
+ end
80
+ end
81
+
82
+ should "have and artist method for retrieving artist IDs" do
83
+ stub_get('http://wearehunted.com/api/lookup/artist/?text=Shakira', 'artist_shakira.json')
84
+ result = WeAreHunted.artist("Shakira")
85
+ assert_equal 1, result.size
86
+ assert_equal 48031, result[0]
87
+ end
88
+
89
+ context "has an artist method that" do
90
+ should "return artist ids for artists identified in a block of text" do
91
+ text = "After achieving superstardom throughout Latin America, Colombian-born Shakira became Latin pop's biggest female crossover artist since Jennifer Lopez. Noted for her aggressive, rock-influenced approach."
92
+ stub_get("http://wearehunted.com/api/lookup/artist/?text=#{URI.escape(text)}", 'artist_shakira_blog_post.json')
93
+ result = WeAreHunted.artist(text)
94
+ assert_equal 3, result.size
95
+ assert_equal [3024, 48452, 48031], result
96
+ end
97
+
98
+ should "handle arrays of artist names" do
99
+ stub_get("http://wearehunted.com/api/lookup/artist/?name=Shakira&name=Broken%20Bells", 'artist_shakira_broken_bells.json')
100
+ result = WeAreHunted.artist("Shakira", "Broken Bells")
101
+ assert_equal 2, result.size
102
+ assert_equal [100008, 48031], result
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{wearehunted}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["ggoodale"]
12
+ s.date = %q{2010-03-30}
13
+ s.description = %q{A Ruby wrapper around the We Are Hunted API. See http://wearehunted.com/api for more information.}
14
+ s.email = %q{ggoodale@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/wearehunted.rb",
26
+ "test/fixtures/artist_shakira.json",
27
+ "test/fixtures/artist_shakira_blog_post.json",
28
+ "test/fixtures/artist_shakira_broken_bells.json",
29
+ "test/fixtures/default_daily_singles_chart.json",
30
+ "test/fixtures/default_daily_singles_chart_limited.json",
31
+ "test/fixtures/jennifer_lopez_shakira_suggest.json",
32
+ "test/fixtures/madonna_shakira_suggest.json",
33
+ "test/fixtures/shakira_itunes_grooveshark.json",
34
+ "test/fixtures/shakira_suggest.json",
35
+ "test/fixtures/shakira_suggest_limited.json",
36
+ "test/fixtures/twitter_daily_chart_itunes_grooveshark.json",
37
+ "test/helper.rb",
38
+ "test/test_wearehunted.rb",
39
+ "wearehunted.gemspec"
40
+ ]
41
+ s.homepage = %q{http://github.com/ggoodale/wearehunted}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.6}
45
+ s.summary = %q{A Ruby wrapper around the We Are Hunted API.}
46
+ s.test_files = [
47
+ "test/helper.rb",
48
+ "test/test_wearehunted.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
57
+ s.add_runtime_dependency(%q<json>, [">= 0"])
58
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<httparty>, [">= 0"])
62
+ s.add_dependency(%q<json>, [">= 0"])
63
+ s.add_dependency(%q<shoulda>, [">= 0"])
64
+ s.add_dependency(%q<fakeweb>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<httparty>, [">= 0"])
68
+ s.add_dependency(%q<json>, [">= 0"])
69
+ s.add_dependency(%q<shoulda>, [">= 0"])
70
+ s.add_dependency(%q<fakeweb>, [">= 0"])
71
+ end
72
+ end
73
+
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wearehunted
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - ggoodale
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-30 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: json
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: shoulda
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :development
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: fakeweb
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :development
67
+ version_requirements: *id004
68
+ description: A Ruby wrapper around the We Are Hunted API. See http://wearehunted.com/api for more information.
69
+ email: ggoodale@gmail.com
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - LICENSE
76
+ - README.rdoc
77
+ files:
78
+ - .gitignore
79
+ - LICENSE
80
+ - README.rdoc
81
+ - Rakefile
82
+ - VERSION
83
+ - lib/wearehunted.rb
84
+ - test/fixtures/artist_shakira.json
85
+ - test/fixtures/artist_shakira_blog_post.json
86
+ - test/fixtures/artist_shakira_broken_bells.json
87
+ - test/fixtures/default_daily_singles_chart.json
88
+ - test/fixtures/default_daily_singles_chart_limited.json
89
+ - test/fixtures/jennifer_lopez_shakira_suggest.json
90
+ - test/fixtures/madonna_shakira_suggest.json
91
+ - test/fixtures/shakira_itunes_grooveshark.json
92
+ - test/fixtures/shakira_suggest.json
93
+ - test/fixtures/shakira_suggest_limited.json
94
+ - test/fixtures/twitter_daily_chart_itunes_grooveshark.json
95
+ - test/helper.rb
96
+ - test/test_wearehunted.rb
97
+ - wearehunted.gemspec
98
+ has_rdoc: true
99
+ homepage: http://github.com/ggoodale/wearehunted
100
+ licenses: []
101
+
102
+ post_install_message:
103
+ rdoc_options:
104
+ - --charset=UTF-8
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.3.6
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: A Ruby wrapper around the We Are Hunted API.
128
+ test_files:
129
+ - test/helper.rb
130
+ - test/test_wearehunted.rb