spof 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/lookup.rb +38 -0
- data/lib/search.rb +34 -0
- data/lib/spof/version.rb +1 -1
- data/lib/spof.rb +5 -69
- data/lib/wrapper.rb +38 -0
- data/test/{basic.rb → test_search_and_lookup.rb} +1 -1
- data/test/test_wrapper.rb +22 -0
- data/test/test_wrapper_basic_search.rb +28 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e67eb54727921db21214c372c07994b195a3d79c
|
4
|
+
data.tar.gz: d7c6afe3ce115e661447a740c44d3559802ee16e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 046d4636494ddffb0bde59767f3703fdf16c596de48ba4c121b1cb063e2ef1a80920834b9c62e39cca9e71dfa0c0cafe42b8cf699eb4253f8840a00b12541d8a
|
7
|
+
data.tar.gz: 1647b7fd105c2be5812c103a7c865f67c059083e913c24d1f54a0d0cd1edff558912ba7e5f31cdf0656df55138da6bc83aab21b0eadce457e53d86677c54b412
|
data/lib/lookup.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Spof
|
2
|
+
|
3
|
+
module Lookup
|
4
|
+
|
5
|
+
def self.album(spotify_uri, *extras)
|
6
|
+
legal_extras = [:track, :trackdetail]
|
7
|
+
extras.each do |e|
|
8
|
+
raise SpofError, "Illegal extra" if not legal_extras.include?(e)
|
9
|
+
end
|
10
|
+
return get(spotify_uri, *extras)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.artist(spotify_uri, *extras)
|
14
|
+
legal_extras = [:album, :albumdetail]
|
15
|
+
extras.each do |e|
|
16
|
+
raise SpofError, "Illegal extra" if not legal_extras.include?(e)
|
17
|
+
end
|
18
|
+
return get(spotify_uri, *extras)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.track(spotify_uri)
|
22
|
+
return get(spotify_uri)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get(spotify_uri, *extras)
|
26
|
+
uri = URI('http://ws.spotify.com/lookup/1/.json')
|
27
|
+
uri.query = URI.encode_www_form({
|
28
|
+
:uri => spotify_uri,
|
29
|
+
:extras => extras
|
30
|
+
})
|
31
|
+
response = Net::HTTP.get(uri)
|
32
|
+
return uri.to_s if Spof.testing?
|
33
|
+
return JSON.parse(response, :symbolize_names => true)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/search.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Spof
|
2
|
+
|
3
|
+
module Search
|
4
|
+
|
5
|
+
def self.album(text, page = 1)
|
6
|
+
url = 'http://ws.spotify.com/search/1/album.json'
|
7
|
+
return get_response(url, text, page)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.artist(text, page = 1)
|
11
|
+
url = 'http://ws.spotify.com/search/1/artist.json'
|
12
|
+
return get_response(url, text, page)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.track(text, page = 1)
|
16
|
+
url = 'http://ws.spotify.com/search/1/track.json'
|
17
|
+
return get_response(url, text, page)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def self.get_response(url, text, page = 1)
|
22
|
+
uri = URI(url)
|
23
|
+
uri.query = URI.encode_www_form({
|
24
|
+
:q => text,
|
25
|
+
:page => page
|
26
|
+
})
|
27
|
+
return uri.to_s if Spof.testing?
|
28
|
+
response = Net::HTTP.get(uri)
|
29
|
+
return JSON.parse(response, :symbolize_names => true)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/spof/version.rb
CHANGED
data/lib/spof.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require "spof/version"
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "search"
|
3
|
+
require "lookup"
|
4
|
+
require "wrapper"
|
4
5
|
|
6
|
+
require "net/http"
|
7
|
+
require "json"
|
5
8
|
|
6
9
|
module Spof
|
7
10
|
|
@@ -18,71 +21,4 @@ module Spof
|
|
18
21
|
class SpofError < StandardError
|
19
22
|
end
|
20
23
|
|
21
|
-
|
22
|
-
module Search
|
23
|
-
|
24
|
-
def self.album(text, page = 1)
|
25
|
-
url = 'http://ws.spotify.com/search/1/album.json'
|
26
|
-
return get_response(url, text, page)
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.artist(text, page = 1)
|
30
|
-
url = 'http://ws.spotify.com/search/1/artist.json'
|
31
|
-
return get_response(url, text, page)
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.track(text, page = 1)
|
35
|
-
url = 'http://ws.spotify.com/search/1/track.json'
|
36
|
-
return get_response(url, text, page)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def self.get_response(url, text, page = 1)
|
41
|
-
uri = URI(url)
|
42
|
-
uri.query = URI.encode_www_form({
|
43
|
-
:q => text,
|
44
|
-
:page => page
|
45
|
-
})
|
46
|
-
return uri.to_s if Spof.testing?
|
47
|
-
response = Net::HTTP.get(uri)
|
48
|
-
return JSON.parse(response, :symbolize_names => true)
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
module Lookup
|
54
|
-
|
55
|
-
def self.album(spotify_uri, *extras)
|
56
|
-
legal_extras = [:track, :trackdetail]
|
57
|
-
extras.each do |e|
|
58
|
-
raise SpofError, "Illegal extra" if not legal_extras.include?(e)
|
59
|
-
end
|
60
|
-
return get(spotify_uri, *extras)
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.artist(spotify_uri, *extras)
|
64
|
-
legal_extras = [:album, :albumdetail]
|
65
|
-
extras.each do |e|
|
66
|
-
raise SpofError, "Illegal extra" if not legal_extras.include?(e)
|
67
|
-
end
|
68
|
-
return get(spotify_uri, *extras)
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.track(spotify_uri)
|
72
|
-
return get(spotify_uri)
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.get(spotify_uri, *extras)
|
76
|
-
uri = URI('http://ws.spotify.com/lookup/1/.json')
|
77
|
-
uri.query = URI.encode_www_form({
|
78
|
-
:uri => spotify_uri,
|
79
|
-
:extras => extras
|
80
|
-
})
|
81
|
-
response = Net::HTTP.get(uri)
|
82
|
-
return uri.to_s if Spof.testing?
|
83
|
-
return JSON.parse(response, :symbolize_names => true)
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
24
|
end
|
data/lib/wrapper.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "search"
|
2
|
+
require "lookup"
|
3
|
+
|
4
|
+
module Spof
|
5
|
+
|
6
|
+
class Wrapper
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@type = nil
|
10
|
+
Spof.config(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def album
|
14
|
+
@type = :album
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def artist
|
19
|
+
@type = :artist
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def track
|
24
|
+
@type = :track
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def search(text)
|
29
|
+
if [:album, :artist, :track].include?(@type)
|
30
|
+
Spof::Search.send(@type, text)
|
31
|
+
else
|
32
|
+
raise Spof::SpofError, "Invalid search type"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spof'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
|
5
|
+
class TestWrapper < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Spof.config({
|
9
|
+
:testing => true
|
10
|
+
})
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_helper_methods_return_self
|
14
|
+
assert_nothing_thrown do
|
15
|
+
w = Spof::Wrapper.new
|
16
|
+
w.album.artist.track
|
17
|
+
w.artist.track.album
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spof'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestBasicWrapper < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@w = Spof::Wrapper.new :testing => true
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_search_album_request
|
11
|
+
expected = Spof::Search.album('space oddity')
|
12
|
+
real = @w.album.search('space oddity')
|
13
|
+
assert_equal expected, real
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_search_artist_request
|
17
|
+
expected = Spof::Search.artist('david bowie')
|
18
|
+
real = @w.artist.search('david bowie')
|
19
|
+
assert_equal expected, real
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_search_track_request
|
23
|
+
expected = Spof::Search.track('life on mars')
|
24
|
+
real = @w.track.search('life on mars')
|
25
|
+
assert_equal expected, real
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Contreras
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -51,10 +51,15 @@ files:
|
|
51
51
|
- LICENSE
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
|
+
- lib/lookup.rb
|
55
|
+
- lib/search.rb
|
54
56
|
- lib/spof.rb
|
55
57
|
- lib/spof/version.rb
|
58
|
+
- lib/wrapper.rb
|
56
59
|
- spof.gemspec
|
57
|
-
- test/
|
60
|
+
- test/test_search_and_lookup.rb
|
61
|
+
- test/test_wrapper.rb
|
62
|
+
- test/test_wrapper_basic_search.rb
|
58
63
|
homepage: http://github.com/ignaciocontreras/spof
|
59
64
|
licenses:
|
60
65
|
- MIT
|
@@ -80,4 +85,6 @@ signing_key:
|
|
80
85
|
specification_version: 4
|
81
86
|
summary: Spotify Search & Lookup
|
82
87
|
test_files:
|
83
|
-
- test/
|
88
|
+
- test/test_search_and_lookup.rb
|
89
|
+
- test/test_wrapper.rb
|
90
|
+
- test/test_wrapper_basic_search.rb
|