meta-spotify 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/meta-spotify/album.rb +13 -11
- data/lib/meta-spotify/version.rb +1 -1
- data/test/fixtures/album_one_upc.xml +12 -0
- data/test/helper.rb +1 -0
- data/test/test_album.rb +22 -3
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 960fbabcafa79a3c832fdd7367bc2de387b0ce3b
|
4
|
+
data.tar.gz: d6a08c80e9d1f62a3559efeff72cb12f6d5286a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 704098dd7cef7f6428f533426b94bb6b7077968eb0b87207ac1ee45d7050288ec5aaabcb4bec43a5c5408993bdb022c2db54061fe379d55fc83832650e3c16d6
|
7
|
+
data.tar.gz: 60b8ff55290ab4b61ac001bb770a64c0800e8ef8fc6619a13c16562b7b9812dde8912656591170571587b6dfcb01cd623c1f7237fe4f92d6ee8a87581a4ff3de
|
data/lib/meta-spotify/album.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module MetaSpotify
|
2
2
|
class Album < MetaSpotify::Base
|
3
|
-
|
3
|
+
|
4
4
|
def self.uri_regex
|
5
5
|
/^spotify:album:([A-Za-z0-9]+)$/
|
6
6
|
end
|
7
|
-
|
8
|
-
attr_reader :released, :artists, :available_territories, :tracks, :upc,
|
7
|
+
|
8
|
+
attr_reader :released, :artists, :available_territories, :tracks, :upc,
|
9
9
|
:musicbrainz_id, :musicbrainz_uri, :allmusic_id, :allmusic_uri
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(hash)
|
12
12
|
@name = hash['name']
|
13
13
|
@popularity = hash['popularity'].to_f if hash.has_key? 'popularity'
|
@@ -29,34 +29,36 @@ module MetaSpotify
|
|
29
29
|
end
|
30
30
|
@released = hash['released'] if hash.has_key? 'released'
|
31
31
|
@uri = hash['href'] if hash.has_key? 'href'
|
32
|
-
|
32
|
+
|
33
33
|
if hash['id'].is_a? Array
|
34
|
-
|
34
|
+
|
35
35
|
hash['id'].each do |id|
|
36
36
|
case id['type']
|
37
|
-
when 'upc' then
|
37
|
+
when 'upc' then
|
38
38
|
@upc = id['__content__']
|
39
39
|
when 'mbid' then
|
40
40
|
@musicbrainz_id = id['__content__']
|
41
41
|
@musicbrainz_uri = id['href']
|
42
|
-
when 'amgid' then
|
42
|
+
when 'amgid' then
|
43
43
|
@allmusic_id = id['__content__']
|
44
44
|
@allmusic_uri = id['href']
|
45
45
|
end
|
46
46
|
end
|
47
|
+
else
|
48
|
+
@upc = hash['id']['__content__'] if hash.has_key? 'id'
|
47
49
|
end
|
48
|
-
|
50
|
+
|
49
51
|
@available_territories = if hash.has_key?('availability') && !hash['availability']['territories'].nil?
|
50
52
|
hash['availability']['territories'].split(/\s+/).map {|t| t.downcase } || []
|
51
53
|
else
|
52
54
|
[]
|
53
55
|
end
|
54
56
|
end
|
55
|
-
|
57
|
+
|
56
58
|
def is_available_in?(territory)
|
57
59
|
(@available_territories.include?('worldwide') || @available_territories.include?(territory.downcase))
|
58
60
|
end
|
59
|
-
|
61
|
+
|
60
62
|
def is_not_available_in?(territory)
|
61
63
|
!is_available_in?(territory)
|
62
64
|
end
|
data/lib/meta-spotify/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<album xmlns="http://www.spotify.com/ns/music/1">
|
3
|
+
<name>Aleph</name>
|
4
|
+
<artist href="spotify:artist:3hteYQFiMFbJY7wS0xDymP">
|
5
|
+
<name>Gesaffelstein</name>
|
6
|
+
</artist>
|
7
|
+
<released>2013</released>
|
8
|
+
<id type="upc">825646397471</id>
|
9
|
+
<availability>
|
10
|
+
<territories>AD AR AT AU BE BG BO BR CH CL CO CR CY CZ DE DK DO EC EE ES FI FR GB GR GT HK HN HR HU IE IS IT LT LU LV MC MT MX MY NI NL NO NZ PA PE PH PL PT PY RO SE SG SI SK SV TR TW UY</territories>
|
11
|
+
</availability>
|
12
|
+
</album>
|
data/test/helper.rb
CHANGED
@@ -19,6 +19,7 @@ end
|
|
19
19
|
TRACK_URI = "spotify:track:3zBhJBEbDD4a4SO1EaEiBP"
|
20
20
|
ARTIST_URI = "spotify:artist:4YrKBkKSVeqDamzBPWVnSJ"
|
21
21
|
ALBUM_URI = "spotify:album:6G9fHYDCoyEErUkHrFYfs4"
|
22
|
+
ALBUM_ONE_UPC_URI = "spotify:album:3MiiF9utmtGnLVITgl0JP7"
|
22
23
|
|
23
24
|
class Test::Unit::TestCase
|
24
25
|
end
|
data/test/test_album.rb
CHANGED
@@ -16,7 +16,7 @@ class TestAlbum < Test::Unit::TestCase
|
|
16
16
|
assert @worldwide_album.is_available_in?('UK')
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
context "searching for an album name" do
|
21
21
|
setup do
|
22
22
|
FakeWeb.register_uri(:get,
|
@@ -44,7 +44,7 @@ class TestAlbum < Test::Unit::TestCase
|
|
44
44
|
assert_equal 6, @results[:total_results]
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
context "looking up a album" do
|
49
49
|
setup do
|
50
50
|
FakeWeb.register_uri(:get,
|
@@ -75,6 +75,25 @@ class TestAlbum < Test::Unit::TestCase
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
context "looking up an album with just an upc code" do
|
80
|
+
setup do
|
81
|
+
FakeWeb.register_uri(:get,
|
82
|
+
"http://ws.spotify.com/lookup/1/?uri=#{CGI.escape ALBUM_ONE_UPC_URI}",
|
83
|
+
:body => fixture_file("album_one_upc.xml"))
|
84
|
+
@result = MetaSpotify::Album.lookup(ALBUM_ONE_UPC_URI)
|
85
|
+
end
|
86
|
+
should "fetch an album and return an album object" do
|
87
|
+
assert_kind_of MetaSpotify::Album, @result
|
88
|
+
assert_equal "Aleph", @result.name
|
89
|
+
assert_equal ALBUM_ONE_UPC_URI, @result.uri
|
90
|
+
assert_equal "2013", @result.released
|
91
|
+
assert_equal "825646397471", @result.upc
|
92
|
+
assert_equal '3MiiF9utmtGnLVITgl0JP7', @result.spotify_id
|
93
|
+
assert_equal 'http://open.spotify.com/album/3MiiF9utmtGnLVITgl0JP7', @result.http_uri
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
78
97
|
context "looking up an album with extra details" do
|
79
98
|
setup do
|
80
99
|
FakeWeb.register_uri(:get,
|
@@ -82,7 +101,7 @@ class TestAlbum < Test::Unit::TestCase
|
|
82
101
|
:body => fixture_file('album_with_trackdetail.xml'))
|
83
102
|
@result = MetaSpotify::Album.lookup(ALBUM_URI, :extras => 'trackdetail')
|
84
103
|
end
|
85
|
-
|
104
|
+
|
86
105
|
should "fetch an album and return an object with more detailed track information" do
|
87
106
|
assert_kind_of MetaSpotify::Album, @result
|
88
107
|
assert_kind_of MetaSpotify::Track, @result.tracks.first
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta-spotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Nash
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/meta-spotify/version.rb
|
76
76
|
- meta-spotify.gemspec
|
77
77
|
- test/fixtures/album.xml
|
78
|
+
- test/fixtures/album_one_upc.xml
|
78
79
|
- test/fixtures/album_search.xml
|
79
80
|
- test/fixtures/album_with_trackdetail.xml
|
80
81
|
- test/fixtures/artist.xml
|
@@ -113,6 +114,7 @@ specification_version: 4
|
|
113
114
|
summary: A ruby wrapper for the Spotify Metadata API
|
114
115
|
test_files:
|
115
116
|
- test/fixtures/album.xml
|
117
|
+
- test/fixtures/album_one_upc.xml
|
116
118
|
- test/fixtures/album_search.xml
|
117
119
|
- test/fixtures/album_with_trackdetail.xml
|
118
120
|
- test/fixtures/artist.xml
|
@@ -126,3 +128,4 @@ test_files:
|
|
126
128
|
- test/test_album.rb
|
127
129
|
- test/test_artist.rb
|
128
130
|
- test/test_track.rb
|
131
|
+
has_rdoc:
|