Class: Hooloo

Inherits:
Object
  • Object
show all
Defined in:
lib/hooloo/hooloo.rb,
lib/hooloo/version.rb

Defined Under Namespace

Classes: Company, Genre, MozartHash, Rollup, Show, Video

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.api_uriObject



13
14
15
# File 'lib/hooloo/hooloo.rb', line 13

def api_uri
  hulu_uri + '/mozart/v1.h2o/'
end

.auto_cast(obj) ⇒ Object



7
8
9
# File 'lib/hooloo/hooloo.rb', line 7

def auto_cast(obj)
  # TODO: Automatically cast an object received from Mozart into the corresponding Ruby Class
end

.hulu_uriObject

TODO: Automatically cast an object received from Mozart into the corresponding Ruby Class



10
11
12
# File 'lib/hooloo/hooloo.rb', line 10

def hulu_uri
  URI("http://www.hulu.com/")
end

.request(*args) ⇒ Object



23
24
25
26
# File 'lib/hooloo/hooloo.rb', line 23

def request(*args)
  # TODO: check if we get 403'd and request a new token
  MultiJson.load open(request_uri(*args)).read
end

.request_uri(path, query = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/hooloo/hooloo.rb', line 16

def request_uri(path, query={})
  uri = api_uri + path
  uri.query = URI.encode_www_form({
    access_token: tokens["API"]
  }.merge(query))
  uri
end

.tokensObject



27
28
29
30
31
# File 'lib/hooloo/hooloo.rb', line 27

def tokens
  @tokens or begin
    @tokens = Hash[open(hulu_uri).read.scan(/([A-Z]+)_DONUT = '([a-zA-Z0-9\-_\/]+)';$/)]
  end
end

.tokens!Object



32
33
34
35
# File 'lib/hooloo/hooloo.rb', line 32

def tokens!
  @tokens = nil
  tokens
end