hooloo 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85573d2b1b378c17ec0143207b0fe001e121e14b
4
- data.tar.gz: 49a263beb1aebb40aad6122b973f047112bb91e4
3
+ metadata.gz: 1615bf1fea0dc7d8018501e31c3c7a1a283c0e22
4
+ data.tar.gz: 3c0e8b7ccce9c26f92567ffb82e2a0e0f5d8616d
5
5
  SHA512:
6
- metadata.gz: 102aab5dee2acd6fe9638a091340adbade108ba5bc2077e9a127a874ba73c42d6a9431ea122c4ef7e09ea26f0eb7129d37d78336c20611702e91fb6d0ab0cf2e
7
- data.tar.gz: dbe99bf1541d50a9033402201f6f69dcff16cfbcce0ea350c0f1dc3c80f0ddf94913c01e47ac10c8772acb5406caccdf0ab4558a3ace25709840515d9e355cc4
6
+ metadata.gz: d907d13bb38d54c27da515379cb891dcc63f197f2c05816441b3785ebbad93867cf2883f9846e18b3dfb629c23ce35ecfb7b2a9c97d1c1cb7ece0c0e3e54ec2c
7
+ data.tar.gz: 463a835292e78cb51ec5ac52475c848c8e75749cff28b2bf2aef56f5d6244c0f113dfb0f966a510e0d8f7c567301f9bf1101b95201615f9cc4c864811547ac65
@@ -7,9 +7,15 @@ class Hooloo::Genre < Hooloo::MozartHash
7
7
  @obj = obj
8
8
  end
9
9
  end
10
- def shows(args={items_per_page: 10, position: 0})
11
- args.merge!({genre: canonical_name, sort: 'release_with_popularity'})
12
- Hooloo.request('shows', args)['data'].map { |x| Hooloo::Show.new x['show'] }
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
  #
@@ -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\-_\/]+)';$/)]
@@ -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
@@ -1,7 +1,8 @@
1
1
  class Hooloo::Show < Hooloo::MozartHash
2
- def self.popular_today(args={limit: 10, position: 0})
3
- args.merge!({sort: 'popular_today'})
4
- Hooloo.request('shows', args)['data'].map { |x| new x['show'] }
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.request("shows/#{id}/episodes", {
16
- items_per_page: 128,
15
+ def videos(season=1, args={})
16
+ Hooloo.paginated_request("shows/#{id}/episodes", {
17
17
  season_number: season
18
- })['data'].map { |x| Hooloo::Video.new x['video'] }
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
@@ -1,3 +1,3 @@
1
1
  class Hooloo
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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.length.must_be :>, 0
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 }
@@ -5,7 +5,7 @@ describe Hooloo::Show do
5
5
  describe 'Popular Today' do
6
6
  let(:shows) { Hooloo::Show.popular_today }
7
7
  it 'should retrieve popular_today' do
8
- shows.length.must_equal 10
8
+ shows.count.must_equal 10
9
9
  end
10
10
  end
11
11
  describe 'Loading' do
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.2.1
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-16 00:00:00.000000000 Z
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json