meta-spotify 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +10 -0
- data/VERSION +1 -1
- data/lib/meta-spotify/album.rb +1 -0
- data/lib/meta-spotify/artist.rb +1 -0
- data/lib/meta-spotify/track.rb +2 -2
- data/lib/meta-spotify.rb +7 -3
- data/meta-spotify.gemspec +3 -2
- data/test/fixtures/artist_search_one_result.xml +12 -0
- data/test/test_album.rb +1 -0
- data/test/test_artist.rb +39 -15
- metadata +3 -2
data/HISTORY
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 0.1.3 / 2009-11-16
|
2
|
+
|
3
|
+
* 1 minor enhancement
|
4
|
+
|
5
|
+
* Added popularity to artists and albums when they are a result of a search
|
6
|
+
|
7
|
+
* 1 bug fix
|
8
|
+
|
9
|
+
* Search results with only one result were failing
|
10
|
+
|
1
11
|
=== 0.1.2 / 2009-11-15
|
2
12
|
|
3
13
|
* 2 minor enhancements
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/meta-spotify/album.rb
CHANGED
data/lib/meta-spotify/artist.rb
CHANGED
data/lib/meta-spotify/track.rb
CHANGED
@@ -3,10 +3,11 @@ module MetaSpotify
|
|
3
3
|
|
4
4
|
URI_REGEX = /^spotify:track:[A-Za-z0-9]+$/
|
5
5
|
|
6
|
-
attr_reader :album, :artists, :track_number, :length
|
6
|
+
attr_reader :album, :artists, :track_number, :length
|
7
7
|
|
8
8
|
def initialize(hash)
|
9
9
|
@name = hash['name']
|
10
|
+
@popularity = hash['popularity'].to_f if hash.has_key? 'popularity'
|
10
11
|
if hash.has_key? 'artist'
|
11
12
|
@artists = []
|
12
13
|
if hash['artist'].is_a? Array
|
@@ -17,7 +18,6 @@ module MetaSpotify
|
|
17
18
|
end
|
18
19
|
@album = Album.new(hash['album']) if hash.has_key? 'album'
|
19
20
|
@track_number = hash['track_number'].to_i if hash.has_key? 'track_number'
|
20
|
-
@popularity = hash['popularity'].to_f if hash.has_key? 'popularity'
|
21
21
|
@length = hash['length'].to_f if hash.has_key? 'length'
|
22
22
|
end
|
23
23
|
end
|
data/lib/meta-spotify.rb
CHANGED
@@ -10,7 +10,7 @@ module MetaSpotify
|
|
10
10
|
include HTTParty
|
11
11
|
base_uri 'http://ws.spotify.com'
|
12
12
|
|
13
|
-
attr_reader :name, :uri
|
13
|
+
attr_reader :name, :uri, :popularity
|
14
14
|
|
15
15
|
def self.search(string, opts={})
|
16
16
|
item_name = self.name.downcase.gsub(/^.*::/,'')
|
@@ -21,8 +21,12 @@ module MetaSpotify
|
|
21
21
|
result = result[item_name+'s']
|
22
22
|
items = []
|
23
23
|
unless result[item_name].nil?
|
24
|
-
result[item_name].
|
25
|
-
|
24
|
+
if result[item_name].is_a? Array
|
25
|
+
result[item_name].each do |item|
|
26
|
+
items << self.new(item)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
items << self.new(result[item_name])
|
26
30
|
end
|
27
31
|
end
|
28
32
|
return { (item_name+'s').to_sym => items,
|
data/meta-spotify.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{meta-spotify}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Phil Nash"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-16}
|
13
13
|
s.email = %q{philnash@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"test/fixtures/album_search.xml",
|
33
33
|
"test/fixtures/artist.xml",
|
34
34
|
"test/fixtures/artist_search.xml",
|
35
|
+
"test/fixtures/artist_search_one_result.xml",
|
35
36
|
"test/fixtures/artist_with_albumdetail.xml",
|
36
37
|
"test/fixtures/track.xml",
|
37
38
|
"test/fixtures/track_search.xml",
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<artists xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1">
|
3
|
+
<opensearch:Query role="request" startPage="1" searchTerms="1200 Micrograms"/>
|
4
|
+
<opensearch:totalResults>1</opensearch:totalResults>
|
5
|
+
<opensearch:startIndex>0</opensearch:startIndex>
|
6
|
+
<opensearch:itemsPerPage>100</opensearch:itemsPerPage>
|
7
|
+
<artist href="spotify:artist:3AUNfvctGVnEOGZiAh0JIK">
|
8
|
+
<name>1200 Micrograms</name>
|
9
|
+
|
10
|
+
<popularity>0.48196</popularity>
|
11
|
+
</artist>
|
12
|
+
</artists>
|
data/test/test_album.rb
CHANGED
@@ -28,6 +28,7 @@ class TestAlbum < Test::Unit::TestCase
|
|
28
28
|
assert_kind_of Array, @results[:albums]
|
29
29
|
assert_kind_of MetaSpotify::Album, @results[:albums].first
|
30
30
|
assert_equal "Foo Foo", @results[:albums].first.name
|
31
|
+
assert_equal 0.29921, @results[:albums].first.popularity
|
31
32
|
assert_equal 1, @results[:query][:start_page]
|
32
33
|
assert_equal 'request', @results[:query][:role]
|
33
34
|
assert_equal "foo", @results[:query][:search_terms]
|
data/test/test_artist.rb
CHANGED
@@ -2,22 +2,46 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestArtist < Test::Unit::TestCase
|
4
4
|
context "searching for an artist name" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
context "many results" do
|
6
|
+
setup do
|
7
|
+
FakeWeb.register_uri(:get,
|
8
|
+
"http://ws.spotify.com/search/1/artist?q=foo",
|
9
|
+
:body => fixture_file("artist_search.xml"))
|
10
|
+
@results = MetaSpotify::Artist.search('foo')
|
11
|
+
end
|
12
|
+
should "return a list of results and search meta" do
|
13
|
+
assert_kind_of Array, @results[:artists]
|
14
|
+
assert_kind_of MetaSpotify::Artist, @results[:artists].first
|
15
|
+
assert_equal "Foo Fighters", @results[:artists].first.name
|
16
|
+
assert_equal 0.89217, @results[:artists].first.popularity
|
17
|
+
assert_equal 1, @results[:query][:start_page]
|
18
|
+
assert_equal 'request', @results[:query][:role]
|
19
|
+
assert_equal "foo", @results[:query][:search_terms]
|
20
|
+
assert_equal 100, @results[:items_per_page]
|
21
|
+
assert_equal 0, @results[:start_index]
|
22
|
+
assert_equal 9, @results[:total_results]
|
23
|
+
end
|
10
24
|
end
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
context "a single result" do
|
26
|
+
setup do
|
27
|
+
FakeWeb.register_uri(:get,
|
28
|
+
"http://ws.spotify.com/search/1/artist?q=1200%20Micrograms",
|
29
|
+
:body => fixture_file("artist_search_one_result.xml"))
|
30
|
+
@results = MetaSpotify::Artist.search('1200 Micrograms')
|
31
|
+
end
|
32
|
+
should "still return a list of results, for consistency" do
|
33
|
+
assert_kind_of Array, @results[:artists]
|
34
|
+
assert_equal 1, @results[:artists].length
|
35
|
+
assert_kind_of MetaSpotify::Artist, @results[:artists].first
|
36
|
+
assert_equal "1200 Micrograms", @results[:artists].first.name
|
37
|
+
assert_equal 0.48196, @results[:artists].first.popularity
|
38
|
+
assert_equal 1, @results[:query][:start_page]
|
39
|
+
assert_equal 'request', @results[:query][:role]
|
40
|
+
assert_equal "1200 Micrograms", @results[:query][:search_terms]
|
41
|
+
assert_equal 100, @results[:items_per_page]
|
42
|
+
assert_equal 0, @results[:start_index]
|
43
|
+
assert_equal 1, @results[:total_results]
|
44
|
+
end
|
21
45
|
end
|
22
46
|
end
|
23
47
|
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Nash
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-16 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- test/fixtures/album_search.xml
|
79
79
|
- test/fixtures/artist.xml
|
80
80
|
- test/fixtures/artist_search.xml
|
81
|
+
- test/fixtures/artist_search_one_result.xml
|
81
82
|
- test/fixtures/artist_with_albumdetail.xml
|
82
83
|
- test/fixtures/track.xml
|
83
84
|
- test/fixtures/track_search.xml
|