spot 0.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/song_spec.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "spec_helper"
2
2
  require "./lib/spot/song"
3
3
 
4
- describe SpotContainer::Song do
4
+ describe Spot::Song do
5
5
  before(:each) do
6
- @song = SpotContainer::Song.new(JSON.load(File.read("spec/fixtures/track.json"))["tracks"].first)
6
+ @song = Spot::Song.new(JSON.load(File.read("spec/fixtures/track.json"))["tracks"].first)
7
7
  end
8
8
 
9
9
  context "the available? method" do
@@ -17,11 +17,11 @@ describe SpotContainer::Song do
17
17
  end
18
18
 
19
19
  it "should have an artist" do
20
- @song.artist.should be_instance_of(SpotContainer::Artist)
20
+ @song.artist.should be_instance_of(Spot::Artist)
21
21
  end
22
22
 
23
23
  it "should have an album" do
24
- @song.album.should be_instance_of(SpotContainer::Album)
24
+ @song.album.should be_instance_of(Spot::Album)
25
25
  end
26
26
 
27
27
  it "should have the correct accessors" do
@@ -45,7 +45,7 @@ describe SpotContainer::Song do
45
45
  end
46
46
 
47
47
  it "should inherit from base" do
48
- @song.class.ancestors.should include(SpotContainer::Base)
48
+ @song.class.ancestors.should include(Spot::Base)
49
49
  end
50
50
 
51
51
  it "should have a title method that equals the name method" do
@@ -53,16 +53,6 @@ describe SpotContainer::Song do
53
53
  end
54
54
 
55
55
  it "should have a working to string method" do
56
- @song.to_s.should eq("#{@song.title} - #{@song.artist.name}")
57
- end
58
-
59
- context "user requst" do
60
- before(:all) do
61
- WebMock.allow_net_connect!
62
- end
63
-
64
- it "should match user request" do
65
- Spot.territory("SE").prime.strip.find_song("Call My Name - Tove Styrke").result.to_s.should eq("Call My Name - Tove Styrke")
66
- end
67
- end
56
+ @song.to_s.should eq("#{@song.artist.name} - #{@song.title}")
57
+ end
68
58
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,20 @@
1
1
  require "rspec"
2
- require "webmock/rspec"
3
2
  require "spot"
3
+ require "vcr"
4
+ require "webmock/rspec"
4
5
 
5
6
  RSpec.configure do |config|
6
7
  config.mock_with :rspec
8
+ config.extend VCR::RSpec::Macros
9
+ end
10
+
11
+ VCR.configure do |c|
12
+ c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
13
+ c.hook_into :webmock
14
+ c.default_cassette_options = {
15
+ :record => :new_episodes
16
+ }
17
+ c.allow_http_connections_when_no_cassette = false
7
18
  end
8
19
 
9
20
  def mock_media(ret)
@@ -19,17 +30,10 @@ def validate_artists(artists)
19
30
  end
20
31
  end
21
32
 
22
- def set_up(times = 100, ret = true, klass = SpotContainer::Song)
33
+ def set_up(times = 100, ret = true, klass = Spot::Song)
23
34
  klass.should_receive(:new).exactly(times).times.and_return(mock_media(ret))
24
35
  end
25
36
 
26
37
  def generate_url(type, search, page = 1)
27
38
  "http://ws.spotify.com/search/1/#{type}.json?q=#{URI.escape(search)}&page=#{page}"
28
- end
29
-
30
- def stubs(type, search, page = 1)
31
- url = generate_url(type, search, page)
32
- stub_request(:get, url).
33
- to_return(:body => File.read("spec/fixtures/#{type}.json"), :status => 200)
34
- url
35
39
  end
