hulu-api 1.0.1

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmQyMjkwZDBiOWFhMTkwZTkyYzI2MzNjY2E1M2MxMTFhYWIxNjM5Yw==
5
+ data.tar.gz: !binary |-
6
+ YzdhMDFhODBmZWJlZWMzNmRmMTM2OTJkOTg4ZmMzMDA0ZGIzZmYxYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzEzYWYzZTZiMjBiMzgzMDAxNDM2ZGYzODUyZTMxY2M4YTliMGMzMTNhNGIz
10
+ OWRkNGJlZDVkNTIzNzMyZWQ1ZTc4ZDQxZjVlODgzYzFjMWU3MTc3MWIzZDI4
11
+ NGY0OWFlYzliNzllMTZhMWQ1YTc0NDQ0NTk2ZGM1NDNmZTVhOGQ=
12
+ data.tar.gz: !binary |-
13
+ M2E1YTczNGUxN2YzMmFjZmJlNWE2ZGJlNGU3YTc0MGRkZDBiNGU2YzEyY2Uy
14
+ NWRmMWQwOTk0ZmNkYWNlMTQ2M2MzYzA5Yzc5ZTg1MDRlNjlkZTgyOWZmMmFj
15
+ ZGZjNDBmMjBhY2IzNjcwZDJlM2YzMDY2NGViODQ2NjNmMDQzNDk=
@@ -0,0 +1,3 @@
1
+ require 'curl'
2
+ require 'simple_xml'
3
+ require File.join(File.dirname(__FILE__), "hulu_api", "hulu_api")
@@ -0,0 +1,61 @@
1
+ class Hulu
2
+ BASE_URL = 'http://m.hulu.com/'
3
+ SEARCH_URL = 'http://m.hulu.com/search?dp_identifier=%s&query=%s&items_per_page=%d&page=%d'
4
+ EMBED_CODE = '<iframe src="http://www.hulu.com/embed.html?eid=%s" width="%d" height="%d" frameborder="0" scrolling="no" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>'
5
+
6
+ POSSIBLE_RETRIEVALS = {:shows => 'shows', :genres => 'channels', :companies => 'companies', :videos => 'videos'}
7
+
8
+ def initialize(client_id = 'Hulu')
9
+ @client_id = client_id
10
+ end
11
+
12
+ def http(url)
13
+ ch = Curl::Easy.http_get url
14
+ response = ch.body_str
15
+ status = ch.status
16
+ if(status.equal? "404 Not Found")
17
+ raise "Failure to retrieve Hulu content"
18
+ end
19
+ response
20
+ end
21
+
22
+ def generate_url(type='', params={})
23
+ url = "#{BASE_URL}/#{type}/?dp_id=#{@client_id}"
24
+ params.each do |k,v|
25
+ url << "&#{k}=#{v}"
26
+ end
27
+ url
28
+ end
29
+
30
+ def method_missing(symbol, *args)
31
+ type_arg = POSSIBLE_RETRIEVALS[symbol.to_sym]
32
+ if type_arg
33
+ generate_url type_arg, *args
34
+ end
35
+ end
36
+
37
+ def get_companies(params={})
38
+ url = generate_url "companies", params
39
+ http url
40
+ end
41
+
42
+ def get_embed_code(eid, width = 512, height = 288)
43
+ sprintf EMBED_CODE, eid, width, height
44
+ end
45
+
46
+ def search(query, items_per_page=10, page=1)
47
+ url = sprintf SEARCH_URL, @client_id, query, items_per_page, page
48
+ puts url
49
+ xml_str = http url
50
+ r = to_json(xml_str)
51
+ end
52
+
53
+ def to_json(xml_str)
54
+ doc = REXML::Document.new(xml_str)
55
+ doc.simplify("/results")
56
+ end
57
+
58
+
59
+
60
+ end
61
+
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hulu-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gary Rosales
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: curb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.6
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.6
33
+ - !ruby/object:Gem::Dependency
34
+ name: simple-xml
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 1.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.0
53
+ description: A Hulu API port of the unofficial Hulu API PHP library
54
+ email: pwfixed@garyrosales.com
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - lib/hulu_api.rb
60
+ - lib/hulu_api/hulu_api.rb
61
+ homepage: https://github.com/pointwisefixed/hulu_api
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.1
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A Hulu API port the unofficial Hulu API PHP
85
+ test_files: []