mattt-mtv-music 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +75 -0
- data/lib/mtv-music.rb +20 -0
- data/lib/mtv-music/artist.rb +18 -0
- data/lib/mtv-music/base.rb +140 -0
- data/lib/mtv-music/version.rb +11 -0
- data/lib/mtv-music/video.rb +68 -0
- data/lib/rest.rb +60 -0
- data/mtv-music.gemspec +34 -0
- data/test/test_helper.rb +12 -0
- data/test/test_mtv_music_artist.rb +62 -0
- data/test/test_mtv_music_video.rb +52 -0
- metadata +89 -0
data/README
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= mtv-music
|
2
|
+
|
3
|
+
A Ruby wrapper for the MTV Music API.
|
4
|
+
See http://developer.mtvnservices.com/ for more information about the API.
|
5
|
+
|
6
|
+
== Example Usage
|
7
|
+
|
8
|
+
=== Artists:
|
9
|
+
|
10
|
+
require 'mtv-music'
|
11
|
+
include MTV::Music
|
12
|
+
|
13
|
+
artist = Artist.new("Radiohead")
|
14
|
+
|
15
|
+
puts artist.name
|
16
|
+
puts artist.website
|
17
|
+
|
18
|
+
puts '*' * 40
|
19
|
+
puts
|
20
|
+
|
21
|
+
puts 'Videos'
|
22
|
+
artist.videos.each do |video|
|
23
|
+
puts "\t- %s" % video.title
|
24
|
+
end
|
25
|
+
|
26
|
+
=== Videos:
|
27
|
+
|
28
|
+
require 'mtv-music'
|
29
|
+
include MTV::Music
|
30
|
+
|
31
|
+
video = Video.new("hznHivqrbHHZBZNXB") # Radiohead's "There There"
|
32
|
+
|
33
|
+
puts video.title
|
34
|
+
puts video.artist.name
|
35
|
+
puts video.released_on
|
36
|
+
|
37
|
+
# The MTV Music API makes it easy to embed videos into any webpage
|
38
|
+
puts video.embed_code
|
39
|
+
# <embed src="http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:202930"
|
40
|
+
# width="448" height="366" type="application/x-shockwave-flash"
|
41
|
+
# allowFullScreen="true" allowScriptAccess="always" flashvars="autoPlay=false" />
|
42
|
+
|
43
|
+
|
44
|
+
== REQUIREMENTS:
|
45
|
+
|
46
|
+
mtv-music has the following gem dependencies:
|
47
|
+
|
48
|
+
* Hpricot >= 0.6
|
49
|
+
* ActiveSupport >= 2.1.0
|
50
|
+
* FlexMock >= 0.8.2
|
51
|
+
|
52
|
+
== LICENSE:
|
53
|
+
|
54
|
+
(The MIT License)
|
55
|
+
|
56
|
+
Copyright (c) 2008 Mattt Thompson
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
59
|
+
a copy of this software and associated documentation files (the
|
60
|
+
'Software'), to deal in the Software without restriction, including
|
61
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
62
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
63
|
+
permit persons to whom the Software is furnished to do so, subject to
|
64
|
+
the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be
|
67
|
+
included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
70
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
71
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
72
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
73
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
74
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
75
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/mtv-music.rb
ADDED
@@ -0,0 +1,20 @@
|
|
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 'mtv-music/base'
|
8
|
+
require 'mtv-music/version'
|
9
|
+
|
10
|
+
require 'mtv-music/artist'
|
11
|
+
require 'mtv-music/video'
|
12
|
+
|
13
|
+
module MTV
|
14
|
+
module Music
|
15
|
+
API_VERSION = '1'
|
16
|
+
API_URL = "http://api.mtvnservices.com/#{API_VERSION}/"
|
17
|
+
|
18
|
+
MTV::Music::Base::connection = REST::Connection.new(API_URL, :rate_limit => 0.68)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MTV
|
2
|
+
module Music
|
3
|
+
class Artist < Base
|
4
|
+
attribute :name, String, :matcher => "author/name"
|
5
|
+
attribute :thumbnail_url, String, :matcher => "media:thumbnail", :attribute => "url"
|
6
|
+
|
7
|
+
def videos
|
8
|
+
xml = Video.fetch_and_parse(self.class.api_path(:videos, self.id))
|
9
|
+
return xml.search("entry/id").collect{|elem| Video.new(Video.fetch_and_parse(elem.inner_text))}
|
10
|
+
end
|
11
|
+
|
12
|
+
def related
|
13
|
+
xml = Artist.fetch_and_parse(self.class.api_path(:related, self.id))
|
14
|
+
return xml.search("entry/id").collect{|elem| Artist.new(Artist.fetch_and_parse(elem.inner_text))}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
module MTV
|
2
|
+
module Music
|
3
|
+
class Base
|
4
|
+
class << self
|
5
|
+
|
6
|
+
cattr_accessor :attributes
|
7
|
+
cattr_accessor :connection
|
8
|
+
|
9
|
+
def attribute(*args)
|
10
|
+
@attributes ||= {}
|
11
|
+
|
12
|
+
options = args.extract_options!
|
13
|
+
name, type = args
|
14
|
+
class_eval %(attr_accessor :#{name})
|
15
|
+
@attributes[name] = options.update({:type => type})
|
16
|
+
end
|
17
|
+
|
18
|
+
def attributes
|
19
|
+
@attributes || {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def name_with_demodulization
|
23
|
+
self.name_without_demodulization.demodulize
|
24
|
+
end
|
25
|
+
|
26
|
+
alias_method_chain :name, :demodulization
|
27
|
+
|
28
|
+
def fetch_and_parse(resource, options = {})
|
29
|
+
return Hpricot::XML(connection.get(resource, options))
|
30
|
+
end
|
31
|
+
|
32
|
+
def api_path(method, id = nil)
|
33
|
+
parameters = [self.name, id, method].compact
|
34
|
+
return parameters.collect!{|param| CGI::escape(param.to_s).downcase}.join('/')
|
35
|
+
end
|
36
|
+
|
37
|
+
# Generic Feed Parameters
|
38
|
+
|
39
|
+
# feed-format Specifies the format of the feed to be returned.
|
40
|
+
# value: atom, mrss
|
41
|
+
# example: ?feed-format=mrss
|
42
|
+
# max-results Limit the maximum number of results. The default value is 25. The maximum value is 100
|
43
|
+
# value: 25, 1-100
|
44
|
+
# example: ?max-results=25
|
45
|
+
# start-index Choose the first result to display in the returns. The first return is 1.
|
46
|
+
# When used with the max-results parameter, multiple pages of results can be created.
|
47
|
+
# value: 1, %d
|
48
|
+
# example: ?start-index=26
|
49
|
+
# date Limit the returns to date range specified.
|
50
|
+
# value: MMDDYYYY-MMDDYYYY
|
51
|
+
# example: ?date=01011980-12311989
|
52
|
+
# sort Specifies the sort order for returns.
|
53
|
+
# value: relevance, date_ascending, date_descending
|
54
|
+
# example: ?sort=date_ascending
|
55
|
+
def search(term, options = {})
|
56
|
+
options = options.update({:term => term})
|
57
|
+
case date = options[:date]
|
58
|
+
when Range
|
59
|
+
options[:date] = "%s-%s" % [date.first, date.last].collect{|d| d.strftime("%m%d%Y")}
|
60
|
+
when Time
|
61
|
+
options[:date] = "%s-%s" % [date, Time.now].collect{|d| d.strftime("%m%d%Y")}
|
62
|
+
end
|
63
|
+
|
64
|
+
xml = fetch_and_parse(api_path(:search), options)
|
65
|
+
results = xml.search(:entry).collect{|elem| self.new(fetch_and_parse((elem/'id').inner_text))}
|
66
|
+
return results.delete_if{|e| e.uri.blank?}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
attr_accessor :id, :uri
|
71
|
+
|
72
|
+
def initialize(xml)
|
73
|
+
raise ArgumentError unless xml.kind_of?(Hpricot)
|
74
|
+
|
75
|
+
if xml.at(:uri).inner_text == "http://api.mtvnservices.com/1/"
|
76
|
+
raise MTVNetworkServiceError, xml.at(:title).inner_text, xml.at(:content).inner_text
|
77
|
+
end
|
78
|
+
|
79
|
+
@uri = xml.at(:id).inner_text
|
80
|
+
@id = @uri.split('/').last
|
81
|
+
|
82
|
+
self.class.attributes.each do |attribute, options|
|
83
|
+
element = xml.search(options[:matcher]).first
|
84
|
+
next if element.nil?
|
85
|
+
value = options[:attribute] ? element.attributes[options[:attribute]] : element.inner_text# rescue nil
|
86
|
+
begin
|
87
|
+
if options[:type] == Integer
|
88
|
+
value = value.to_i
|
89
|
+
elsif options[:type] == Float
|
90
|
+
value = value.to_f
|
91
|
+
elsif options[:type] == Date
|
92
|
+
value = Date.parse(value) rescue nil
|
93
|
+
end
|
94
|
+
ensure
|
95
|
+
self.instance_variable_set("@#{attribute}", value)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
def initialize_with_polymorphism(arg)
|
102
|
+
case arg
|
103
|
+
when String
|
104
|
+
if arg =~ /http:\/\//
|
105
|
+
initialize_without_polymorphism(query_by_uri(arg))
|
106
|
+
else
|
107
|
+
initialize_without_polymorphism(query_by_string(arg))
|
108
|
+
end
|
109
|
+
when Hpricot
|
110
|
+
initialize_without_polymorphism(arg)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
alias_method_chain :initialize, :polymorphism
|
115
|
+
|
116
|
+
protected
|
117
|
+
|
118
|
+
def query_by_string(string)
|
119
|
+
xml = self.class.fetch_and_parse(self.class.api_path(nil, string.gsub(/\s+/, '_')))
|
120
|
+
return xml.at(:entry)
|
121
|
+
end
|
122
|
+
|
123
|
+
def query_by_uri(uri)
|
124
|
+
xml = self.class.fetch_and_parse(uri)
|
125
|
+
return xml.at(:entry)
|
126
|
+
end
|
127
|
+
|
128
|
+
def query_association_by_id(association, id)
|
129
|
+
klass = "mtv/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 MTVNetworkServiceError < StandardError; end
|
136
|
+
|
137
|
+
class Artist < Base; end
|
138
|
+
class Video < Base; end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module MTV
|
2
|
+
module Music
|
3
|
+
class Video < Base
|
4
|
+
attribute :media_uri, String, :matcher => "media:content", :attribute => "url"
|
5
|
+
attribute :artist_uri, String, :matcher => "author/uri"
|
6
|
+
attribute :title, String, :matcher => "media:title"
|
7
|
+
attribute :description, String, :matcher => "media:description"
|
8
|
+
attribute :director, String, :matcher => "media:credit[@role^='director']"
|
9
|
+
attribute :released_on, Date, :matcher => "published"
|
10
|
+
attribute :updated_on, Date, :matcher => "updated"
|
11
|
+
|
12
|
+
# <embed src="http://media.mtvnservices.com/mgid:uma:video:api.mtvnservices.com:235854"
|
13
|
+
# width="448" height="366" type="application/x-shockwave-flash"
|
14
|
+
# allowFullScreen="true" allowScriptAccess="always" flashvars="autoPlay=false" />
|
15
|
+
def embed_code(options = {})
|
16
|
+
options.update({
|
17
|
+
:src => @media_uri,
|
18
|
+
:type => "application/x-shockwave-flash",
|
19
|
+
:width => "448",
|
20
|
+
:height => "366",
|
21
|
+
:allowFullScreen => "true",
|
22
|
+
:allowScriptAccess => "always",
|
23
|
+
:flashvars => "autoPlay=false"})
|
24
|
+
tag(:embed, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def artist
|
28
|
+
Artist.new(@artist_uri)
|
29
|
+
end
|
30
|
+
|
31
|
+
alias_method :to_html, :embed_code
|
32
|
+
|
33
|
+
class << self
|
34
|
+
# Workaround for case-sensitivity for Video aliases
|
35
|
+
def api_path(method, id = nil)
|
36
|
+
parameters = [self.name.downcase, id, method].compact
|
37
|
+
return parameters.collect!{|param| CGI::escape(param.to_s)}.join('/')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Taken from ActionView#TagHelper
|
43
|
+
def tag(name, options = nil, open = false, escape = true)
|
44
|
+
"<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def tag_options(options, escape = true)
|
48
|
+
unless options.blank?
|
49
|
+
attrs = []
|
50
|
+
if escape
|
51
|
+
options.each do |key, value|
|
52
|
+
next unless value
|
53
|
+
key = key.to_s
|
54
|
+
value = Set.new(%w(disabled readonly multiple)).include?(key) ? key : escape_once(value)
|
55
|
+
attrs << %(#{key}="#{value}")
|
56
|
+
end
|
57
|
+
else
|
58
|
+
attrs = options.map { |key, value| %(#{key}="#{value}") }
|
59
|
+
end
|
60
|
+
" #{attrs.sort * ' '}" unless attrs.empty?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def escape_once(html)
|
65
|
+
html.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |special| ERB::Util::HTML_ESCAPE[special] }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/rest.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Ported from John Nunemaker's Scrobbler Gem (http://scrobbler.rubyforge.org/)
|
2
|
+
|
3
|
+
require 'net/https'
|
4
|
+
require 'activesupport'
|
5
|
+
|
6
|
+
module REST
|
7
|
+
class Connection
|
8
|
+
def initialize(base_url, options = {})
|
9
|
+
@base_url = base_url
|
10
|
+
@username = options[:username]
|
11
|
+
@password = options[:password]
|
12
|
+
|
13
|
+
@rate_limit = options[:rate_limit].to_f
|
14
|
+
@lock_expiry = Time.now.to_f
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(resource, args = nil)
|
18
|
+
request(resource, "get", args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(resource, args = nil)
|
22
|
+
request(resource, "post", args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def request(resource, method = "get", args = {})
|
26
|
+
url = URI.join(@base_url, resource)
|
27
|
+
|
28
|
+
unless args.empty?
|
29
|
+
# TODO: What about keys without value?
|
30
|
+
url.query = args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join("&")
|
31
|
+
end
|
32
|
+
|
33
|
+
case method
|
34
|
+
when "get"
|
35
|
+
req = Net::HTTP::Get.new(url.request_uri)
|
36
|
+
when "post"
|
37
|
+
req = Net::HTTP::Post.new(url.request_uri)
|
38
|
+
end
|
39
|
+
|
40
|
+
if @username and @password
|
41
|
+
req.basic_auth(@username, @password)
|
42
|
+
end
|
43
|
+
|
44
|
+
http = Net::HTTP.new(url.host, url.port)
|
45
|
+
http.use_ssl = (url.port == 443)
|
46
|
+
|
47
|
+
res = http.start() { |conn| conn.request(req) }
|
48
|
+
puts url
|
49
|
+
res.body
|
50
|
+
end
|
51
|
+
|
52
|
+
def request_with_rate_limiting(*args)
|
53
|
+
sleep @lock_expiry - Time.now.to_f rescue ArgumentError
|
54
|
+
@lock_expiry = Time.now.to_f + @rate_limit
|
55
|
+
request_without_rate_limiting(*args)
|
56
|
+
end
|
57
|
+
|
58
|
+
alias_method_chain :request, :rate_limiting
|
59
|
+
end
|
60
|
+
end
|
data/mtv-music.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "mtv-music"
|
3
|
+
s.version = "0.1.0"
|
4
|
+
s.date = "2008-11-13"
|
5
|
+
s.summary = "A Ruby wrapper for the MTV Music API."
|
6
|
+
s.email = "mail@matttthompson.com"
|
7
|
+
s.homepage = "http://github.com/mattt/mtv-music/"
|
8
|
+
s.description = "A Ruby wrapper for the MTV Music API.
|
9
|
+
See http://developer.mtvnservices.com/ for more information about the API."
|
10
|
+
s.authors = ["Mattt Thompson"]
|
11
|
+
|
12
|
+
s.files = [
|
13
|
+
"README",
|
14
|
+
"mtv-music.gemspec",
|
15
|
+
"lib/mtv-music.rb",
|
16
|
+
"lib/rest.rb",
|
17
|
+
"lib/mtv-music/base.rb",
|
18
|
+
"lib/mtv-music/artist.rb",
|
19
|
+
"lib/mtv-music/video.rb",
|
20
|
+
"lib/mtv-music/version.rb"
|
21
|
+
]
|
22
|
+
s.test_files = [
|
23
|
+
"test/test_helper.rb",
|
24
|
+
"test/test_mtv_music_artist.rb",
|
25
|
+
"test/test_mtv_music_video.rb"
|
26
|
+
]
|
27
|
+
|
28
|
+
s.add_dependency("hpricot", ["> 0.6"])
|
29
|
+
s.add_dependency("activesupport", ["> 2.1.0"])
|
30
|
+
s.add_dependency("flexmock", ["> 0.8.2"])
|
31
|
+
|
32
|
+
s.has_rdoc = false
|
33
|
+
s.rdoc_options = ["--main", "README"]
|
34
|
+
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/mtv-music'
|
7
|
+
|
8
|
+
include MTV::Music
|
9
|
+
|
10
|
+
def fixture(_filename)
|
11
|
+
File.open(File.dirname(__FILE__) + '/fixtures/%s.xml' % _filename ).read
|
12
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestMTVMusicArtist < Test::Unit::TestCase
|
4
|
+
def test_artist_initialization_from_alias
|
5
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
6
|
+
once.with("artist/radiohead").
|
7
|
+
and_return(Hpricot::XML(fixture(:radiohead)))
|
8
|
+
|
9
|
+
assert_nothing_raised do
|
10
|
+
@artist = Artist.new("Radiohead")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_artist_initialization_from_alias_with_whitespace
|
15
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
16
|
+
once.with("artist/nine_inch_nails").
|
17
|
+
and_return(Hpricot::XML(fixture(:nine_inch_nails)))
|
18
|
+
|
19
|
+
assert_nothing_raised do
|
20
|
+
@artist = Artist.new("Nine Inch Nails")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_artist_no_such_alias_error
|
25
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
26
|
+
once.with("artist/sailing_three_tuesdays").
|
27
|
+
and_return(Hpricot::XML(fixture(:sailing_three_tuesdays)))
|
28
|
+
|
29
|
+
assert_raise MTVNetworkServiceError do
|
30
|
+
@artist = Artist.new("Sailing Three Tuesdays")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_artist_class_attributes_and_associations
|
35
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
36
|
+
once.with("artist/radiohead").
|
37
|
+
and_return(Hpricot::XML(fixture(:radiohead)))
|
38
|
+
|
39
|
+
assert_nothing_raised do
|
40
|
+
@artist = Artist.new("Radiohead")
|
41
|
+
end
|
42
|
+
|
43
|
+
assert ! Artist.attributes.empty?
|
44
|
+
Artist.attributes.keys.each do |attribute|
|
45
|
+
assert_respond_to @artist, attribute
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_artist_instance_variables
|
50
|
+
flexmock(Artist).should_receive(:fetch_and_parse).
|
51
|
+
once.with("artist/radiohead").
|
52
|
+
and_return(Hpricot::XML(fixture(:radiohead)))
|
53
|
+
|
54
|
+
assert_nothing_raised do
|
55
|
+
@artist = Artist.new("Radiohead")
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_equal @artist.id, "radiohead"
|
59
|
+
assert_equal @artist.uri, "http://api.mtvnservices.com/1/artist/radiohead/"
|
60
|
+
assert_equal @artist.name, "Radiohead"
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestYahooMusicRelease < Test::Unit::TestCase
|
4
|
+
def test_video_initialization_from_alias
|
5
|
+
flexmock(Video).should_receive(:fetch_and_parse).
|
6
|
+
once.with("video/hznHivqrbHHZBZNXB").
|
7
|
+
and_return(Hpricot::XML(fixture(:there_there)))
|
8
|
+
|
9
|
+
assert_nothing_raised do
|
10
|
+
@video = Video.new("hznHivqrbHHZBZNXB")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_artist_nonexistent_id_error
|
15
|
+
flexmock(Video).should_receive(:fetch_and_parse).
|
16
|
+
once.with("video/nil").
|
17
|
+
and_return(Hpricot::XML(fixture(:nil_video)))
|
18
|
+
|
19
|
+
assert_raise MTVNetworkServiceError do
|
20
|
+
@artist = Video.new("nil")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_video_class_attributes_and_associations
|
25
|
+
flexmock(Video).should_receive(:fetch_and_parse).
|
26
|
+
once.with("video/hznHivqrbHHZBZNXB").
|
27
|
+
and_return(Hpricot::XML(fixture(:there_there)))
|
28
|
+
|
29
|
+
assert_nothing_raised do
|
30
|
+
@video = Video.new("hznHivqrbHHZBZNXB")
|
31
|
+
end
|
32
|
+
|
33
|
+
assert ! Video.attributes.empty?
|
34
|
+
Video.attributes.keys.each do |attribute|
|
35
|
+
assert_respond_to @video, attribute
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_video_instance_variables
|
40
|
+
flexmock(Video).should_receive(:fetch_and_parse).
|
41
|
+
once.with("video/hznHivqrbHHZBZNXB").
|
42
|
+
and_return(Hpricot::XML(fixture(:there_there)))
|
43
|
+
|
44
|
+
assert_nothing_raised do
|
45
|
+
@video = Video.new("hznHivqrbHHZBZNXB")
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_equal @video.id, "hznHivqrbHHZDPSP"
|
49
|
+
assert_equal @video.title, "There There"
|
50
|
+
assert_equal @video.director, "Chris Hopewell"
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattt-mtv-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 MTV Music API. See http://developer.mtvnservices.com/ 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
|
+
- mtv-music.gemspec
|
53
|
+
- lib/mtv-music.rb
|
54
|
+
- lib/rest.rb
|
55
|
+
- lib/mtv-music/base.rb
|
56
|
+
- lib/mtv-music/artist.rb
|
57
|
+
- lib/mtv-music/video.rb
|
58
|
+
- lib/mtv-music/version.rb
|
59
|
+
has_rdoc: false
|
60
|
+
homepage: http://github.com/mattt/mtv-music/
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 2
|
85
|
+
summary: A Ruby wrapper for the MTV Music API.
|
86
|
+
test_files:
|
87
|
+
- test/test_helper.rb
|
88
|
+
- test/test_mtv_music_artist.rb
|
89
|
+
- test/test_mtv_music_video.rb
|