spof 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 238ccae06d153bd5a1b3f834e6c3b6eede3c4924
4
+ data.tar.gz: 9847fcc1701a775e7a68eba37b03ee51041a29d1
5
+ SHA512:
6
+ metadata.gz: 9feaf4636b8a24b7fa250d6c75c821d9015c084a25b69de01b4109e05a92580623a5c42c5d001aa999ecd1d6034e8998668801bf3f64cdf5474e534ec9230293
7
+ data.tar.gz: 43f055869e46da51f0b16a9023d726d5cabd1d71aaa595f3b4867fb19f252cc532c125b7e24155744e9bbbdd7b0aa21ad58e072cf424f2d3d9803d5f21bc72c8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-19mode
7
+ - rbx-19mode
8
+
9
+ script: ruby test/basic.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spof.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Ignacio Contreras Pinilla
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ Sputnik
2
+ =======
3
+
4
+ Ruby wrapper for the Spotify Search & Lookup API. Under development.
5
+
6
+ [![Build Status](https://travis-ci.org/ignaciocontreras/sputnik.png?branch=master)](https://travis-ci.org/ignaciocontreras/sputnik)
7
+
8
+ License
9
+ -------
10
+
11
+ See LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Spof
2
+ VERSION = "0.0.1"
3
+ end
data/lib/spof.rb ADDED
@@ -0,0 +1,88 @@
1
+ require "spof/version"
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+
6
+ module Spof
7
+
8
+ @@testing = false
9
+
10
+ def self.config(options = {})
11
+ @@testing = options[:testing] || false
12
+ end
13
+
14
+ def self.testing?
15
+ @@testing
16
+ end
17
+
18
+ class SpofError < StandardError
19
+ end
20
+
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)
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)
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)
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
+ end
data/spof.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spof/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spof"
8
+ spec.version = Spof::VERSION
9
+ spec.authors = ["ignaciocontreras"]
10
+ spec.email = ["ignacio@ignacio.cat"]
11
+ spec.description = %q{Spotify Search & Lookup API Ruby wrapper}
12
+ spec.summary = %q{Spotify Search & Lookup}
13
+ spec.homepage = "http://github.com/ignaciocontreras/spof"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
data/test/basic.rb ADDED
@@ -0,0 +1,117 @@
1
+ require_relative '../lib/spof'
2
+ require 'test/unit'
3
+
4
+
5
+ class TestBasic < Test::Unit::TestCase
6
+
7
+ def setup
8
+ Spof.config({
9
+ :testing => true
10
+ })
11
+ end
12
+
13
+ def test_search_album_request_ok
14
+ expected = 'http://ws.spotify.com/search/1/album.json?q=nine+inch+nails&page=1'
15
+ actual = Spof::Search.album('nine inch nails')
16
+ assert_equal expected, actual
17
+ end
18
+
19
+ def test_search_artist_request_ok
20
+ expected = 'http://ws.spotify.com/search/1/artist.json?q=david+bowie&page=1'
21
+ actual = Spof::Search.artist('david bowie')
22
+ assert_equal expected, actual
23
+ end
24
+
25
+ def test_search_track_request_ok
26
+ expected = 'http://ws.spotify.com/search/1/track.json?q=life+on+mars&page=1'
27
+ actual = Spof::Search.track('life on mars')
28
+ assert_equal expected, actual
29
+ end
30
+
31
+ def test_lookup_get_album_request_ok
32
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:album:40pUoRK9pOn3tMoXY02fUB'
33
+ real = Spof::Lookup.get('spotify:album:40pUoRK9pOn3tMoXY02fUB')
34
+ assert expected, real
35
+ end
36
+
37
+ def test_lookup_get_artist_request_ok
38
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy'
39
+ real = Spof::Lookup.get('spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy')
40
+ assert expected, real
41
+ end
42
+
43
+ def test_lookup_get_track_request_ok
44
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:track:2Z9vxEQVzEdj5Ph9JLUzDo'
45
+ real = Spof::Lookup.get('spotify:track:2Z9vxEQVzEdj5Ph9JLUzDo')
46
+ assert expected, real
47
+ end
48
+
49
+ def test_lookup_album_request_no_extras_ok
50
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:album:40pUoRK9pOn3tMoXY02fUB'
51
+ real = Spof::Lookup.album('spotify:album:40pUoRK9pOn3tMoXY02fUB')
52
+ assert expected, real
53
+ end
54
+
55
+ def test_lookup_artist_request_no_extras_ok
56
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy'
57
+ real = Spof::Lookup.artist('spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy')
58
+ assert expected, real
59
+ end
60
+
61
+ def test_lookup_track_request_no_extras_ok
62
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:track:2Z9vxEQVzEdj5Ph9JLUzDo'
63
+ real = Spof::Lookup.track('spotify:track:2Z9vxEQVzEdj5Ph9JLUzDo')
64
+ assert expected, real
65
+ end
66
+
67
+ def test_lookup_album_request_track_extra_ok
68
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:album:40pUoRK9pOn3tMoXY02fUB&extras=track'
69
+ real = Spof::Lookup.album('spotify:album:40pUoRK9pOn3tMoXY02fUB', :track)
70
+ assert expected, real
71
+ end
72
+
73
+ def test_lookup_album_request_trackdetail_extra_ok
74
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:album:40pUoRK9pOn3tMoXY02fUB&extras=trackdetail'
75
+ real = Spof::Lookup.album('spotify:album:40pUoRK9pOn3tMoXY02fUB', :trackdetail)
76
+ assert expected, real
77
+ end
78
+
79
+ def test_lookup_artist_request_album_extra_ok
80
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy&extras=album'
81
+ real = Spof::Lookup.artist('spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy', :album)
82
+ assert expected, real
83
+ end
84
+
85
+ def test_lookup_artist_request_albumdetail_extra_ok
86
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy&extras=albumdetail'
87
+ real = Spof::Lookup.artist('spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy', :albumdetail)
88
+ assert expected, real
89
+ end
90
+
91
+ def test_lookup_album_request_both_extras_ok
92
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:album:40pUoRK9pOn3tMoXY02fUB&extras=track,trackdetail'
93
+ real = Spof::Lookup.album('spotify:album:40pUoRK9pOn3tMoXY02fUB', :track, :trackdetail)
94
+ assert expected, real
95
+ end
96
+
97
+ def test_lookup_artist_request_both_extras_ok
98
+ expected = 'http://ws.spotify.com/lookup/1/?uri=spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy&extras=album,albumdetail'
99
+ real = Spof::Lookup.artist('spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy', :album, :albumdetail)
100
+ assert expected, real
101
+ end
102
+
103
+ def test_lookup_album_illegal_extra_error
104
+
105
+ assert_raise (Spof::SpofError) {
106
+ Spof::Lookup.album('spotify:album:40pUoRK9pOn3tMoXY02fUB', :track, :illegal)
107
+ }
108
+
109
+ end
110
+
111
+ def test_lookup_artist_illegal_extra_error
112
+ assert_raise (Spof::SpofError) {
113
+ Spof::Lookup.artist('spotify:artist:0oSGxfWSnnOXhD2fKuz2Gy', :album, :illegal)
114
+ }
115
+ end
116
+
117
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spof
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ignaciocontreras
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Spotify Search & Lookup API Ruby wrapper
42
+ email:
43
+ - ignacio@ignacio.cat
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - lib/spof.rb
55
+ - lib/spof/version.rb
56
+ - spof.gemspec
57
+ - test/basic.rb
58
+ homepage: http://github.com/ignaciocontreras/spof
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Spotify Search & Lookup
82
+ test_files:
83
+ - test/basic.rb