meta-spotify 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +6 -0
- data/lib/meta-spotify.rb +13 -1
- data/lib/meta-spotify/album.rb +8 -1
- data/lib/meta-spotify/artist.rb +8 -1
- data/lib/meta-spotify/track.rb +8 -1
- data/lib/meta-spotify/version.rb +1 -1
- data/test/test_album.rb +15 -6
- data/test/test_artist.rb +24 -12
- data/test/test_track.rb +13 -5
- metadata +8 -8
data/HISTORY
CHANGED
data/lib/meta-spotify.rb
CHANGED
@@ -12,6 +12,10 @@ module MetaSpotify
|
|
12
12
|
|
13
13
|
attr_reader :name, :uri, :popularity
|
14
14
|
|
15
|
+
def self.uri_regex
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
15
19
|
def self.search(string, opts={})
|
16
20
|
item_name = self.name.downcase.gsub(/^.*::/,'')
|
17
21
|
query = {:q => string}
|
@@ -43,7 +47,7 @@ module MetaSpotify
|
|
43
47
|
|
44
48
|
def self.lookup(uri, opts={})
|
45
49
|
uri = uri.strip
|
46
|
-
raise URIError.new("Spotify URI not in the correct syntax") unless
|
50
|
+
raise URIError.new("Spotify URI not in the correct syntax") unless uri_regex.match(uri)
|
47
51
|
query = {:uri => uri}
|
48
52
|
query[:extras] = opts[:extras] if opts.has_key? :extras
|
49
53
|
result = get("/lookup/#{API_VERSION}/",:query => query, :format => :xml)
|
@@ -61,6 +65,14 @@ module MetaSpotify
|
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
68
|
+
def spotify_id
|
69
|
+
if uri
|
70
|
+
uri[self.class.uri_regex, 1]
|
71
|
+
else
|
72
|
+
nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
64
76
|
private
|
65
77
|
|
66
78
|
def self.raise_errors(response)
|
data/lib/meta-spotify/album.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module MetaSpotify
|
2
2
|
class Album < MetaSpotify::Base
|
3
3
|
|
4
|
-
|
4
|
+
def self.uri_regex
|
5
|
+
/^spotify:album:([A-Za-z0-9]+)$/
|
6
|
+
end
|
5
7
|
|
6
8
|
attr_reader :released, :artists, :available_territories, :tracks, :upc,
|
7
9
|
:musicbrainz_id, :musicbrainz_uri, :allmusic_id, :allmusic_uri
|
@@ -58,5 +60,10 @@ module MetaSpotify
|
|
58
60
|
def is_not_available_in?(territory)
|
59
61
|
!is_available_in?(territory)
|
60
62
|
end
|
63
|
+
|
64
|
+
def http_uri
|
65
|
+
"http://open.spotify.com/album/#{spotify_id}"
|
66
|
+
end
|
67
|
+
|
61
68
|
end
|
62
69
|
end
|
data/lib/meta-spotify/artist.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module MetaSpotify
|
2
2
|
class Artist < MetaSpotify::Base
|
3
3
|
|
4
|
-
|
4
|
+
def self.uri_regex
|
5
|
+
/^spotify:artist:([A-Za-z0-9]+)$/
|
6
|
+
end
|
5
7
|
|
6
8
|
attr_reader :albums
|
7
9
|
|
@@ -18,5 +20,10 @@ module MetaSpotify
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
23
|
+
|
24
|
+
def http_uri
|
25
|
+
"http://open.spotify.com/artist/#{spotify_id}"
|
26
|
+
end
|
27
|
+
|
21
28
|
end
|
22
29
|
end
|
data/lib/meta-spotify/track.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module MetaSpotify
|
2
2
|
class Track < MetaSpotify::Base
|
3
3
|
|
4
|
-
|
4
|
+
def self.uri_regex
|
5
|
+
/^spotify:track:([A-Za-z0-9]+)$/
|
6
|
+
end
|
5
7
|
|
6
8
|
attr_reader :album, :artists, :track_number, :length,
|
7
9
|
:musicbrainz_id, :musicbrainz_uri, :allmusic_id, :allmusic_uri
|
@@ -36,5 +38,10 @@ module MetaSpotify
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
41
|
+
|
42
|
+
def http_uri
|
43
|
+
"http://open.spotify.com/track/#{spotify_id}"
|
44
|
+
end
|
45
|
+
|
39
46
|
end
|
40
47
|
end
|
data/lib/meta-spotify/version.rb
CHANGED
data/test/test_album.rb
CHANGED
@@ -26,12 +26,19 @@ class TestAlbum < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
should "return a list of results and search meta" do
|
28
28
|
assert_kind_of Array, @results[:albums]
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
29
|
+
|
30
|
+
album = @results[:albums].first
|
31
|
+
assert_kind_of MetaSpotify::Album, album
|
32
|
+
assert_equal "Foo Foo", album.name
|
33
|
+
assert_equal 0.29921, album.popularity
|
34
|
+
assert_equal '7KXRgAg4K6eXjlYIIXzt3T', album.spotify_id
|
35
|
+
assert_equal 'http://open.spotify.com/album/7KXRgAg4K6eXjlYIIXzt3T', album.http_uri
|
36
|
+
|
37
|
+
query = @results[:query]
|
38
|
+
assert_equal 1, query[:start_page]
|
39
|
+
assert_equal 'request', query[:role]
|
40
|
+
assert_equal "foo", query[:search_terms]
|
41
|
+
|
35
42
|
assert_equal 100, @results[:items_per_page]
|
36
43
|
assert_equal 0, @results[:start_index]
|
37
44
|
assert_equal 6, @results[:total_results]
|
@@ -53,6 +60,8 @@ class TestAlbum < Test::Unit::TestCase
|
|
53
60
|
assert_equal "634904012922", @result.upc
|
54
61
|
assert_equal "3a3685aa-9c4d-42f8-a401-e34a89494041", @result.musicbrainz_id
|
55
62
|
assert_equal "http://www.allmusic.com/cg/amg.dll?p=amg&sql=10:dpfixqtkld0e", @result.allmusic_uri
|
63
|
+
assert_equal '6G9fHYDCoyEErUkHrFYfs4', @result.spotify_id
|
64
|
+
assert_equal 'http://open.spotify.com/album/6G9fHYDCoyEErUkHrFYfs4', @result.http_uri
|
56
65
|
end
|
57
66
|
should "create an artist object for that album" do
|
58
67
|
assert_kind_of Array, @result.artists
|
data/test/test_artist.rb
CHANGED
@@ -11,12 +11,18 @@ class TestArtist < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
should "return a list of results and search meta" do
|
13
13
|
assert_kind_of Array, @results[:artists]
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
assert_equal
|
18
|
-
assert_equal
|
19
|
-
assert_equal
|
14
|
+
|
15
|
+
artist = @results[:artists].first
|
16
|
+
assert_kind_of MetaSpotify::Artist, artist
|
17
|
+
assert_equal "Foo Fighters", artist.name
|
18
|
+
assert_equal 0.89217, artist.popularity
|
19
|
+
assert_equal '7jy3rLJdDQY21OgRLCZ9sD', artist.spotify_id
|
20
|
+
assert_equal 'http://open.spotify.com/artist/7jy3rLJdDQY21OgRLCZ9sD', artist.http_uri
|
21
|
+
|
22
|
+
query = @results[:query]
|
23
|
+
assert_equal 1, query[:start_page]
|
24
|
+
assert_equal 'request', query[:role]
|
25
|
+
assert_equal "foo", query[:search_terms]
|
20
26
|
assert_equal 100, @results[:items_per_page]
|
21
27
|
assert_equal 0, @results[:start_index]
|
22
28
|
assert_equal 9, @results[:total_results]
|
@@ -32,12 +38,18 @@ class TestArtist < Test::Unit::TestCase
|
|
32
38
|
should "still return a list of results, for consistency" do
|
33
39
|
assert_kind_of Array, @results[:artists]
|
34
40
|
assert_equal 1, @results[:artists].length
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert_equal
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
41
|
+
|
42
|
+
artist = @results[:artists].first
|
43
|
+
assert_kind_of MetaSpotify::Artist, artist
|
44
|
+
assert_equal "1200 Micrograms", artist.name
|
45
|
+
assert_equal 0.48196, artist.popularity
|
46
|
+
assert_equal '3AUNfvctGVnEOGZiAh0JIK', artist.spotify_id
|
47
|
+
assert_equal 'http://open.spotify.com/artist/3AUNfvctGVnEOGZiAh0JIK', artist.http_uri
|
48
|
+
|
49
|
+
query = @results[:query]
|
50
|
+
assert_equal 1, query[:start_page]
|
51
|
+
assert_equal 'request', query[:role]
|
52
|
+
assert_equal "1200 Micrograms", query[:search_terms]
|
41
53
|
assert_equal 100, @results[:items_per_page]
|
42
54
|
assert_equal 0, @results[:start_index]
|
43
55
|
assert_equal 1, @results[:total_results]
|
data/test/test_track.rb
CHANGED
@@ -10,11 +10,17 @@ class TestTrack < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
should "return a list of results and search meta" do
|
12
12
|
assert_kind_of Array, @results[:tracks]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
assert_equal
|
17
|
-
assert_equal
|
13
|
+
|
14
|
+
track = @results[:tracks].first
|
15
|
+
assert_kind_of MetaSpotify::Track, track
|
16
|
+
assert_equal "Big Me", track.name
|
17
|
+
assert_equal '6pb5BBnIM5IM7R1cqag6rE', track.spotify_id
|
18
|
+
assert_equal 'http://open.spotify.com/track/6pb5BBnIM5IM7R1cqag6rE', track.http_uri
|
19
|
+
|
20
|
+
query = @results[:query]
|
21
|
+
assert_equal 1, query[:start_page]
|
22
|
+
assert_equal 'request', query[:role]
|
23
|
+
assert_equal "foo", query[:search_terms]
|
18
24
|
assert_equal 100, @results[:items_per_page]
|
19
25
|
assert_equal 0, @results[:start_index]
|
20
26
|
assert_equal 486, @results[:total_results]
|
@@ -48,6 +54,8 @@ class TestTrack < Test::Unit::TestCase
|
|
48
54
|
assert_equal TRACK_URI, @result.uri
|
49
55
|
assert_equal "e230c541-78fb-4d08-99c9-ebcb111d7058", @result.musicbrainz_id
|
50
56
|
assert_equal "http://www.allmusic.com/cg/amg.dll?p=amg&sql=33:jifqxvlhldde", @result.allmusic_uri
|
57
|
+
assert_equal '3zBhJBEbDD4a4SO1EaEiBP', @result.spotify_id
|
58
|
+
assert_equal 'http://open.spotify.com/track/3zBhJBEbDD4a4SO1EaEiBP', @result.http_uri
|
51
59
|
end
|
52
60
|
should "create an album object for that track" do
|
53
61
|
assert_kind_of MetaSpotify::Album, @result.album
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta-spotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70213547995960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0.8'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70213547995960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &70213547995140 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.10.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70213547995140
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: fakeweb
|
38
|
-
requirement: &
|
38
|
+
requirement: &70213547994460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 1.2.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70213547994460
|
47
47
|
description: ! "A ruby wrapper for the Spotify Metadata API.\n See
|
48
48
|
https://developer.spotify.com/technologies/web-api/\n for
|
49
49
|
API documentation."
|