meta-spotify 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.3.0 / 2012-10-9
2
+
3
+ * 1 minor update
4
+
5
+ * Adds http_uri method to artist, album and track
6
+
1
7
  === 0.2.0 / 2012-08-31
2
8
 
3
9
  * 1 major update
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 self::URI_REGEX.match(uri)
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)
@@ -1,7 +1,9 @@
1
1
  module MetaSpotify
2
2
  class Album < MetaSpotify::Base
3
3
 
4
- URI_REGEX = /^spotify:album:[A-Za-z0-9]+$/
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
@@ -1,7 +1,9 @@
1
1
  module MetaSpotify
2
2
  class Artist < MetaSpotify::Base
3
3
 
4
- URI_REGEX = /^spotify:artist:[A-Za-z0-9]+$/
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
@@ -1,7 +1,9 @@
1
1
  module MetaSpotify
2
2
  class Track < MetaSpotify::Base
3
3
 
4
- URI_REGEX = /^spotify:track:[A-Za-z0-9]+$/
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
@@ -1,3 +1,3 @@
1
1
  module MetaSpotify
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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
- assert_kind_of MetaSpotify::Album, @results[:albums].first
30
- assert_equal "Foo Foo", @results[:albums].first.name
31
- assert_equal 0.29921, @results[:albums].first.popularity
32
- assert_equal 1, @results[:query][:start_page]
33
- assert_equal 'request', @results[:query][:role]
34
- assert_equal "foo", @results[:query][:search_terms]
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
- 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]
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
- 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
+
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
- 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]
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.2.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-08-30 00:00:00.000000000 Z
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: &70293660427780 !ruby/object:Gem::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: *70293660427780
24
+ version_requirements: *70213547995960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &70293660427280 !ruby/object:Gem::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: *70293660427280
35
+ version_requirements: *70213547995140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fakeweb
38
- requirement: &70293660426760 !ruby/object:Gem::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: *70293660426760
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."