data/spec/spot_spec.rb ADDED
@@ -0,0 +1,221 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ describe Spot::Search do
4
+ use_vcr_cassette "spotify"
5
+
6
+ before(:each) do
7
+ @spot = Spot::Search.new
8
+ end
9
+
10
+ context "tracks if success" do
11
+ it "should contain the right amounts of songs" do
12
+ Spot::Search.find_all_songs("kaizers orchestra").should have(100).results
13
+ end
14
+
15
+ it "should call Spot::Song with the right arguments" do
16
+ Spot::Song.should_receive(:new) do |args|
17
+ args["album"]["released"].should match(/^\d{4}$/)
18
+ args["album"]["href"].should match(/^spotify\:album\:[a-zA-Z0-9]+$/)
19
+ args["album"]["name"].should_not be_empty
20
+ args["album"]["availability"]["territories"].should match(/[A-Z]{2}|(worldwide)/)
21
+
22
+ args["name"].should_not be_empty
23
+ args["popularity"].should match(/[0-9\.]+/)
24
+ args["length"].should be_instance_of(Float)
25
+ args["href"].should match(/^spotify\:track\:[a-zA-Z0-9]+$/)
26
+
27
+ validate_artists(args["artists"])
28
+
29
+ mock_media(true)
30
+ end.exactly(100).times
31
+
32
+ Spot::Search.find_all_songs("kaizers orchestra").results
33
+ end
34
+
35
+ it "should not have any songs" do
36
+ Spot::Search.find_all_songs("d41d8cd98f00b204e9800998ecf8427e").results.should be_empty
37
+ end
38
+ end
39
+
40
+ context "artists if success" do
41
+ after(:each) do
42
+ a_request(:get, @url).should have_been_made.once
43
+ end
44
+
45
+ before(:each) do
46
+ @url = generate_url("artist", "kaizers orchestra")
47
+ end
48
+
49
+ it "should contain the right amounts of artists" do
50
+ Spot::Search.find_all_artists("kaizers orchestra").results.should have(1).results
51
+ end
52
+
53
+ it "should call Spot::Artist with the right arguments" do
54
+ Spot::Artist.should_receive(:new) do |args|
55
+ args["name"].should_not be_empty
56
+ args["popularity"].should match(/[0-9\.]+/)
57
+ args["href"].should match(/^spotify\:artist\:[a-zA-Z0-9]+$/)
58
+ mock_media(true)
59
+ end.exactly(1).times
60
+
61
+ Spot::Search.find_all_artists("kaizers orchestra").results
62
+ end
63
+
64
+ it "should be able to cache a request" do
65
+ set_up(1, true, Spot::Artist)
66
+ spot = Spot::Search.find_all_artists("kaizers orchestra")
67
+ 10.times { spot.results }
68
+ end
69
+
70
+ it "should not have any songs if nothing is valid" do
71
+ set_up(1, false, Spot::Artist)
72
+ Spot::Search.find_all_artists("kaizers orchestra").results.should be_empty
73
+ end
74
+ end
75
+
76
+ context "album if success" do
77
+ it "should contain the right amounts of albums" do
78
+ Spot::Search.find_all_albums("kaizers orchestra").should have(55).results
79
+ end
80
+
81
+ it "should call Spot::Album with the right arguments" do
82
+ Spot::Album.should_receive(:new) do |args|
83
+ validate_artists(args["artists"])
84
+
85
+ args["href"].should match(/^spotify\:album\:[a-zA-Z0-9]+$/)
86
+
87
+ args["availability"]["territories"].should match(/[A-Z]{2}|(worldwide)/)
88
+ args["name"].should_not be_empty
89
+ args["popularity"].should match(/[0-9\.]+/)
90
+ mock_media(true)
91
+ end.exactly(55).times
92
+
93
+ Spot::Search.find_all_albums("kaizers orchestra").results
94
+ end
95
+
96
+ it "should be possible to specify a territories" do
97
+ Spot::Search.territory("RANDOM").find_all_albums("kaizers orchestra").results.should be_empty
98
+ end
99
+ end
100
+
101
+ context "find_*" do
102
+ it "should only return one element" do
103
+ Spot::Search.find_song("kaizers orchestra").result.should be_instance_of(Spot::Song)
104
+ end
105
+ end
106
+
107
+ it "should be possible to set a page variable" do
108
+ url = generate_url("track", "kaizers orchestra", 11)
109
+ Spot::Search.page(11).find_song("kaizers orchestra").result
110
+ a_request(:get, url).should have_been_made.once
111
+ end
112
+
113
+ context "the prime method" do
114
+ it "should return the best match" do
115
+ Spot::Search.prime.find_song("kaizers orchestra").result.artist.name.should eq("Kaizers Orchestra")
116
+ end
117
+ end
118
+
119
+ context "method does not exist" do
120
+ it "should raise no method error if the method does't exist (plain value)" do
121
+ lambda { Spot::Search.find_song("string").random_method }.should raise_error(NoMethodError)
122
+ end
123
+
124
+ it "should raise an error if the method matches find_*_*" do
125
+ lambda { Spot::Search.find_song("string").find_by_song }.should raise_error(NoMethodError)
126
+ end
127
+
128
+ it "should raise an error if the method matches find_all_* " do
129
+ lambda { Spot::Search.find_song("string").find_all_random }.should raise_error(NoMethodError)
130
+ end
131
+ end
132
+
133
+ context "exclude" do
134
+ it "should have a working exclude? method" do
135
+ {
136
+ "tribute" => true,
137
+ "cover random" => true,
138
+ "live" => true,
139
+ "club mix random" => true,
140
+ "LIVE" => true,
141
+ "karaoKE" => true,
142
+ "instrumental" => true,
143
+ "Karaoke - Won't Get Fooled Again" => true,
144
+ "club version" => true,
145
+ "instrumentals" => true,
146
+ "demo" => true,
147
+ "made famous by" => true,
148
+ "remixes" => true,
149
+ "ringtone" => true,
150
+ "ringtones" => true,
151
+ "riingtonerandom" => false,
152
+ "club random mix" => false,
153
+ "random" => false,
154
+ "oliver" => false
155
+ }.each do |comp, outcome|
156
+ @spot.exclude?(comp).should eq(outcome)
157
+ end
158
+ end
159
+ end
160
+
161
+ context "territory" do
162
+ it "should not find any songs when using a non valid territory" do
163
+ @spot.territory("RANDOM").find_all_songs("search").results.should be_empty
164
+ end
165
+
166
+ it "should find some songs when using a valid territory" do
167
+ @spot.territory("SE").find_all_songs("search").results.should_not be_empty
168
+ end
169
+
170
+ it "should be ignored if nil" do
171
+ @spot.territory(nil).find_all_songs("search").results.count.should eq(@spot.find_all_songs("search").results.count)
172
+ end
173
+ end
174
+
175
+ context "the info values" do
176
+ after(:each) do
177
+ a_request(:get, @url).should have_been_made.once
178
+ end
179
+
180
+ it "should have some info" do
181
+ @url = generate_url("track", "kaizers orchestra")
182
+ spot = Spot::Search.strip.find_song("kaizers orchestra")
183
+ spot.num_results.should be > 0
184
+ spot.limit.should eq(100)
185
+ spot.offset.should eq(0)
186
+ spot.query.should eq("kaizers orchestra")
187
+ end
188
+ end
189
+
190
+ context "bugs" do
191
+ it "handles 'Jason Derulo - Undefeated'" do
192
+ Spot::Search.strip.find_song("Jason Derulo - Undefeated").result.to_s.should eq("Jason Derulo - Undefeated")
193
+ end
194
+
195
+ it "handles 'Call My Name - Tove Styrke'" do
196
+ Spot::Search.territory("SE").prime.strip.find_song("Tove Styrke - Call My Name").result.to_s.should eq("Tove Styrke - Call My Name")
197
+ end
198
+
199
+ it "handles 'D'Banj - Oliver Twist'" do
200
+ Spot::Search.territory("SE").prime.strip.find_song("D'Banj - Oliver Twist").result.to_s.downcase.should eq("D'Banj - Oliver Twist".downcase)
201
+ end
202
+
203
+ it "should handle 'Iron Maiden - Can I Play With Madness'" do
204
+ song = Spot::Search.territory("SE").prime.strip.find_song("Iron Maiden - Can I Play With Madness").result
205
+ song.artist.name.should eq("Iron Maiden")
206
+ song.title.should match(%r{Can I Play With Madness})
207
+ end
208
+
209
+ it "should handle 'Smooth - Undercover Lover'" do
210
+ Spot::Search.territory("SE").strip.prime.find_song("Smooth - Undercover Lover").result.to_s.should eq("Smooth - Undercover Lover")
211
+ end
212
+
213
+ it "should handle 'Basto! - Live Tonight (Gregory's Theme) (extended mix)'" do
214
+ Spot::Search.territory("SE").strip.prime.find_song("Basto! - Live Tonight (Gregory's Theme) (extended mix)").result.to_s.should eq("Basto - Live Tonight (Gregory's Theme) - Radio Edit")
215
+ end
216
+
217
+ it "should handle 'Wtf! - Da Bop'" do
218
+ Spot::Search.territory("SE").strip.prime.find_song("Wtf! - Da Bop").result.to_s.should eq("WTF! - Da Bop - Video Edit")
219
+ end
220
+ end
221
+ end
data/spot.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "spot"
6
- s.version = "0.1.4"
6
+ s.version = "2.0.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Linus Oleander"]
9
9
  s.email = ["linus@oleander.nu"]
