rares-netflix 0.1.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.
@@ -0,0 +1,38 @@
1
+ # Netflix
2
+
3
+ ## Description
4
+
5
+ This gem handles some of the complexity in dealing with the netflix api (and OAuth in turn).
6
+
7
+ ## Installation
8
+
9
+ sudo gem install netflix
10
+
11
+ ## Usage
12
+
13
+ require "netflix"
14
+
15
+ ## License
16
+
17
+ Copyright (c) 2008 Rob Ares
18
+
19
+ Permission is hereby granted, free of charge, to any person
20
+ obtaining a copy of this software and associated documentation
21
+ files (the "Software"), to deal in the Software without
22
+ restriction, including without limitation the rights to use,
23
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ copies of the Software, and to permit persons to whom the
25
+ Software is furnished to do so, subject to the following
26
+ conditions:
27
+
28
+ The above copyright notice and this permission notice shall be
29
+ included in all copies or substantial portions of the Software.
30
+
31
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
33
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
35
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
36
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
38
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'spec/rake/spectask'
4
+
5
+ require 'lib/netflix/version'
6
+
7
+ task :default => :spec
8
+
9
+ spec = Gem::Specification.new do |s|
10
+ s.name = "netflix"
11
+ s.version = Netflix::Version.to_s
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w(README.markdown)
14
+ s.summary = "This gem handles some of the complexity in dealing with the netflix api (and OAuth in turn)."
15
+ s.author = "Rob Ares"
16
+ s.email = "rob.ares@gmail.com"
17
+ s.homepage = "http://www.robares.com"
18
+ s.files = %w(README.markdown Rakefile) + Dir.glob("{lib,test}/**/*")
19
+ s.add_dependency("rares-oauth", ">=0.2.7")
20
+ end
21
+
22
+ Rake::GemPackageTask.new(spec) do |pkg|
23
+ pkg.gem_spec = spec
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:spec) do |s|
27
+ s.spec_files = FileList[File.dirname(__FILE__) + '/spec/*_spec.rb']
28
+ s.verbose = true
29
+ s.spec_opts = ["--color", "--format specdoc", "--diff"]
30
+ end
31
+
32
+ desc 'Generate the gemspec to serve this Gem from Github'
33
+ task :github do
34
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
35
+ File.open(file, 'w') {|f| f << spec.to_ruby }
36
+ puts "Created gemspec: #{file}"
37
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'hpricot'
3
+
4
+ require 'netflix/user'
5
+ require 'netflix/client'
6
+
7
+ # require 'netflix/...'
@@ -0,0 +1,119 @@
1
+ require "oauth"
2
+
3
+ module Netflix
4
+
5
+ OAUTH_ENDPOINTS = {
6
+ :request => "http://api.netflix.com/oauth/request_token",
7
+ :authorize => "https://api-user.netflix.com/oauth/login",
8
+ :access => "http://api.netflix.com/oauth/access_token"
9
+ }.freeze
10
+
11
+ # for bloed ups.
12
+ class NetflixClientError < StandardError; end
13
+
14
+ # Client class responsible for setting up api calls.
15
+ class AssHat
16
+ attr_accessor :consumer_key, :consumer_secret, :application_name, :api_version
17
+
18
+ def initialize(consumer_key, consumer_secret, application_name)
19
+ raise ArgumentError if consumer_key.nil? or consumer_secret.nil? or application_name.nil?
20
+ @consumer_key = consumer_key
21
+ @consumer_secret = consumer_secret
22
+ @application_name = application_name
23
+ @api_version = "1.0"
24
+
25
+ @access_token = nil
26
+ @access_token_secret = nil
27
+ end
28
+
29
+ # client.acquire_request_token("http://cnn.com/") do |t, s, auth_url|
30
+ # # save to db here.
31
+ # redirect_to auth_url
32
+ # end
33
+ def acquire_request_token(callback_url, &blk)
34
+
35
+ # populate oauth token
36
+ # return token, secret
37
+ # do stuff
38
+
39
+ # give this to the client so that they can save it and stuff
40
+ yield request_token, request_token_secret, build_authorize_url(callback_url)
41
+ end
42
+
43
+ # assuming we have stored these somewhere
44
+ # this just gets us the tokens, we need to have an object that will allow us to make calls.
45
+ # client.exchange_request_token_for_access_token(rt, rs) do |t, s, uid|
46
+ # # save to db here.
47
+ #
48
+ # # do class_eval so that we can just call go(:get, "/queue")
49
+ # end
50
+ def exchange_request_token_for_access_token(request_token, request_token_secret, &blk)
51
+ yield access_token, access_token_secret, user_id
52
+ # use the request token here to get an access token
53
+ # return access token and user id to save.
54
+ # return token, secret
55
+ end
56
+
57
+
58
+ # client.from_access_token(at, as) do |s|
59
+ # do class_eval so that we can just call go(:get, "/queue")
60
+ # end
61
+ def from_access_token(access_token, access_token_secret, &blk)
62
+ #pass infos to the client
63
+ # set instance vars that the oauth client uses.
64
+ # evaluate this block
65
+ yield AccessTokenWrapper.new(access_token, access_token_secret, user_id)
66
+ end
67
+
68
+ def build_authorize_url(callback_url)
69
+ raise
70
+ end
71
+
72
+ end
73
+
74
+ class Client
75
+
76
+ def self.consumer_token=(consumer_token)
77
+ @consumer_token = consumer_token
78
+ end
79
+
80
+ def self.consumer_token
81
+ @consumer_token
82
+ end
83
+
84
+ def self.consumer_secret=(consumer_secret)
85
+ @consumer_secret = consumer_secret
86
+ end
87
+
88
+ def self.consumer_secret
89
+ @consumer_secret
90
+ end
91
+
92
+ # attr_accessor :access_token, :access_token_secret, :user_id
93
+ #
94
+ # def initialize(access_token, access_token_secret, user_id)
95
+ # @access_token = access_token
96
+ # @access_token_secret = access_token_secret
97
+ # @user_id = user_id
98
+ # end
99
+ #
100
+ # def user
101
+ #
102
+ # end
103
+ #
104
+ # def get(path, arguments = {})
105
+ # raise Netflix::NetflixClientError.new("An access token is required to make api calls") if @access_token.nil? or @access_token_secret.nil?
106
+ #
107
+ #
108
+ #
109
+ # # fail if no access creds.
110
+ # # populate access token with instance vars.
111
+ # # delegate to the client class
112
+ # # need to append "Accept-Encoding" => "compress" as header and figure out a way to append the etag stuff.
113
+ # # supposedly /users/current will work but i have yet to see this working.
114
+ #
115
+ # end
116
+
117
+ end
118
+
119
+ end
@@ -0,0 +1,29 @@
1
+ module Netflix
2
+ class User
3
+
4
+ def initialize(wrapper)
5
+ @wrapper = wrapper
6
+ end
7
+
8
+ def populate(response)
9
+ @document = response
10
+ end
11
+
12
+ def current
13
+ self.populate(@wrapper.get("/user/#{@wrapper.user_id}"))
14
+ end
15
+
16
+ def id
17
+ @document.at("//user_id").inner_text
18
+ end
19
+
20
+ def first_name
21
+ @document.at('//first_name').inner_text
22
+ end
23
+
24
+ def last_name
25
+ @document.at("//last_name").inner_text
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Netflix
2
+ module Version
3
+
4
+ MAJOR = 0
5
+ MINOR = 1
6
+ TINY = 0
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, TINY].join('.')
10
+ end
11
+
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rares-netflix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Ares
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-14 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rares-oauth
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.7
23
+ version:
24
+ description:
25
+ email: rob.ares@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README.markdown
32
+ files:
33
+ - README.markdown
34
+ - Rakefile
35
+ - lib/netflix
36
+ - lib/netflix/client.rb
37
+ - lib/netflix/user.rb
38
+ - lib/netflix/version.rb
39
+ - lib/netflix.rb
40
+ has_rdoc: true
41
+ homepage: http://www.robares.com
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.2.0
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: This gem handles some of the complexity in dealing with the netflix api (and OAuth in turn).
66
+ test_files: []
67
+