Sha256: d72d4afe891bd4ae8e076fb91300e674fbbff8306a57891b92df5415f09dd283

Contents?: true

Size: 868 Bytes

Versions: 4

Compression:

Stored size: 868 Bytes

Contents

require 'uri'
require 'open-uri'
require 'multi_json'

class Hooloo
  class << self
    def auto_cast(obj)
      # TODO: Automatically cast an object received from Mozart into the corresponding Ruby Class
    end
    def hulu_uri
      URI("http://www.hulu.com/")
    end
    def api_uri
      hulu_uri + '/mozart/v1.h2o/'
    end
    def request_uri(path, query={})
      uri = api_uri + path
      uri.query = URI.encode_www_form({
        access_token: tokens["API"]
      }.merge(query))
      uri
    end
    def request(*args)
      # TODO: check if we get 403'd and request a new token
      MultiJson.load open(request_uri(*args)).read
    end
    def tokens
      @tokens or begin
        @tokens = Hash[open(hulu_uri).read.scan(/([A-Z]+)_DONUT = '([a-zA-Z0-9\-_\/]+)';$/)]
      end
    end
    def tokens!
      @tokens = nil
      tokens
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hooloo-0.2.1 lib/hooloo/hooloo.rb
hooloo-0.2.0 lib/hooloo/hooloo.rb
hooloo-0.1.1 lib/hooloo/hooloo.rb
hooloo-0.1.0 lib/hooloo/hooloo.rb