@@ -22,8 +22,9 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency("rest-client")
23
23
  s.add_dependency("abstract")
24
24
  s.add_dependency("levenshteinish")
25
- s.add_dependency("rchardet19")
25
+ s.add_dependency("charlock_holmes")
26
26
 
27
27
  s.add_development_dependency("rspec")
28
- s.add_development_dependency("webmock")
28
+ s.add_development_dependency("vcr")
29
+ s.add_development_dependency("webmock", "~> 1.8.0")
29
30
  end
metadata CHANGED
@@ -1,105 +1,111 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: spot
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
4
5
  prerelease:
5
- version: 0.1.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Linus Oleander
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-05 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-06-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: json_pure
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70199036450180 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rest-client
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70199036450180
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ requirement: &70199036449740 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: abstract
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70199036449740
36
+ - !ruby/object:Gem::Dependency
37
+ name: abstract
38
+ requirement: &70199036449320 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
46
44
  type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: levenshteinish
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70199036449320
47
+ - !ruby/object:Gem::Dependency
48
+ name: levenshteinish
49
+ requirement: &70199036448900 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
57
55
  type: :runtime
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: rchardet19
61
56
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70199036448900
58
+ - !ruby/object:Gem::Dependency
59
+ name: charlock_holmes
60
+ requirement: &70199031942860 !ruby/object:Gem::Requirement
63
61
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
68
66
  type: :runtime
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
67
+ prerelease: false
68
+ version_requirements: *70199031942860
69
+ - !ruby/object:Gem::Dependency
71
70
  name: rspec
