meta-spotify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'meta-spotify'
8
+ require 'fakeweb'
9
+ require 'cgi'
10
+
11
+ FakeWeb.allow_net_connect = false
12
+
13
+ def fixture_file(filename)
14
+ return '' if filename == ''
15
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
16
+ File.read(file_path)
17
+ end
18
+
19
+ TRACK_URI = "spotify:track:3zBhJBEbDD4a4SO1EaEiBP"
20
+ ARTIST_URI = "spotify:artist:4YrKBkKSVeqDamzBPWVnSJ"
21
+ ALBUM_URI = "spotify:album:6G9fHYDCoyEErUkHrFYfs4"
22
+
23
+ class Test::Unit::TestCase
24
+ end
@@ -0,0 +1,64 @@
1
+ require 'helper'
2
+
3
+ class TestAlbum < Test::Unit::TestCase
4
+ context "an album with territories" do
5
+ setup do
6
+ @album = MetaSpotify::Album.new('name' => 'test', 'availability' => { 'territories' => 'DE' })
7
+ @worldwide_album = MetaSpotify::Album.new('name' => 'test', 'availability' => { 'territories' => 'worldwide' })
8
+ end
9
+ should "be available in DE" do
10
+ assert @album.is_available_in?('DE')
11
+ end
12
+ should "not be available in UK" do
13
+ assert @album.is_not_available_in?('UK')
14
+ end
15
+ should "be available anywhere" do
16
+ assert @worldwide_album.is_available_in?('UK')
17
+ end
18
+ end
19
+
20
+ context "searching for an album name" do
21
+ setup do
22
+ FakeWeb.register_uri(:get,
23
+ "http://ws.spotify.com/search/1/album?q=foo",
24
+ :body => fixture_file("album_search.xml"))
25
+ @results = MetaSpotify::Album.search('foo')
26
+ end
27
+ should "return a list of results and search meta" do
28
+ assert_kind_of Array, @results[:albums]
29
+ assert_kind_of MetaSpotify::Album, @results[:albums].first
30
+ assert_equal "Foo Foo", @results[:albums].first.name
31
+ assert_equal 1, @results[:query][:start_page]
32
+ assert_equal 'request', @results[:query][:role]
33
+ assert_equal "foo", @results[:query][:search_terms]
34
+ assert_equal 100, @results[:items_per_page]
35
+ assert_equal 0, @results[:start_index]
36
+ assert_equal 6, @results[:total_results]
37
+ end
38
+ end
39
+
40
+ context "looking up a album" do
41
+ setup do
42
+ FakeWeb.register_uri(:get,
43
+ "http://ws.spotify.com/lookup/1/?uri=#{CGI.escape ALBUM_URI}",
44
+ :body => fixture_file("album.xml"))
45
+ @result = MetaSpotify::Album.lookup(ALBUM_URI)
46
+ end
47
+ should "fetch an album and return an album object" do
48
+ assert_kind_of MetaSpotify::Album, @result
49
+ assert_equal "Remedy", @result.name
50
+ assert_equal "1999", @result.released
51
+ end
52
+ should "create an artist object for that album" do
53
+ assert_kind_of Array, @result.artists
54
+ assert_kind_of MetaSpotify::Artist, @result.artists.first
55
+ assert_equal "Basement Jaxx", @result.artists.first.name
56
+ assert_equal "spotify:artist:4YrKBkKSVeqDamzBPWVnSJ", @result.artists.first.uri
57
+ end
58
+ should "fail trying to look up an track" do
59
+ assert_raises MetaSpotify::URIError do
60
+ MetaSpotify::Album.lookup(TRACK_URI)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ class TestArtist < Test::Unit::TestCase
4
+ context "searching for an artist name" do
5
+ setup do
6
+ FakeWeb.register_uri(:get,
7
+ "http://ws.spotify.com/search/1/artist?q=foo",
8
+ :body => fixture_file("artist_search.xml"))
9
+ @results = MetaSpotify::Artist.search('foo')
10
+ end
11
+ should "return a list of results and search meta" do
12
+ assert_kind_of Array, @results[:artists]
13
+ assert_kind_of MetaSpotify::Artist, @results[:artists].first
14
+ assert_equal "Foo Fighters", @results[:artists].first.name
15
+ assert_equal 1, @results[:query][:start_page]
16
+ assert_equal 'request', @results[:query][:role]
17
+ assert_equal "foo", @results[:query][:search_terms]
18
+ assert_equal 100, @results[:items_per_page]
19
+ assert_equal 0, @results[:start_index]
20
+ assert_equal 9, @results[:total_results]
21
+ end
22
+ end
23
+
24
+ context "looking up an artist" do
25
+ setup do
26
+ FakeWeb.register_uri(:get,
27
+ "http://ws.spotify.com/lookup/1/?uri=#{CGI.escape(ARTIST_URI)}",
28
+ :body => fixture_file("artist.xml"))
29
+ @result = MetaSpotify::Artist.lookup(ARTIST_URI)
30
+ end
31
+ should "fetch an artist and return an artist object" do
32
+ assert_kind_of MetaSpotify::Artist, @result
33
+ assert_equal "Basement Jaxx", @result.name
34
+ end
35
+ should "fail trying to look up an album" do
36
+ assert_raises MetaSpotify::URIError do
37
+ MetaSpotify::Artist.lookup(ALBUM_URI)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,66 @@
1
+ require 'helper'
2
+
3
+ class TestTrack < Test::Unit::TestCase
4
+ context "searching for a track" do
5
+ setup do
6
+ FakeWeb.register_uri(:get,
7
+ "http://ws.spotify.com/search/1/track?q=foo",
8
+ :body => fixture_file("track_search.xml"))
9
+ @results = MetaSpotify::Track.search('foo')
10
+ end
11
+ should "return a list of results and search meta" do
12
+ assert_kind_of Array, @results[:tracks]
13
+ assert_kind_of MetaSpotify::Track, @results[:tracks].first
14
+ assert_equal "Big Me", @results[:tracks].first.name
15
+ assert_equal 1, @results[:query][:start_page]
16
+ assert_equal 'request', @results[:query][:role]
17
+ assert_equal "foo", @results[:query][:search_terms]
18
+ assert_equal 100, @results[:items_per_page]
19
+ assert_equal 0, @results[:start_index]
20
+ assert_equal 486, @results[:total_results]
21
+ end
22
+ end
23
+ context "paginating search" do
24
+ setup do
25
+ FakeWeb.register_uri(:get,
26
+ "http://ws.spotify.com/search/1/track?q=foo&page=2",
27
+ :body => fixture_file("track_search_page_2.xml"))
28
+ @results = MetaSpotify::Track.search('foo', :page => 2)
29
+ end
30
+ should "return page 2's results" do
31
+ assert_equal 2, @results[:query][:start_page]
32
+ assert_equal 100, @results[:start_index]
33
+ end
34
+ end
35
+ context "looking up a track" do
36
+ setup do
37
+ FakeWeb.register_uri(:get,
38
+ "http://ws.spotify.com/lookup/1/?uri=#{CGI.escape TRACK_URI}",
39
+ :body => fixture_file("track.xml"))
40
+ @result = MetaSpotify::Track.lookup(TRACK_URI)
41
+ end
42
+ should "fetch a track and return a track object" do
43
+ assert_kind_of MetaSpotify::Track, @result
44
+ assert_equal "Rendez-vu", @result.name
45
+ assert_equal 1, @result.track_number
46
+ assert_equal 345, @result.length
47
+ assert_equal 0.51368, @result.popularity
48
+ end
49
+ should "create an album object for that track" do
50
+ assert_kind_of MetaSpotify::Album, @result.album
51
+ assert_equal "Remedy", @result.album.name
52
+ assert_equal "spotify:album:6G9fHYDCoyEErUkHrFYfs4", @result.album.uri
53
+ end
54
+ should "create an artist object for that album" do
55
+ assert_kind_of Array, @result.artists
56
+ assert_kind_of MetaSpotify::Artist, @result.artists.first
57
+ assert_equal "Basement Jaxx", @result.artists.first.name
58
+ assert_equal "spotify:artist:4YrKBkKSVeqDamzBPWVnSJ", @result.artists.first.uri
59
+ end
60
+ should "fail trying to look up an artist" do
61
+ assert_raises MetaSpotify::URIError do
62
+ MetaSpotify::Track.lookup(ARTIST_URI)
63
+ end
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meta-spotify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - philnash
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-30 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: A ruby wrapper for the Spotify Metadata API
26
+ email: philnash@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - HISTORY
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/meta-spotify.rb
43
+ - lib/meta-spotify/album.rb
44
+ - lib/meta-spotify/artist.rb
45
+ - lib/meta-spotify/track.rb
46
+ - meta-spotify.gemspec
47
+ - test/fixtures/album.xml
48
+ - test/fixtures/album_search.xml
49
+ - test/fixtures/artist.xml
50
+ - test/fixtures/artist_search.xml
51
+ - test/fixtures/track.xml
52
+ - test/fixtures/track_search.xml
53
+ - test/fixtures/track_search_page_2.xml
54
+ - test/helper.rb
55
+ - test/test_album.rb
56
+ - test/test_artist.rb
57
+ - test/test_track.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/philnash/meta-spotify
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
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.3.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A ruby wrapper for the Spotify Metadata API
86
+ test_files:
87
+ - test/helper.rb
88
+ - test/test_album.rb
89
+ - test/test_artist.rb
90
+ - test/test_track.rb