spotify-search 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDFlNTE4NGVmNmFlZjUzZTllZjg4NzdlNDMyZTk2NTk5YTI3NTVmMg==
5
+ data.tar.gz: !binary |-
6
+ ODdhNjRiMjgyOGU4M2FkOWU1ZTdiMDA3YWE0NGVkMjY5MTg2YWE5ZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZmU0ZGQ5YzQyZjc0NzlkMzBhMTA1ODUwNzExMmIwOTYwYWM3YjIyNzg5NWJm
10
+ YWRlOTgwNmU1YjYxMjg3MjI4NWI4NGMxODE2NDk2ZWM2MTdhMTBjNWFhYmFj
11
+ N2U0YWM0Y2QwMWM2NWEwYjg1YjZkN2ViYjE2M2JkMmViMDZmYmI=
12
+ data.tar.gz: !binary |-
13
+ OTI2MmFlMjViMjRlZmM1MWVmZTZiNDU5OGJhMGRiYTk5Nzc4MmVjMzYxZThi
14
+ YzQ0NWY3NjhmZjI2NThjYjY4NGU0MDAyYzQ3ZjI3NTRiMmM2ZGYyM2JhNTUx
15
+ NmE0Mjg2NWQ3MmNiZjUwMTEyNDhjNThlNDFhZmZkMWJiNjYwNDY=
@@ -0,0 +1,20 @@
1
+ module Spotify
2
+ module API
3
+ class Base
4
+
5
+ def initialize
6
+ raise(NotImplementedError, "Abstract class not meant to be instantiated directly.")
7
+ end
8
+
9
+ protected
10
+ def search(type, params)
11
+ request(type, params)
12
+ end
13
+
14
+ def request(base, params = {})
15
+ JSON.parse(RestClient.get("#{@uri}#{base}.json", {:params => params}).body)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ module Spotify
5
+ module API
6
+ class Lookup < Spotify::API::Base
7
+
8
+ def initialize
9
+ @uri = "http://ws.spotify.com/lookup/1/"
10
+ end
11
+
12
+ def artist(uri, level=nil)
13
+ params = level == nil ? {} : { :extras => 'albumdetail' }
14
+ results = search(nil, params.merge(:uri => "spotify:artist:#{uri}"))
15
+
16
+ case level
17
+ when :detailed
18
+ artist = Resources::Lookup::ArtistDetailed.new(results['artist'])
19
+ else
20
+ artist = Resources::Lookup::ArtistBase.new(results['artist'])
21
+ end
22
+ Resources::Base.new(results['info'], artist)
23
+ end
24
+
25
+ def album(uri, level=nil)
26
+ params = level == nil ? {} : { :extras => 'trackdetail' }
27
+ results = search(nil, params.merge(:uri => "spotify:album:#{uri}"))
28
+
29
+ case level
30
+ when :detailed
31
+ album = Resources::Lookup::AlbumDetailed.new(results['album'])
32
+ else
33
+ album = Resources::Lookup::AlbumBase.new(results['album'])
34
+ end
35
+ Resources::Base.new(results['info'], album)
36
+ end
37
+
38
+ def track(uri)
39
+ results = search(nil, :uri => "spotify:track:#{uri}")
40
+ track = Resources::Lookup::TrackBase.new(results['track'])
41
+ Resources::Base.new(results['info'], track)
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ module Spotify
5
+ module API
6
+ class Search < Spotify::API::Base
7
+
8
+ def initialize
9
+ @uri = "http://ws.spotify.com/search/1/"
10
+ end
11
+
12
+ def artists(query, params = {})
13
+ results = search('artist', params.merge(:q => query))
14
+ artists = results['artists'].map { |artist| Resources::Search::Artist.new(artist) }
15
+ Resources::Base.new(results['info'], artists)
16
+ end
17
+
18
+ def tracks(query, params = {})
19
+ results = search('track', params.merge(:q => query))
20
+ tracks = results['tracks'].map { |track| Resources::Search::Track.new(track) }
21
+ Resources::Base.new(results['info'], tracks)
22
+ end
23
+
24
+ def albums(query, params = {})
25
+ results = search('album', params.merge(:q => query))
26
+ albums = results['albums'].map { |album| Resources::Search::Album.new(album) }
27
+ Resources::Base.new(results['info'], albums)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ require 'spotify/api/base'
2
+ require 'spotify/api/lookup'
3
+ require 'spotify/api/search'
@@ -0,0 +1,18 @@
1
+ module Spotify
2
+
3
+ class Client
4
+
5
+ def initialize
6
+ end
7
+
8
+ def search
9
+ Spotify::API::Search.new
10
+ end
11
+
12
+ def lookup
13
+ Spotify::API::Lookup.new
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,16 @@
1
+ module Spotify
2
+ module Resources
3
+
4
+ class Base
5
+
6
+ attr_reader :info, :results
7
+
8
+ def initialize(info, results)
9
+ @info = Spotify::Resources::Info.new(info)
10
+ @results = results
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ module Spotify
2
+ module Resources
3
+
4
+ class Info
5
+
6
+ attr_reader :num_results, :limit, :offset, :query, :type, :page
7
+
8
+ def initialize(info)
9
+ @info = info
10
+ end
11
+
12
+ def num_results
13
+ @info['num_results']
14
+ end
15
+
16
+ def limit
17
+ @info['limit']
18
+ end
19
+
20
+ def offset
21
+ @info['offset']
22
+ end
23
+
24
+ def query
25
+ @info['query']
26
+ end
27
+
28
+ def type
29
+ @info['type']
30
+ end
31
+
32
+ def page
33
+ @info['page']
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ module Spotify
2
+ module Resources
3
+ module Lookup
4
+ class AlbumBase
5
+
6
+ def initialize(body)
7
+ @body = body
8
+ end
9
+
10
+ def artist_id
11
+ @body['artist-id']
12
+ end
13
+
14
+ def name
15
+ @body['name']
16
+ end
17
+
18
+ def artist
19
+ @body['artist']
20
+ end
21
+
22
+ def external_ids
23
+ @body['external-ids']
24
+ end
25
+
26
+ def released
27
+ @body['released']
28
+ end
29
+
30
+ def href
31
+ @body['href']
32
+ end
33
+
34
+ def availability
35
+ @body['availability']
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ module Spotify
2
+ module Resources
3
+ module Lookup
4
+ class AlbumDetails < Spotify::Resources::Lookup::AlbumBase
5
+
6
+ def initialize(body)
7
+ @body = body
8
+ end
9
+
10
+ def tracks
11
+ @body['tracks'].map { |track| Spotify::Resources::Lookup::TrackBase.new(track) }
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Spotify
2
+ module Resources
3
+ module Lookup
4
+ class ArtistBase
5
+
6
+ def initialize(body)
7
+ @body = body
8
+ end
9
+
10
+ def href
11
+ @body['href']
12
+ end
13
+
14
+ def name
15
+ @body['name']
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module Spotify
2
+ module Resources
3
+ module Lookup
4
+ class ArtistDetailed < Spotify::Resources::Lookup::ArtistBase
5
+
6
+ def initialize(body)
7
+ @body = body
8
+ end
9
+
10
+ def albums
11
+ @body['albums'].map { |album| Spotify::Resources::Lookup::AlbumBase.new(album['album']) }
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,50 @@
1
+ module Spotify
2
+ module Resources
3
+ module Lookup
4
+ class TrackBase
5
+
6
+ # http://ws.spotify.com/lookup/1/.json?uri=spotify:track:6NmXV4o6bmp704aPGyTVVG
7
+ # and
8
+ # http://ws.spotify.com/lookup/1/.json?uri=spotify:album:6G9fHYDCoyEErUkHrFYfs4&extras=trackdetail
9
+ #
10
+ # do not returning the same 'track' object - We're leaving out 'disc-number', 'available', and
11
+ # 'availability.'
12
+ #
13
+ # TODO - Redefine the architecture where the correct values can be returned.
14
+
15
+ def initialize(body)
16
+ @body = body
17
+ end
18
+
19
+ def track_number
20
+ @body['track-number']
21
+ end
22
+
23
+ def popularity
24
+ @body['popularity']
25
+ end
26
+
27
+ def external_ids
28
+ @body['external-ids']
29
+ end
30
+
31
+ def length
32
+ @body['length']
33
+ end
34
+
35
+ def href
36
+ @body['href']
37
+ end
38
+
39
+ def artists
40
+ @body['artists'].map { |artist| Spotify::Resources::Lookup::ArtistBase.new(artist) }
41
+ end
42
+
43
+ def name
44
+ @body['name']
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ module Spotify
2
+ module Resources
3
+ module Search
4
+
5
+ class Album
6
+
7
+ def initialize(body)
8
+ @body = body
9
+ end
10
+
11
+ def name
12
+ @body['name']
13
+ end
14
+
15
+ def popularity
16
+ @body['popularity']
17
+ end
18
+
19
+ def external_ids
20
+ @body['external-ids']
21
+ end
22
+
23
+ def href
24
+ @body['href']
25
+ end
26
+
27
+ def artists
28
+ # Has no popularity!
29
+ @body['artists'].map { |a| Spotify::Resources::Search::Artist.new(a)}
30
+ end
31
+
32
+ def availability
33
+ @body['availability']
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ module Spotify
2
+ module Resources
3
+ module Search
4
+
5
+ class Artist
6
+
7
+ def initialize(body)
8
+ @body = body
9
+ end
10
+
11
+ def href
12
+ @body['href']
13
+ end
14
+
15
+ def name
16
+ @body['name']
17
+ end
18
+
19
+ def popularity
20
+ @body['popularity']
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ module Spotify
2
+ module Resources
3
+ module Search
4
+
5
+ class Track
6
+
7
+ def initialize(body)
8
+ @body = body
9
+ end
10
+
11
+ def album
12
+ # Might want to default to lookup here.
13
+ # No released
14
+ Spotify::Resources::Search::Album.new(@body['album'])
15
+ end
16
+
17
+ def name
18
+ @body['name']
19
+ end
20
+
21
+ def popularity
22
+ @body['popularity']
23
+ end
24
+
25
+ def external_ids
26
+ # External ID resource?
27
+ @body['external-ids']
28
+ end
29
+
30
+ def length
31
+ @body['length']
32
+ end
33
+
34
+ def href
35
+ @body['href']
36
+ end
37
+
38
+ def artists
39
+ # Has href and name?
40
+ @body['artists'].map { |a| Spotify::Resources::Search::Artist.new(a)}
41
+ end
42
+
43
+ def trac_number
44
+ @body['trac-number']
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,12 @@
1
+ require 'spotify/resources/base'
2
+ require 'spotify/resources/info'
3
+
4
+ require 'spotify/resources/search/album'
5
+ require 'spotify/resources/search/artist'
6
+ require 'spotify/resources/search/track'
7
+
8
+ require 'spotify/resources/lookup/album/base'
9
+ require 'spotify/resources/lookup/album/details'
10
+ require 'spotify/resources/lookup/artist/base'
11
+ require 'spotify/resources/lookup/artist/details'
12
+ require 'spotify/resources/lookup/track/base'
data/lib/spotify.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'spotify/client'
2
+
3
+ require 'spotify/resources'
4
+ require 'spotify/api'
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spotify-search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - TJ Biddle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Spotify metadata API Wrapper.
14
+ email: biddle.thomas@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/spotify/api/base.rb
20
+ - lib/spotify/api/lookup.rb
21
+ - lib/spotify/api/search.rb
22
+ - lib/spotify/api.rb
23
+ - lib/spotify/client.rb
24
+ - lib/spotify/resources/base.rb
25
+ - lib/spotify/resources/info.rb
26
+ - lib/spotify/resources/lookup/album/base.rb
27
+ - lib/spotify/resources/lookup/album/details.rb
28
+ - lib/spotify/resources/lookup/artist/base.rb
29
+ - lib/spotify/resources/lookup/artist/details.rb
30
+ - lib/spotify/resources/lookup/track/base.rb
31
+ - lib/spotify/resources/search/album.rb
32
+ - lib/spotify/resources/search/artist.rb
33
+ - lib/spotify/resources/search/track.rb
34
+ - lib/spotify/resources.rb
35
+ - lib/spotify.rb
36
+ homepage: https://github.com/thomasbiddle/spotify-search
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.0.6
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Spotify metadata API Wrapper
59
+ test_files: []