71
+ requirement: &70199031942440 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
72
78
  prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
79
+ version_requirements: *70199031942440
80
+ - !ruby/object:Gem::Dependency
81
+ name: vcr
82
+ requirement: &70199031942020 !ruby/object:Gem::Requirement
74
83
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
79
88
  type: :development
80
- version_requirements: *id006
81
- - !ruby/object:Gem::Dependency
82
- name: webmock
83
89
  prerelease: false
84
- requirement: &id007 !ruby/object:Gem::Requirement
90
+ version_requirements: *70199031942020
91
+ - !ruby/object:Gem::Dependency
92
+ name: webmock
93
+ requirement: &70199031941520 !ruby/object:Gem::Requirement
85
94
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: "0"
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.8.0
90
99
  type: :development
91
- version_requirements: *id007
100
+ prerelease: false
101
+ version_requirements: *70199031941520
92
102
  description: A Ruby implementation of the Spotify Meta API.
93
- email:
103
+ email:
94
104
  - linus@oleander.nu
95
105
  executables: []
96
-
97
106
  extensions: []
98
-
99
107
  extra_rdoc_files: []
100
-
101
- files:
102
- - .DS_Store
108
+ files:
103
109
  - .gitignore
104
110
  - .rspec
105
111
  - Gemfile
@@ -109,54 +115,57 @@ files:
109
115
  - lib/spot/album.rb
110
116
  - lib/spot/artist.rb
111
117
  - lib/spot/base.rb
118
+ - lib/spot/clean.rb
112
119
  - lib/spot/exclude.yml
120
+ - lib/spot/ignore.yml
113
121
  - lib/spot/song.rb
114
122
  - spec/album_spec.rb
115
123
  - spec/artist_spec.rb
116
124
  - spec/base_spec.rb
125
+ - spec/clean_spec.rb
117
126
  - spec/fixtures/album.json
118
127
  - spec/fixtures/artist.json
119
128
  - spec/fixtures/exclude.tribute.json
120
129
  - spec/fixtures/track.json
130
+ - spec/fixtures/vcr_cassettes/spotify.yml
121
131
  - spec/song_spec.rb
122
132
  - spec/spec_helper.rb
123
- - spec/spotify_spec.rb
133
+ - spec/spot_spec.rb
124
134
  - spot.gemspec
125
135
  homepage: https://github.com/oleander/Spot
126
136
  licenses: []
127
-
128
137
  post_install_message:
129
138
  rdoc_options: []
130
-
131
- require_paths:
139
+ require_paths:
132
140
  - lib
133
- required_ruby_version: !ruby/object:Gem::Requirement
141
+ required_ruby_version: !ruby/object:Gem::Requirement
134
142
  none: false
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: "0"
139
- required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
148
  none: false
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: "0"
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
145
153
  requirements: []
146
-
147
154
  rubyforge_project: spot
148
- rubygems_version: 1.8.8
155
+ rubygems_version: 1.8.15
149
156
  signing_key:
150
157
  specification_version: 3
151
158
  summary: A Ruby implementation of the Spotify Meta API
152
- test_files:
159
+ test_files:
153
160
  - spec/album_spec.rb
154
161
  - spec/artist_spec.rb
155
162
  - spec/base_spec.rb
163
+ - spec/clean_spec.rb
156
164
  - spec/fixtures/album.json
157
165
  - spec/fixtures/artist.json
158
166
  - spec/fixtures/exclude.tribute.json
159
167
  - spec/fixtures/track.json
168
+ - spec/fixtures/vcr_cassettes/spotify.yml
160
169
  - spec/song_spec.rb
161
170
  - spec/spec_helper.rb
162
- - spec/spotify_spec.rb
171
+ - spec/spot_spec.rb