mattt-yahoo-music 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +85 -0
- data/lib/rest.rb +48 -0
- data/lib/yahoo-music/artist.rb +31 -0
- data/lib/yahoo-music/base.rb +147 -0
- data/lib/yahoo-music/category.rb +26 -0
- data/lib/yahoo-music/release.rb +35 -0
- data/lib/yahoo-music/review.rb +32 -0
- data/lib/yahoo-music/track.rb +35 -0
- data/lib/yahoo-music/version.rb +11 -0
- data/lib/yahoo-music/video.rb +31 -0
- data/lib/yahoo-music.rb +29 -0
- data/test/test_helper.rb +12 -0
- data/test/test_yahoo_music_artist.rb +60 -0
- data/test/test_yahoo_music_release.rb +64 -0
- data/yahoo-music.gemspec +38 -0
- metadata +93 -0
data/README
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
= yahoo-music
|
2
|
+
|
3
|
+
A Ruby wrapper for the Yahoo! Music APIs.
|
4
|
+
|
5
|
+
== Example Usage
|
6
|
+
|
7
|
+
=== Artists:
|
8
|
+
|
9
|
+
require 'yahoo-music'
|
10
|
+
include Yahoo::Music
|
11
|
+
Yahoo::Music.app_id = [Your App ID Here]
|
12
|
+
|
13
|
+
artist = Artist.new("Ben Folds Five")
|
14
|
+
|
15
|
+
puts artist.name
|
16
|
+
puts artist.website
|
17
|
+
|
18
|
+
puts '*' * 40
|
19
|
+
puts
|
20
|
+
|
21
|
+
puts 'Releases'
|
22
|
+
artist.releases.each do |release|
|
23
|
+
puts "\t- %s" % release.title
|
24
|
+
end
|
25
|
+
|
26
|
+
=== Releases & Tracks:
|
27
|
+
|
28
|
+
require 'yahoo-music'
|
29
|
+
include Yahoo::Music
|
30
|
+
Yahoo::Music.app_id = [Your App ID Here]
|
31
|
+
|
32
|
+
album = Album.search("The White Album").first
|
33
|
+
|
34
|
+
puts album.title
|
35
|
+
puts album.artist
|
36
|
+
puts "Release Date:" + album.released_on.strftime("%m/%d/%Y")
|
37
|
+
|
38
|
+
puts '*' * 40
|
39
|
+
puts
|
40
|
+
|
41
|
+
puts 'Tracks'
|
42
|
+
artist.tracks.each_with_index do |track, i|
|
43
|
+
puts "\t%d %s \t%2d:%2d" % [i, track.title, track.duration / 60, track.duration % 60]
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
== REQUIREMENTS:
|
48
|
+
|
49
|
+
To use this library, you must have a valid Yahoo! App ID.
|
50
|
+
You can get one at http://developer.yahoo.com/wsregapp/
|
51
|
+
|
52
|
+
Additionally, yahoo-music has the following gem dependencies:
|
53
|
+
|
54
|
+
* Hpricot >= 0.6
|
55
|
+
* ActiveSupport >= 2.1.0
|
56
|
+
* FlexMock >= 0.8.2
|
57
|
+
|
58
|
+
== INSTALL:
|
59
|
+
|
60
|
+
* sudo gem install yahoo-music
|
61
|
+
|
62
|
+
== LICENSE:
|
63
|
+
|
64
|
+
(The MIT License)
|
65
|
+
|
66
|
+
Copyright (c) 2008 Mattt Thompson
|
67
|
+
|
68
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
69
|
+
a copy of this software and associated documentation files (the
|
70
|
+
'Software'), to deal in the Software without restriction, including
|
71
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
72
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
73
|
+
permit persons to whom the Software is furnished to do so, subject to
|
74
|
+
the following conditions:
|
75
|
+
|
76
|
+
The above copyright notice and this permission notice shall be
|
77
|
+
included in all copies or substantial portions of the Software.
|
78
|
+
|
79
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
80
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
81
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
82
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
83
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
84
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
85
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/rest.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Ported from John Nunemaker's Scrobbler Gem (http://scrobbler.rubyforge.org/)
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
|
5
|
+
module REST
|
6
|
+
class Connection
|
7
|
+
def initialize(base_url, args = {})
|
8
|
+
@base_url = base_url
|
9
|
+
@username = args['username']
|
10
|
+
@password = args['password']
|
11
|
+
@app_id = args['app_id']
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(resource, args = nil)
|
15
|
+
request(resource, "get", args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(resource, args = nil)
|
19
|
+
request(resource, "post", args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def request(resource, method = "get", args = nil)
|
23
|
+
url = URI.join(@base_url, resource)
|
24
|
+
|
25
|
+
if args = args.update('appid' => @app_id)
|
26
|
+
# TODO: What about keys without value?
|
27
|
+
url.query = args.map { |k,v| "%s=%s" % [URI.encode(k), URI.encode(v)] }.join("&")
|
28
|
+
end
|
29
|
+
|
30
|
+
case method
|
31
|
+
when "get"
|
32
|
+
req = Net::HTTP::Get.new(url.request_uri)
|
33
|
+
when "post"
|
34
|
+
req = Net::HTTP::Post.new(url.request_uri)
|
35
|
+
end
|
36
|
+
|
37
|
+
if @username and @password
|
38
|
+
req.basic_auth(@username, @password)
|
39
|
+
end
|
40
|
+
|
41
|
+
http = Net::HTTP.new(url.host, url.port)
|
42
|
+
http.use_ssl = (url.port == 443)
|
43
|
+
|
44
|
+
res = http.start() { |conn| conn.request(req) }
|
45
|
+
res.body
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# <Artist
|
2
|
+
# catzillaID = xs:int
|
3
|
+
# flags = xs:int
|
4
|
+
# hotzillaID = xs:int
|
5
|
+
# id = xs:string
|
6
|
+
# name = xs:string
|
7
|
+
# rating = xs:int
|
8
|
+
# salesGenreCode = xs:int
|
9
|
+
# sortName = xs:string
|
10
|
+
# trackCount = xs:int
|
11
|
+
# website = xs:string
|
12
|
+
# >
|
13
|
+
#
|
14
|
+
# Content:
|
15
|
+
# Image*, Category*, Releases?, TopTracks?, TopSimilarArtists?, RadioStations?, Events?, Fans?, NewsArticles?, ReleaseReviews?, ShortBio?, FullBio?, ItemInfo?, Video*
|
16
|
+
# </Artist>
|
17
|
+
|
18
|
+
module Yahoo
|
19
|
+
module Music
|
20
|
+
class Artist < Base
|
21
|
+
attribute :id, Integer
|
22
|
+
attribute :name, String
|
23
|
+
attribute :sort_name, String, :matcher => "sortName"
|
24
|
+
attribute :website, String
|
25
|
+
|
26
|
+
attribute :releases, Release
|
27
|
+
attribute :categories, Category
|
28
|
+
attribute :videos, Video
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Yahoo
|
2
|
+
module Music
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
attr_accessor :attributes, :associations
|
6
|
+
cattr_accessor :connection
|
7
|
+
|
8
|
+
def attribute(*args)
|
9
|
+
@attributes ||= {}
|
10
|
+
@associations ||= []
|
11
|
+
|
12
|
+
options = args.extract_options!
|
13
|
+
name, type = args
|
14
|
+
class_eval %(attr_accessor :#{name})
|
15
|
+
@attributes[name] = options.update({:type => type})
|
16
|
+
|
17
|
+
if Yahoo::Music::Base.subclasses.include?(type.inspect)
|
18
|
+
@associations << name
|
19
|
+
|
20
|
+
# Define plural and singular association methods
|
21
|
+
define_method("#{name}".pluralize.to_sym) do
|
22
|
+
value = instance_variable_get("@#{name}") || query_association_by_id(name, self.id)
|
23
|
+
instance_variable_set("@#{name}", value)
|
24
|
+
return value
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method("#{name}".singularize.to_sym) do
|
28
|
+
value = instance_variable_get("@#{name}") || query_association_by_id(name, self.id)
|
29
|
+
value = value.first
|
30
|
+
instance_variable_set("@#{name}", value)
|
31
|
+
return value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if options[:type] == Boolean
|
36
|
+
define_method("#{name}?".to_sym) do
|
37
|
+
value = instance_variable_get("@#{name}")
|
38
|
+
return value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def attributes
|
44
|
+
@attributes || {}
|
45
|
+
end
|
46
|
+
|
47
|
+
def associations
|
48
|
+
@associations || []
|
49
|
+
end
|
50
|
+
|
51
|
+
def name_with_demodulization
|
52
|
+
self.name_without_demodulization.demodulize
|
53
|
+
end
|
54
|
+
|
55
|
+
alias_method_chain :name, :demodulization
|
56
|
+
|
57
|
+
def fetch_and_parse(resource, options = {})
|
58
|
+
raise YahooWebServiceError, "No App ID specified" if connection.nil?
|
59
|
+
options = options.update({'response' => self.associations.join(',')}) if self.associations.any?
|
60
|
+
return Hpricot::XML(connection.get(resource, options))
|
61
|
+
end
|
62
|
+
|
63
|
+
def api_path(service, resource, method, *args)
|
64
|
+
response_type = method.nil? ? :item : :list
|
65
|
+
parameters = [service, API_VERSION, response_type, resource, method, *args].compact
|
66
|
+
return parameters.collect!{|param| CGI::escape(param.to_s).downcase}.join('/')
|
67
|
+
end
|
68
|
+
|
69
|
+
# Search by a parameter for a specific service
|
70
|
+
# Ex. Artist.search(term)
|
71
|
+
# options[:search_mode]
|
72
|
+
def search(*args)
|
73
|
+
options = args.extract_options!
|
74
|
+
xml = fetch_and_parse(api_path(self.name, nil, :search, options[:search_mode] || :all, args.join(',')), options)
|
75
|
+
return xml.search(self.name).collect{|elem| self.new(elem)}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def initialize(xml)
|
80
|
+
raise ArgumentError unless xml.kind_of?(Hpricot)
|
81
|
+
|
82
|
+
self.class.attributes.each do |attribute, options|
|
83
|
+
value = xml.attributes[options[:matcher] || attribute.to_s]
|
84
|
+
begin
|
85
|
+
if options[:type] == Integer
|
86
|
+
value = value.to_i
|
87
|
+
elsif options[:type] == Float
|
88
|
+
value = value.to_f
|
89
|
+
elsif options[:type] == Date
|
90
|
+
value = Date.parse(value) rescue nil
|
91
|
+
elsif options[:type] == Boolean
|
92
|
+
value = !! value.to_i.nonzero?
|
93
|
+
elsif self.class.associations.include?(attribute)
|
94
|
+
klass = options[:type]
|
95
|
+
value = xml.search(klass.name).collect{|elem| klass.new(elem)}
|
96
|
+
value = nil if value.empty?
|
97
|
+
end
|
98
|
+
ensure
|
99
|
+
self.instance_variable_set("@#{attribute}", value)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def initialize_with_polymorphism(arg)
|
105
|
+
case arg
|
106
|
+
when String
|
107
|
+
initialize_without_polymorphism(query_by_string(arg))
|
108
|
+
when Integer
|
109
|
+
initialize_without_polymorphism(query_by_id(arg))
|
110
|
+
when Hpricot
|
111
|
+
initialize_without_polymorphism(arg)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
alias_method_chain :initialize, :polymorphism
|
116
|
+
|
117
|
+
protected
|
118
|
+
def query_by_id(id)
|
119
|
+
xml = self.class.fetch_and_parse(self.class.api_path(self.class.name, nil, nil, id))
|
120
|
+
return xml.at(self.class.name)
|
121
|
+
end
|
122
|
+
|
123
|
+
def query_by_string(string)
|
124
|
+
xml = self.class.fetch_and_parse(self.class.api_path(self.class.name, nil, :search, :all, string ))
|
125
|
+
return xml.at(self.class.name)
|
126
|
+
end
|
127
|
+
|
128
|
+
def query_association_by_id(association, id)
|
129
|
+
klass = "yahoo/music/#{association.to_s.singularize}".camelize.constantize
|
130
|
+
xml = self.query_by_id(id).search(klass.name)
|
131
|
+
return xml.collect{|elem| klass.new(elem)}
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class YahooWebServiceError < StandardError; end
|
136
|
+
|
137
|
+
class Artist < Base; end
|
138
|
+
class Category < Base; end
|
139
|
+
class Image < Base; end
|
140
|
+
class Release < Base; end
|
141
|
+
class Review < Base; end
|
142
|
+
class Track < Base; end
|
143
|
+
class Video < Base; end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class Boolean; end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# <Category
|
2
|
+
# artistCount = xs:int
|
3
|
+
# hasAudioStation = xs:boolean
|
4
|
+
# hasRadioStation = xs:boolean
|
5
|
+
# hasVideoStation = xs:boolean
|
6
|
+
# id = xs:string
|
7
|
+
# name = xs:string
|
8
|
+
# rating = xs:int
|
9
|
+
# releaseCount = xs:int
|
10
|
+
# trackCount = xs:int
|
11
|
+
# type = ("Genre"|"Theme"|"Era")
|
12
|
+
# videoCount = xs:int
|
13
|
+
# >
|
14
|
+
#
|
15
|
+
# Content:
|
16
|
+
# ShortDescription?, LongDescription?, Artist*, Station*, Category*
|
17
|
+
# </Category>
|
18
|
+
|
19
|
+
module Yahoo
|
20
|
+
module Music
|
21
|
+
class Category < Base
|
22
|
+
attribute :id, Integer
|
23
|
+
attribute :name, String
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# <Release
|
2
|
+
# UPC = xs:string
|
3
|
+
# catzillaID = xs:int
|
4
|
+
# explicit = xs:boolean
|
5
|
+
# flags = xs:int
|
6
|
+
# id = xs:string
|
7
|
+
# label = xs:string
|
8
|
+
# rating = xs:int
|
9
|
+
# releaseDate = xs:dateTime
|
10
|
+
# releaseYear = xs:int
|
11
|
+
# rights = xs:int
|
12
|
+
# title = xs:string
|
13
|
+
# typeID = xs:int
|
14
|
+
# >
|
15
|
+
#
|
16
|
+
# Content:
|
17
|
+
# Image*, Price*, Track*, Artist*, Category*, Fan*, Review*, ItemInfo?
|
18
|
+
# </Release>
|
19
|
+
|
20
|
+
module Yahoo
|
21
|
+
module Music
|
22
|
+
class Release < Base
|
23
|
+
attribute :id, Integer
|
24
|
+
attribute :title, String
|
25
|
+
attribute :upc, String, :matcher => "UPC"
|
26
|
+
attribute :explicit, Boolean, :matcher => "explicit"
|
27
|
+
attribute :released_on, Date, :matcher => "releaseDate"
|
28
|
+
|
29
|
+
attribute :artists, Artist
|
30
|
+
attribute :categories, Category
|
31
|
+
attribute :reviews, Review
|
32
|
+
attribute :tracks, Track
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# <Review
|
2
|
+
# id = xs:int
|
3
|
+
# publishDate = dateTime
|
4
|
+
# source = xs:string
|
5
|
+
# writer = xs:string
|
6
|
+
# >
|
7
|
+
#
|
8
|
+
# Content:
|
9
|
+
# { xs:string }
|
10
|
+
# </Review>
|
11
|
+
|
12
|
+
module Yahoo
|
13
|
+
module Music
|
14
|
+
class Review < Base
|
15
|
+
attr_reader :content
|
16
|
+
|
17
|
+
attribute :id, Integer
|
18
|
+
attribute :source, String
|
19
|
+
attribute :published_on, Date, :matcher => "publishDate"
|
20
|
+
attribute :website, String
|
21
|
+
|
22
|
+
def initialize(xml)
|
23
|
+
@content = xml.inner_html
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
self.content
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# <Track
|
2
|
+
# discNumber = xs:int
|
3
|
+
# duration = xs:int
|
4
|
+
# explicit = xs:boolean
|
5
|
+
# flags = xs:int
|
6
|
+
# id = xs:string
|
7
|
+
# label = xs:string
|
8
|
+
# popularity = xs:int
|
9
|
+
# rating = xs:int
|
10
|
+
# releaseYear = xs:int
|
11
|
+
# rights = xs:int
|
12
|
+
# title = xs:string
|
13
|
+
# >
|
14
|
+
#
|
15
|
+
# Content:
|
16
|
+
# Image*, Price*, Track*, Artist*, Category*, Fan*, Review*, ItemInfo?
|
17
|
+
# </Track>
|
18
|
+
|
19
|
+
module Yahoo
|
20
|
+
module Music
|
21
|
+
class Track < Base
|
22
|
+
attribute :id, Integer
|
23
|
+
attribute :title, String
|
24
|
+
attribute :duration, Integer
|
25
|
+
attribute :explicit, Boolean
|
26
|
+
|
27
|
+
attribute :release_year, Integer, :matcher => "releaseYear"
|
28
|
+
attribute :track_number, Integer, :matcher => "trackNumber"
|
29
|
+
attribute :disc_number, Integer, :matcher => "discNumber"
|
30
|
+
|
31
|
+
attribute :artists, Artist
|
32
|
+
attribute :releases, Release
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# <Video
|
2
|
+
# copyrightYear = xs:int
|
3
|
+
# duration = xs:int
|
4
|
+
# explicit = xs:boolean
|
5
|
+
# flags = xs:int
|
6
|
+
# id = xs:string
|
7
|
+
# label = xs:string
|
8
|
+
# localOnly = xs:boolean
|
9
|
+
# rating = xs:int
|
10
|
+
# rights = xs:int
|
11
|
+
# salesGenre = xs:int
|
12
|
+
# title = xs:string
|
13
|
+
# typeID = xs:int
|
14
|
+
# >
|
15
|
+
#
|
16
|
+
# Content:
|
17
|
+
# Image*, Artist*, Client*, Category*, Album*, Media*, Bumper?, PaymentLabel?, FlaggedWith*, ItemInfo?, xspf:track?, RecentlyPlayed?
|
18
|
+
# </Video>
|
19
|
+
|
20
|
+
module Yahoo
|
21
|
+
module Music
|
22
|
+
class Video < Base
|
23
|
+
attribute :id, Integer
|
24
|
+
attribute :title, String
|
25
|
+
attribute :duration, Integer
|
26
|
+
attribute :explicit, Boolean
|
27
|
+
|
28
|
+
attribute :copyright_year, Integer, :matcher => "copyrightYear"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/yahoo-music.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
%w{rubygems cgi hpricot activesupport}.each { |x| require x }
|
2
|
+
|
3
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
4
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
5
|
+
|
6
|
+
require 'rest'
|
7
|
+
require 'yahoo-music/base'
|
8
|
+
require 'yahoo-music/version'
|
9
|
+
|
10
|
+
require 'yahoo-music/artist'
|
11
|
+
require 'yahoo-music/category'
|
12
|
+
require 'yahoo-music/release'
|
13
|
+
require 'yahoo-music/review'
|
14
|
+
require 'yahoo-music/track'
|
15
|
+
require 'yahoo-music/video'
|
16
|
+
|
17
|
+
module Yahoo
|
18
|
+
module Music
|
19
|
+
LOCALE = "us"
|
20
|
+
API_URL = "http://#{LOCALE}.music.yahooapis.com/"
|
21
|
+
API_VERSION = 'v1'
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def app_id=(_id)
|
25
|
+
Yahoo::Music::Base::connection = REST::Connection.new(API_URL, 'app_id' => _id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'flexmock'
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'flexmock/test_unit'
|
6
|
+
require File.dirname(__FILE__) + '/../lib/yahoo-music'
|
7
|
+
|
8
|
+
include Yahoo::Music
|
9
|
+
|
10
|
+
def fixture(_filename)
|
11
|
+
File.open(File.dirname(__FILE__) + '/fixtures/%s.xml' % _filename ).read
|
12
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestYahooMusicArtist < Test::Unit::TestCase
|
4
|
+
def test_artist_initialization_from_string
|
5
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
6
|
+
once.with("artist/v1/list/search/all/beirut").
|
7
|
+
and_return(Hpricot::XML(fixture(:artist)))
|
8
|
+
|
9
|
+
assert_nothing_raised do
|
10
|
+
@artist = Artist.new("Beirut")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_artist_initialization_from_id
|
15
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
16
|
+
once.with("artist/v1/item/33892447").
|
17
|
+
and_return(Hpricot::XML(fixture(:artist)))
|
18
|
+
|
19
|
+
assert_nothing_raised do
|
20
|
+
@artist = Artist.new(33892447)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_artist_class_attributes_and_associations
|
25
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
26
|
+
once.with("artist/v1/item/33892447").
|
27
|
+
and_return(Hpricot::XML(fixture(:artist)))
|
28
|
+
|
29
|
+
assert_nothing_raised do
|
30
|
+
@artist = Artist.new(33892447)
|
31
|
+
end
|
32
|
+
|
33
|
+
assert ! Artist.attributes.empty?
|
34
|
+
Artist.attributes.keys.each do |attribute|
|
35
|
+
assert_respond_to @artist, attribute
|
36
|
+
end
|
37
|
+
|
38
|
+
assert ! Artist.associations.empty?
|
39
|
+
Artist.associations.each do |association|
|
40
|
+
assert_respond_to @artist, association
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_artist_instance_variables
|
45
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
46
|
+
once.with("artist/v1/item/33892447").
|
47
|
+
and_return(Hpricot::XML(fixture(:artist)))
|
48
|
+
|
49
|
+
assert_nothing_raised do
|
50
|
+
@artist = Artist.new(33892447)
|
51
|
+
end
|
52
|
+
|
53
|
+
assert_equal @artist.id, 33892447
|
54
|
+
assert_equal @artist.name, "Beirut"
|
55
|
+
assert_equal @artist.website, "http://www.beirutband.com/"
|
56
|
+
assert_nothing_raised do
|
57
|
+
assert @artist.releases.collect{|release| release.title}.include?("Lon Gisland EP")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestYahooMusicRelease < Test::Unit::TestCase
|
4
|
+
def test_release_initialization_from_string
|
5
|
+
flexmock(Release).should_receive(:fetch_and_parse).
|
6
|
+
once.with("release/v1/list/search/all/lon+gisland+ep").
|
7
|
+
and_return(Hpricot::XML(fixture(:release)))
|
8
|
+
|
9
|
+
assert_nothing_raised do
|
10
|
+
@release = Release.new("Lon Gisland EP")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_release_initialization_from_id
|
15
|
+
flexmock(Release).should_receive(:fetch_and_parse).
|
16
|
+
once.with("release/v1/item/39477375").
|
17
|
+
and_return(Hpricot::XML(fixture(:release)))
|
18
|
+
|
19
|
+
assert_nothing_raised do
|
20
|
+
@release = Release.new(39477375)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_release_class_attributes_and_associations
|
25
|
+
flexmock(Release).should_receive(:fetch_and_parse).
|
26
|
+
once.with("release/v1/item/39477375").
|
27
|
+
and_return(Hpricot::XML(fixture(:release)))
|
28
|
+
|
29
|
+
assert_nothing_raised do
|
30
|
+
@release = Release.new(39477375)
|
31
|
+
end
|
32
|
+
|
33
|
+
assert ! Release.attributes.empty?
|
34
|
+
Release.attributes.keys.each do |attribute|
|
35
|
+
assert_respond_to @release, attribute
|
36
|
+
end
|
37
|
+
|
38
|
+
assert ! Release.associations.empty?
|
39
|
+
Release.associations.each do |association|
|
40
|
+
assert_respond_to @release, association
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_release_instance_variables
|
45
|
+
flexmock(Release).should_receive(:fetch_and_parse).
|
46
|
+
once.with("release/v1/item/39477375").
|
47
|
+
and_return(Hpricot::XML(fixture(:release)))
|
48
|
+
|
49
|
+
assert_nothing_raised do
|
50
|
+
@release = Release.new(39477375)
|
51
|
+
end
|
52
|
+
|
53
|
+
assert_equal @release.id, 39477375
|
54
|
+
assert_equal @release.title, "Lon Gisland EP"
|
55
|
+
assert_equal @release.upc, "600197005224"
|
56
|
+
assert_equal @release.explicit, false
|
57
|
+
assert_nothing_raised do
|
58
|
+
["Elephant Gun", "My Family's Role In The World Revolution", "Scenic World (Version)",
|
59
|
+
"The Long Island Sound", "Carousels"].each do |track_title|
|
60
|
+
assert @release.tracks.collect{|track| track.title}.include?(track_title)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/yahoo-music.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "yahoo-music"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2008-11-13"
|
5
|
+
s.summary = "A Ruby wrapper for the Yahoo! Music API."
|
6
|
+
s.email = "mail@matttthompson.com"
|
7
|
+
s.homepage = "http://github.com/mattt/yahoo-music/"
|
8
|
+
s.description = "A Ruby wrapper for the Yahoo! Music API.
|
9
|
+
See http://developer.yahoo.com/music/ for more information about the API."
|
10
|
+
s.authors = ["Mattt Thompson"]
|
11
|
+
|
12
|
+
s.files = [
|
13
|
+
"README",
|
14
|
+
"yahoo-music.gemspec",
|
15
|
+
"lib/yahoo-music.rb",
|
16
|
+
"lib/rest.rb",
|
17
|
+
"lib/yahoo-music/base.rb",
|
18
|
+
"lib/yahoo-music/artist.rb",
|
19
|
+
"lib/yahoo-music/category.rb",
|
20
|
+
"lib/yahoo-music/release.rb",
|
21
|
+
"lib/yahoo-music/review.rb",
|
22
|
+
"lib/yahoo-music/track.rb",
|
23
|
+
"lib/yahoo-music/video.rb",
|
24
|
+
"lib/yahoo-music/version.rb"
|
25
|
+
]
|
26
|
+
s.test_files = [
|
27
|
+
"test/test_helper.rb",
|
28
|
+
"test/test_yahoo_music_artist.rb",
|
29
|
+
"test/test_yahoo_music_release.rb"
|
30
|
+
]
|
31
|
+
|
32
|
+
s.add_dependency("hpricot", ["> 0.6"])
|
33
|
+
s.add_dependency("activesupport", ["> 2.1.0"])
|
34
|
+
s.add_dependency("flexmock", ["> 0.8.2"])
|
35
|
+
|
36
|
+
s.has_rdoc = false
|
37
|
+
s.rdoc_options = ["--main", "README"]
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattt-yahoo-music
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mattt Thompson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-13 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0.6"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: activesupport
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.1.0
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: flexmock
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.2
|
41
|
+
version:
|
42
|
+
description: A Ruby wrapper for the Yahoo! Music API. See http://developer.yahoo.com/music/ for more information about the API.
|
43
|
+
email: mail@matttthompson.com
|
44
|
+
executables: []
|
45
|
+
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
extra_rdoc_files: []
|
49
|
+
|
50
|
+
files:
|
51
|
+
- README
|
52
|
+
- yahoo-music.gemspec
|
53
|
+
- lib/yahoo-music.rb
|
54
|
+
- lib/rest.rb
|
55
|
+
- lib/yahoo-music/base.rb
|
56
|
+
- lib/yahoo-music/artist.rb
|
57
|
+
- lib/yahoo-music/category.rb
|
58
|
+
- lib/yahoo-music/release.rb
|
59
|
+
- lib/yahoo-music/review.rb
|
60
|
+
- lib/yahoo-music/track.rb
|
61
|
+
- lib/yahoo-music/video.rb
|
62
|
+
- lib/yahoo-music/version.rb
|
63
|
+
has_rdoc: false
|
64
|
+
homepage: http://github.com/mattt/yahoo-music/
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --main
|
68
|
+
- README
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.2.0
|
87
|
+
signing_key:
|
88
|
+
specification_version: 2
|
89
|
+
summary: A Ruby wrapper for the Yahoo! Music API.
|
90
|
+
test_files:
|
91
|
+
- test/test_helper.rb
|
92
|
+
- test/test_yahoo_music_artist.rb
|
93
|
+
- test/test_yahoo_music_release.rb
|