alanho-typhoeus_oauth 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Alan Ho
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = typhoeus_oauth
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Alan Ho. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "typhoeus_oauth"
8
+ gem.summary = %Q{TODO: one-line summary of your gem}
9
+ gem.description = %Q{TODO: longer description of your gem}
10
+ gem.email = "alanho@gmail.com"
11
+ gem.homepage = "http://github.com/alanho/typhoeus_oauth"
12
+ gem.authors = ["Alan Ho"]
13
+ gem.add_development_dependency "rspec"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ if File.exist?('VERSION')
39
+ version = File.read('VERSION')
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "typhoeus_oauth #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,60 @@
1
+ require "rubygems"
2
+ require "oauth"
3
+
4
+ module OAuth::RequestProxy
5
+ class TyphoeusRequest < OAuth::RequestProxy::Base
6
+ proxies Typhoeus::Easy
7
+
8
+ def method
9
+ request.method.to_s.upcase
10
+ end
11
+
12
+ def uri
13
+ request.url
14
+ end
15
+
16
+ def parameters
17
+ if options[:clobber_request]
18
+ options[:parameters]
19
+ else
20
+ all_parameters
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def all_parameters
27
+ request_params = CGI.parse(query_string)
28
+ if options[:parameters]
29
+ options[:parameters].each do |k,v|
30
+ if request_params.has_key?(k)
31
+ request_params[k] << v
32
+ else
33
+ request_params[k] = [v].flatten
34
+ end
35
+ end
36
+ end
37
+ request_params
38
+ end
39
+
40
+ def query_string
41
+ params = [ query_params, auth_header_params ]
42
+ # is_form_urlencoded = request.headers['Content-Type'] != nil && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded'
43
+ params << post_params if method.to_s.upcase == 'POST'# && is_form_urlencoded
44
+ params.compact.join('&')
45
+ end
46
+
47
+ def query_params
48
+ URI.parse(request.url).query
49
+ end
50
+
51
+ def post_params
52
+ request.post_data
53
+ end
54
+
55
+ def auth_header_params
56
+ return nil unless request.headers['Authorization'] && request.headers['Authorization'][0,5] == 'OAuth'
57
+ auth_params = request.headers['Authorization']
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,50 @@
1
+ module TyphoeusOAuth
2
+ module ModuleExtension
3
+ def self.included(base)
4
+ base.send :include, InstanceMethods
5
+ base.module_eval %q{
6
+ alias_method :remote_proxy_object_without_oauth, :remote_proxy_object
7
+ alias_method :remote_proxy_object, :remote_proxy_object_with_oauth
8
+
9
+ alias_method :define_remote_method_without_oauth, :define_remote_method
10
+ alias_method :define_remote_method, :define_remote_method_with_oauth
11
+ }
12
+ end
13
+
14
+ module InstanceMethods
15
+ def define_remote_method_with_oauth(name, args = {})
16
+ @remote_defaults ||= {}
17
+
18
+ # allow user to set :oauth_consumer to nil for non-oauth request
19
+ args[:oauth_consumer] = @remote_defaults[:oauth_consumer] unless args.has_key? :oauth_consumer
20
+ args[:oauth_token] = @remote_defaults[:oauth_token] unless args.has_key? :oauth_token
21
+
22
+ define_remote_method_without_oauth(name, args.reject {|k,v| v.nil?} )
23
+ end
24
+
25
+ def remote_proxy_object_with_oauth(url, method, options)
26
+ unless options.has_key? :oauth_consumer
27
+ remote_proxy_object_without_oauth(url, method, options)
28
+ else
29
+ easy = Typhoeus.get_easy_object
30
+
31
+ easy.url = url
32
+ easy.method = method
33
+ easy.headers = options[:headers] if options.has_key?(:headers)
34
+ easy.headers["User-Agent"] = (options[:user_agent] || Typhoeus::USER_AGENT)
35
+ easy.params = options[:params] if options[:params]
36
+ easy.request_body = options[:body] if options[:body]
37
+ easy.timeout = options[:timeout] if options[:timeout]
38
+ if options.has_key?(:oauth_token_key) && options.has_key?(:oauth_token_secret)
39
+ options[:oauth_token] ||= OAuth::AccessToken.new(options[:oauth_consumer], options[:oauth_token_key], options[:oauth_token_secret])
40
+ end
41
+ easy.oauth!(options[:oauth_consumer], options[:oauth_token])
42
+ easy.set_headers
43
+
44
+ proxy = Typhoeus::RemoteProxyObject.new(clear_memoized_proxy_objects, easy, options)
45
+ set_memoized_proxy_object(method, url, options, proxy)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,99 @@
1
+ module TyphoeusOAuth
2
+ module OAuthExtension
3
+ def self.included(base)
4
+ base.send :include, InstanceMethods
5
+
6
+ base.class_eval <<-EOV, __FILE__, __LINE__
7
+ old_post_data = self.instance_method(:post_data=)
8
+
9
+ define_method(:post_data=) do |data|
10
+ @post_data = data
11
+ old_post_data.bind(self).call data
12
+ end
13
+ EOV
14
+ end
15
+
16
+ module InstanceMethods
17
+ include ::OAuth::Helper
18
+ attr_reader :oauth_helper
19
+
20
+ def oauth!(consumer, token, options = {})
21
+ options = { :request_uri => oauth_full_request_uri,
22
+ :consumer => consumer,
23
+ :token => token,
24
+ :scheme => 'header',
25
+ :signature_method => nil,
26
+ :nonce => nil,
27
+ :timestamp => nil }.merge(options)
28
+
29
+ @oauth_helper = OAuth::Client::Helper.new(self, options)
30
+ @oauth_helper.amend_user_agent_header(@headers)
31
+ self.send("set_oauth_#{options[:scheme]}")
32
+ end
33
+
34
+ def signature_base_string(consumer = nil, token = nil, options = {})
35
+ options = { :request_uri => oauth_full_request_uri,
36
+ :consumer => consumer,
37
+ :token => token,
38
+ :scheme => 'header',
39
+ :signature_method => nil,
40
+ :nonce => nil,
41
+ :timestamp => nil }.merge(options)
42
+
43
+ OAuth::Client::Helper.new(self, options).signature_base_string
44
+ end
45
+
46
+ def params
47
+ query = if [:post, :put].include? method
48
+ self.post_data
49
+ else
50
+ URI.parse(self.url).query
51
+ end
52
+ CGI::parse(query)
53
+ end
54
+
55
+ def post_data
56
+ @post_data ||= nil
57
+ end
58
+
59
+ private
60
+ def oauth_full_request_uri
61
+ http = URI.parse(self.url)
62
+
63
+ uri = URI.parse(http.path)
64
+ uri.host = http.host
65
+ uri.port = http.port
66
+
67
+ if self.url =~ /^https/
68
+ uri.scheme = "https"
69
+ else
70
+ uri.scheme = "http"
71
+ end
72
+
73
+ uri.to_s
74
+ end
75
+
76
+ def set_oauth_header
77
+ @headers['Authorization'] = @oauth_helper.header
78
+ end
79
+
80
+ def set_oauth_body
81
+ raise NotImplementedError, "Not implemented yet"
82
+ end
83
+
84
+ def set_oauth_query_string
85
+ oauth_params_str = @oauth_helper.oauth_parameters.map { |k,v| [escape(k), escape(v)] * "=" }.join("&")
86
+
87
+ uri = URI.parse(self.url)
88
+ if uri.query.to_s == ""
89
+ uri.query = oauth_params_str
90
+ else
91
+ uri.query = uri.query + "&" + oauth_params_str
92
+ end
93
+
94
+ self.url = uri.to_s
95
+ self.url << "&oauth_signature=#{escape(oauth_helper.signature)}"
96
+ end
97
+ end
98
+ end
99
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'typhoeus_oauth'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TyphoeusOauth" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alanho-typhoeus_oauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alan Ho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.5
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: pauldix-typhoeus
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.24
44
+ version:
45
+ description: Bridging OAuth and Typhoeus
46
+ email: alanho@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - lib/oauth/request_proxy/typhoeus_request.rb
62
+ - lib/typhoeus_oauth.rb
63
+ - lib/typhoeus_oauth/module_extension.rb
64
+ - lib/typhoeus_oauth/oauth_extension.rb
65
+ - spec/spec_helper.rb
66
+ - spec/typhoeus_oauth_spec.rb
67
+ has_rdoc: false
68
+ homepage: http://github.com/alanho/typhoeus_oauth
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.2.0
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Bridging OAuth and Typhoeus
93
+ test_files:
94
+ - spec/spec_helper.rb
95
+ - spec/typhoeus_oauth_spec.rb