hallon 0.12.0 → 0.13.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/CHANGELOG.md +43 -0
- data/Gemfile +3 -1
- data/README.markdown +41 -11
- data/Rakefile +12 -0
- data/examples/audio_driver.rb +55 -0
- data/examples/playing_audio.rb +10 -50
- data/hallon.gemspec +1 -1
- data/lib/hallon.rb +1 -1
- data/lib/hallon/album_browse.rb +22 -11
- data/lib/hallon/artist_browse.rb +64 -33
- data/lib/hallon/audio_driver.rb +138 -0
- data/lib/hallon/audio_queue.rb +110 -0
- data/lib/hallon/enumerator.rb +55 -16
- data/lib/hallon/error.rb +9 -2
- data/lib/hallon/image.rb +6 -5
- data/lib/hallon/link.rb +7 -4
- data/lib/hallon/linkable.rb +27 -0
- data/lib/hallon/observable/player.rb +18 -1
- data/lib/hallon/observable/session.rb +5 -1
- data/lib/hallon/player.rb +180 -54
- data/lib/hallon/playlist.rb +33 -20
- data/lib/hallon/playlist_container.rb +78 -64
- data/lib/hallon/search.rb +51 -33
- data/lib/hallon/session.rb +1 -1
- data/lib/hallon/toplist.rb +36 -18
- data/lib/hallon/track.rb +12 -6
- data/lib/hallon/version.rb +1 -1
- data/spec/hallon/artist_browse_spec.rb +3 -4
- data/spec/hallon/audio_queue_spec.rb +89 -0
- data/spec/hallon/enumerator_spec.rb +50 -25
- data/spec/hallon/error_spec.rb +2 -2
- data/spec/hallon/image_spec.rb +12 -5
- data/spec/hallon/link_spec.rb +8 -9
- data/spec/hallon/linkable_spec.rb +11 -0
- data/spec/hallon/observable/session_spec.rb +4 -0
- data/spec/hallon/player_spec.rb +118 -5
- data/spec/hallon/playlist_container_spec.rb +2 -2
- data/spec/hallon/playlist_spec.rb +32 -37
- data/spec/hallon/search_spec.rb +3 -3
- data/spec/hallon/user_spec.rb +0 -6
- data/spec/spec_helper.rb +10 -0
- data/spec/support/audio_driver_mock.rb +23 -0
- data/spec/support/context_stub_session.rb +5 -0
- data/spec/support/shared_for_linkable_objects.rb +22 -2
- metadata +26 -20
- data/lib/hallon/queue.rb +0 -71
- data/spec/hallon/queue_spec.rb +0 -35
@@ -0,0 +1,23 @@
|
|
1
|
+
class AudioDriverMock
|
2
|
+
attr_reader :state
|
3
|
+
|
4
|
+
# Expected implementation:
|
5
|
+
attr_accessor :format
|
6
|
+
|
7
|
+
def stream(&block)
|
8
|
+
@stream = block if block_given?
|
9
|
+
@stream
|
10
|
+
end
|
11
|
+
|
12
|
+
def play
|
13
|
+
@state = :play
|
14
|
+
end
|
15
|
+
|
16
|
+
def pause
|
17
|
+
@state = :pause
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop
|
21
|
+
@state = :stop
|
22
|
+
end
|
23
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
shared_examples_for "a Linkable object" do
|
3
|
+
subject { described_class.new(spotify_uri) }
|
4
|
+
|
3
5
|
describe "instantiation" do
|
4
6
|
let(:spotify_pointer) do
|
5
7
|
ptr_type = Hallon::Link.new(spotify_uri).type
|
@@ -30,10 +32,28 @@ shared_examples_for "a Linkable object" do
|
|
30
32
|
end
|
31
33
|
|
32
34
|
describe "#to_link" do
|
33
|
-
subject { described_class.new(spotify_uri) }
|
34
|
-
|
35
35
|
it "should return a valid link" do
|
36
36
|
subject.to_link.should eq Hallon::Link.new(spotify_uri)
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
describe "#to_str" do
|
41
|
+
it "should return the spotify URI for this object" do
|
42
|
+
subject.to_str.should eq spotify_uri
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return an empty string if #to_link fails" do
|
46
|
+
subject.should_receive(:to_link).and_return(nil)
|
47
|
+
subject.to_str.should eq ""
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#===" do
|
52
|
+
it "should compare the objects by their links if both are Linkable" do
|
53
|
+
mock = double
|
54
|
+
mock.stub(:to_link).and_return(subject.to_link)
|
55
|
+
|
56
|
+
(subject === mock).should be_true
|
57
|
+
end
|
58
|
+
end
|
39
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hallon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.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:
|
12
|
+
date: 2012-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ref
|
16
|
-
requirement: &
|
16
|
+
requirement: &70259239927580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70259239927580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: spotify
|
27
|
-
requirement: &
|
27
|
+
requirement: &70259239926980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 10.3.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70259239926980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70259239926460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0.8'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70259239926460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70259239926000 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '2'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70259239926000
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70259239925600 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70259239925600
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdiscount
|
71
|
-
requirement: &
|
71
|
+
requirement: &70259239925140 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70259239925140
|
80
80
|
description:
|
81
81
|
email: kim@burgestrand.se
|
82
82
|
executables: []
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- dev/login.rb
|
99
99
|
- examples/adding_tracks_to_playlist.rb
|
100
|
+
- examples/audio_driver.rb
|
100
101
|
- examples/logging_in.rb
|
101
102
|
- examples/playing_audio.rb
|
102
103
|
- examples/printing_link_information.rb
|
@@ -107,6 +108,8 @@ files:
|
|
107
108
|
- lib/hallon/album_browse.rb
|
108
109
|
- lib/hallon/artist.rb
|
109
110
|
- lib/hallon/artist_browse.rb
|
111
|
+
- lib/hallon/audio_driver.rb
|
112
|
+
- lib/hallon/audio_queue.rb
|
110
113
|
- lib/hallon/base.rb
|
111
114
|
- lib/hallon/enumerator.rb
|
112
115
|
- lib/hallon/error.rb
|
@@ -129,7 +132,6 @@ files:
|
|
129
132
|
- lib/hallon/player.rb
|
130
133
|
- lib/hallon/playlist.rb
|
131
134
|
- lib/hallon/playlist_container.rb
|
132
|
-
- lib/hallon/queue.rb
|
133
135
|
- lib/hallon/search.rb
|
134
136
|
- lib/hallon/session.rb
|
135
137
|
- lib/hallon/toplist.rb
|
@@ -142,6 +144,7 @@ files:
|
|
142
144
|
- spec/hallon/album_spec.rb
|
143
145
|
- spec/hallon/artist_browse_spec.rb
|
144
146
|
- spec/hallon/artist_spec.rb
|
147
|
+
- spec/hallon/audio_queue_spec.rb
|
145
148
|
- spec/hallon/base_spec.rb
|
146
149
|
- spec/hallon/enumerator_spec.rb
|
147
150
|
- spec/hallon/error_spec.rb
|
@@ -163,7 +166,6 @@ files:
|
|
163
166
|
- spec/hallon/player_spec.rb
|
164
167
|
- spec/hallon/playlist_container_spec.rb
|
165
168
|
- spec/hallon/playlist_spec.rb
|
166
|
-
- spec/hallon/queue_spec.rb
|
167
169
|
- spec/hallon/search_spec.rb
|
168
170
|
- spec/hallon/session_spec.rb
|
169
171
|
- spec/hallon/spotify_spec.rb
|
@@ -176,8 +178,10 @@ files:
|
|
176
178
|
- spec/mockspotify/mockspotify_spec.rb
|
177
179
|
- spec/spec_helper.rb
|
178
180
|
- spec/support/.gitkeep
|
181
|
+
- spec/support/audio_driver_mock.rb
|
179
182
|
- spec/support/common_objects.rb
|
180
183
|
- spec/support/context_logged_in.rb
|
184
|
+
- spec/support/context_stub_session.rb
|
181
185
|
- spec/support/cover_me.rb
|
182
186
|
- spec/support/enumerable_comparison.rb
|
183
187
|
- spec/support/shared_for_callbacks.rb
|
@@ -215,9 +219,9 @@ require_paths:
|
|
215
219
|
required_ruby_version: !ruby/object:Gem::Requirement
|
216
220
|
none: false
|
217
221
|
requirements:
|
218
|
-
- -
|
222
|
+
- - ! '>='
|
219
223
|
- !ruby/object:Gem::Version
|
220
|
-
version: '1.
|
224
|
+
version: '1.9'
|
221
225
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
226
|
none: false
|
223
227
|
requirements:
|
@@ -226,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
230
|
version: '0'
|
227
231
|
requirements: []
|
228
232
|
rubyforge_project:
|
229
|
-
rubygems_version: 1.8.
|
233
|
+
rubygems_version: 1.8.15
|
230
234
|
signing_key:
|
231
235
|
specification_version: 3
|
232
236
|
summary: Hallon allows you to write Ruby applications utilizing the official Spotify
|
@@ -238,6 +242,7 @@ test_files:
|
|
238
242
|
- spec/hallon/album_spec.rb
|
239
243
|
- spec/hallon/artist_browse_spec.rb
|
240
244
|
- spec/hallon/artist_spec.rb
|
245
|
+
- spec/hallon/audio_queue_spec.rb
|
241
246
|
- spec/hallon/base_spec.rb
|
242
247
|
- spec/hallon/enumerator_spec.rb
|
243
248
|
- spec/hallon/error_spec.rb
|
@@ -259,7 +264,6 @@ test_files:
|
|
259
264
|
- spec/hallon/player_spec.rb
|
260
265
|
- spec/hallon/playlist_container_spec.rb
|
261
266
|
- spec/hallon/playlist_spec.rb
|
262
|
-
- spec/hallon/queue_spec.rb
|
263
267
|
- spec/hallon/search_spec.rb
|
264
268
|
- spec/hallon/session_spec.rb
|
265
269
|
- spec/hallon/spotify_spec.rb
|
@@ -272,8 +276,10 @@ test_files:
|
|
272
276
|
- spec/mockspotify/mockspotify_spec.rb
|
273
277
|
- spec/spec_helper.rb
|
274
278
|
- spec/support/.gitkeep
|
279
|
+
- spec/support/audio_driver_mock.rb
|
275
280
|
- spec/support/common_objects.rb
|
276
281
|
- spec/support/context_logged_in.rb
|
282
|
+
- spec/support/context_stub_session.rb
|
277
283
|
- spec/support/cover_me.rb
|
278
284
|
- spec/support/enumerable_comparison.rb
|
279
285
|
- spec/support/shared_for_callbacks.rb
|
data/lib/hallon/queue.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require 'thread'
|
3
|
-
|
4
|
-
module Hallon
|
5
|
-
# Hallon::Queue is a non-blocking (well, not entirely) sized FIFO queue.
|
6
|
-
#
|
7
|
-
# You initialize the queue with a `max_size`, and then push data to it.
|
8
|
-
# For every push operation, the Queue will tell you how much of your data
|
9
|
-
# it could consume. If the queue becomes full, it won’t accept any more
|
10
|
-
# data (and will return 0 on the #push operation) until you pull some data
|
11
|
-
# out of it with #pop.
|
12
|
-
#
|
13
|
-
# Hallon::Queue is useful for handling {Hallon::Observable::Session#music_delivery_callback}.
|
14
|
-
#
|
15
|
-
# @example
|
16
|
-
# queue = Hallon::Queue.new(4)
|
17
|
-
# queue.push([1, 2]) # => 2
|
18
|
-
# queue.push([3]) # => 1
|
19
|
-
# queue.push([4, 5, 6]) # => 1
|
20
|
-
# queue.push([5, 6]) # => 0
|
21
|
-
# queue.pop(1) # => [1]
|
22
|
-
# queue.push([5, 6]) # => 1
|
23
|
-
# queue.pop # => [2, 3, 4, 5]
|
24
|
-
class Queue
|
25
|
-
attr_reader :max_size
|
26
|
-
|
27
|
-
# @param [Integer] max_size
|
28
|
-
def initialize(max_size)
|
29
|
-
@mutex = Mutex.new
|
30
|
-
@condv = ConditionVariable.new
|
31
|
-
|
32
|
-
@max_size = max_size
|
33
|
-
@samples = []
|
34
|
-
end
|
35
|
-
|
36
|
-
# @param [#take] data
|
37
|
-
# @return [Integer] how much of the data that was added to the queue
|
38
|
-
def push(samples)
|
39
|
-
synchronize do
|
40
|
-
can_accept = max_size - size
|
41
|
-
new_samples = samples.take(can_accept)
|
42
|
-
|
43
|
-
@samples.concat(new_samples)
|
44
|
-
@condv.signal
|
45
|
-
|
46
|
-
new_samples.size
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# @note If the queue is empty, this operation will block until data is available.
|
51
|
-
# @param [Integer] num_samples max number of samples to pop off the queue
|
52
|
-
# @return [Array] data, where data.size might be less than num_samples but never more
|
53
|
-
def pop(num_samples = max_size)
|
54
|
-
synchronize do
|
55
|
-
@condv.wait(@mutex) while @samples.empty?
|
56
|
-
@samples.shift(num_samples)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# @return [Integer] number of samples in buffer
|
61
|
-
def size
|
62
|
-
@samples.size
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
# @yield (merely a wrapper over @mutex.synchronize)
|
67
|
-
def synchronize
|
68
|
-
@mutex.synchronize { return yield }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/spec/hallon/queue_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
describe Hallon::Queue do
|
3
|
-
let(:queue) { Hallon::Queue.new(4) }
|
4
|
-
subject { queue }
|
5
|
-
|
6
|
-
it "should conform to the example specification of its’ documentation" do
|
7
|
-
queue.push([1, 2]).should eq 2
|
8
|
-
queue.push([3]).should eq 1
|
9
|
-
queue.push([4, 5, 6]).should eq 1
|
10
|
-
queue.push([5, 6]).should eq 0
|
11
|
-
queue.pop(1).should eq [1]
|
12
|
-
queue.push([5, 6]).should eq 1
|
13
|
-
queue.pop.should eq [2, 3, 4, 5]
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#pop" do
|
17
|
-
it "should not block if the queue is not empty" do
|
18
|
-
queue.push([1, 2])
|
19
|
-
|
20
|
-
start = Time.now
|
21
|
-
queue.pop.should eq [1, 2]
|
22
|
-
(Time.now - start).should be_within(0.001).of(0)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should block if the queue is empty" do
|
26
|
-
queue.size.should be_zero
|
27
|
-
|
28
|
-
# I could mock out ConditionVariable and Mutex, but where’s the fun in that?
|
29
|
-
start = Time.now
|
30
|
-
Thread.start { sleep 0.2; queue.push([1]) }
|
31
|
-
queue.pop.should eq [1]
|
32
|
-
(Time.now - start).should be_within(0.08).of(0.2)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|