hooloo 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/hooloo/genre.rb +9 -3
- data/lib/hooloo/hooloo.rb +13 -0
- data/lib/hooloo/mozart_hash.rb +2 -2
- data/lib/hooloo/show.rb +7 -7
- data/lib/hooloo/version.rb +1 -1
- data/spec/hooloo/genre_spec.rb +1 -1
- data/spec/hooloo/show_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1615bf1fea0dc7d8018501e31c3c7a1a283c0e22
|
4
|
+
data.tar.gz: 3c0e8b7ccce9c26f92567ffb82e2a0e0f5d8616d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d907d13bb38d54c27da515379cb891dcc63f197f2c05816441b3785ebbad93867cf2883f9846e18b3dfb629c23ce35ecfb7b2a9c97d1c1cb7ece0c0e3e54ec2c
|
7
|
+
data.tar.gz: 463a835292e78cb51ec5ac52475c848c8e75749cff28b2bf2aef56f5d6244c0f113dfb0f966a510e0d8f7c567301f9bf1101b95201615f9cc4c864811547ac65
|
data/lib/hooloo/genre.rb
CHANGED
@@ -7,9 +7,15 @@ class Hooloo::Genre < Hooloo::MozartHash
|
|
7
7
|
@obj = obj
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# List all shows in this genre
|
11
|
+
#
|
12
|
+
# @param args [Hash] (see Hooloo#request)
|
13
|
+
# @return [Enumerator<Hooloo::Show>] List of shows
|
14
|
+
def shows(args={})
|
15
|
+
Hooloo.paginated_request('shows', {
|
16
|
+
genre: canonical_name,
|
17
|
+
sort: 'release_with_popularity'
|
18
|
+
}.merge(args)) { |g, x| g << Hooloo::Show.new(x['show']) }
|
13
19
|
end
|
14
20
|
# List all genres known to Hulu
|
15
21
|
#
|
data/lib/hooloo/hooloo.rb
CHANGED
@@ -24,6 +24,19 @@ class Hooloo
|
|
24
24
|
# TODO: check if we get 403'd and request a new token
|
25
25
|
MultiJson.load open(request_uri(*args)).read
|
26
26
|
end
|
27
|
+
def paginated_request(path, args={}, page_size=70, &block)
|
28
|
+
# TODO: cache responses
|
29
|
+
Enumerator.new do |g|
|
30
|
+
loop.with_index do |_, i|
|
31
|
+
response = request(path, {
|
32
|
+
items_per_page: page_size,
|
33
|
+
position: i * page_size
|
34
|
+
}.merge(args))['data']
|
35
|
+
response.each { |x| block.call(g, x) }
|
36
|
+
break if response.length < page_size
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
27
40
|
def tokens
|
28
41
|
@tokens or begin
|
29
42
|
@tokens = Hash[open(hulu_uri).read.scan(/([A-Z]+)_DONUT = '([a-zA-Z0-9\-_\/]+)';$/)]
|
data/lib/hooloo/mozart_hash.rb
CHANGED
@@ -49,8 +49,8 @@ class Hooloo::MozartHash
|
|
49
49
|
end
|
50
50
|
# Honestly, we should generate methods when we initially parse the Hash
|
51
51
|
# instead of doing this crap in method_missing. I'll do that later.
|
52
|
-
def method_missing(method)
|
53
|
-
@obj[method.to_s]
|
52
|
+
def method_missing(method, *args, &block)
|
53
|
+
@obj[method.to_s] or super
|
54
54
|
end
|
55
55
|
def respond_to?(method)
|
56
56
|
@obj.has_key? method.to_s or super
|
data/lib/hooloo/show.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class Hooloo::Show < Hooloo::MozartHash
|
2
|
-
def self.popular_today(args={
|
3
|
-
|
4
|
-
|
2
|
+
def self.popular_today(args={})
|
3
|
+
Hooloo.paginated_request('shows', {
|
4
|
+
sort: 'popular_today'
|
5
|
+
}.merge(args)) { |g, x| g << Hooloo::Show.new(x['show']) }
|
5
6
|
end
|
6
7
|
def initialize(id)
|
7
8
|
super
|
@@ -11,11 +12,10 @@ class Hooloo::Show < Hooloo::MozartHash
|
|
11
12
|
@obj = id
|
12
13
|
end
|
13
14
|
end
|
14
|
-
def videos(season=1)
|
15
|
-
Hooloo.
|
16
|
-
items_per_page: 128,
|
15
|
+
def videos(season=1, args={})
|
16
|
+
Hooloo.paginated_request("shows/#{id}/episodes", {
|
17
17
|
season_number: season
|
18
|
-
})
|
18
|
+
}.merge(args)) { |g, x| g << Hooloo::Video.new(x['video']) }
|
19
19
|
end
|
20
20
|
bool :embed_permitted, :has_captions
|
21
21
|
date :cache_time
|
data/lib/hooloo/version.rb
CHANGED
data/spec/hooloo/genre_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe Hooloo::Genre do
|
|
11
11
|
describe 'Shows List' do
|
12
12
|
let(:genre) { Hooloo::Genre.new 'anime' }
|
13
13
|
it 'should return multiple shows' do
|
14
|
-
genre.shows.
|
14
|
+
genre.shows.count.must_be :>, 0
|
15
15
|
end
|
16
16
|
it 'should convert shows to Show objects' do
|
17
17
|
genre.shows.each { |x| x.must_be_instance_of Hooloo::Show }
|
data/spec/hooloo/show_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hooloo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Lejeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|