oauth 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of oauth might be problematic. Click here for more details.
- data/History.txt +35 -17
- data/Manifest.txt +13 -1
- data/README.rdoc +5 -7
- data/Rakefile +6 -4
- data/TODO +18 -0
- data/bin/oauth +1 -1
- data/examples/yql.rb +44 -0
- data/lib/oauth.rb +1 -0
- data/lib/oauth/cli.rb +201 -31
- data/lib/oauth/client/action_controller_request.rb +13 -12
- data/lib/oauth/client/helper.rb +10 -14
- data/lib/oauth/client/net_http.rb +25 -22
- data/lib/oauth/consumer.rb +164 -110
- data/lib/oauth/errors.rb +3 -0
- data/lib/oauth/errors/error.rb +4 -0
- data/lib/oauth/errors/problem.rb +14 -0
- data/lib/oauth/errors/unauthorized.rb +12 -0
- data/lib/oauth/helper.rb +44 -6
- data/lib/oauth/oauth.rb +7 -0
- data/lib/oauth/oauth_test_helper.rb +12 -13
- data/lib/oauth/request_proxy/action_controller_request.rb +5 -6
- data/lib/oauth/request_proxy/base.rb +95 -45
- data/lib/oauth/request_proxy/jabber_request.rb +1 -2
- data/lib/oauth/request_proxy/mock_request.rb +8 -0
- data/lib/oauth/request_proxy/net_http.rb +2 -2
- data/lib/oauth/request_proxy/rack_request.rb +7 -7
- data/lib/oauth/server.rb +31 -33
- data/lib/oauth/signature/base.rb +23 -21
- data/lib/oauth/signature/hmac/base.rb +1 -1
- data/lib/oauth/signature/hmac/sha1.rb +0 -1
- data/lib/oauth/signature/plaintext.rb +2 -2
- data/lib/oauth/signature/rsa/sha1.rb +5 -4
- data/lib/oauth/token.rb +6 -136
- data/lib/oauth/tokens/access_token.rb +68 -0
- data/lib/oauth/tokens/consumer_token.rb +32 -0
- data/lib/oauth/tokens/request_token.rb +28 -0
- data/lib/oauth/tokens/server_token.rb +9 -0
- data/lib/oauth/tokens/token.rb +17 -0
- data/lib/oauth/version.rb +1 -1
- data/oauth.gemspec +12 -6
- data/test/cases/spec/1_0-final/test_construct_request_url.rb +1 -1
- data/test/test_access_token.rb +28 -0
- data/test/test_action_controller_request_proxy.rb +17 -0
- data/test/test_consumer.rb +3 -4
- data/test/test_helper.rb +0 -5
- data/test/test_request_token.rb +53 -0
- data/test/test_server.rb +1 -1
- data/website/index.html +2 -2
- metadata +37 -4
- data/specs.txt +0 -13
@@ -4,9 +4,9 @@ require 'action_controller/test_process'
|
|
4
4
|
|
5
5
|
module ActionController
|
6
6
|
class Base
|
7
|
-
def process_with_oauth(request,response=nil)
|
7
|
+
def process_with_oauth(request, response=nil)
|
8
8
|
request.apply_oauth!
|
9
|
-
process_without_oauth(request,response)
|
9
|
+
process_without_oauth(request, response)
|
10
10
|
end
|
11
11
|
|
12
12
|
alias_method_chain :process, :oauth
|
@@ -18,21 +18,22 @@ module ActionController
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.use_oauth?
|
21
|
-
@use_oauth
|
21
|
+
@use_oauth
|
22
22
|
end
|
23
23
|
|
24
24
|
def configure_oauth(consumer = nil, token = nil, options = {})
|
25
|
-
@oauth_options = { :consumer
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
@oauth_options = { :consumer => consumer,
|
26
|
+
:token => token,
|
27
|
+
:scheme => 'header',
|
28
|
+
:signature_method => nil,
|
29
|
+
:nonce => nil,
|
30
|
+
:timestamp => nil }.merge(options)
|
31
31
|
end
|
32
32
|
|
33
33
|
def apply_oauth!
|
34
34
|
return unless ActionController::TestRequest.use_oauth? && @oauth_options
|
35
|
-
|
35
|
+
|
36
|
+
@oauth_helper = OAuth::Client::Helper.new(self, @oauth_options.merge(:request_uri => request_uri))
|
36
37
|
|
37
38
|
self.send("set_oauth_#{@oauth_options[:scheme]}")
|
38
39
|
end
|
@@ -43,9 +44,9 @@ module ActionController
|
|
43
44
|
|
44
45
|
def set_oauth_parameters
|
45
46
|
@query_parameters = @oauth_helper.parameters_with_oauth
|
46
|
-
@query_parameters.merge!(
|
47
|
+
@query_parameters.merge!(:oauth_signature => @oauth_helper.signature)
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
def set_oauth_query_string
|
50
51
|
end
|
51
52
|
end
|
data/lib/oauth/client/helper.rb
CHANGED
@@ -7,7 +7,7 @@ require 'oauth/signature/hmac/sha1'
|
|
7
7
|
module OAuth::Client
|
8
8
|
class Helper
|
9
9
|
include OAuth::Helper
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(request, options = {})
|
12
12
|
@request = request
|
13
13
|
@options = options
|
@@ -26,10 +26,6 @@ module OAuth::Client
|
|
26
26
|
options[:timestamp] ||= generate_timestamp
|
27
27
|
end
|
28
28
|
|
29
|
-
def generate_timestamp
|
30
|
-
Time.now.to_i.to_s
|
31
|
-
end
|
32
|
-
|
33
29
|
def oauth_parameters
|
34
30
|
{
|
35
31
|
'oauth_consumer_key' => options[:consumer].key,
|
@@ -38,25 +34,25 @@ module OAuth::Client
|
|
38
34
|
'oauth_timestamp' => timestamp,
|
39
35
|
'oauth_nonce' => nonce,
|
40
36
|
'oauth_version' => '1.0'
|
41
|
-
}.reject { |k,v| v == "" }
|
37
|
+
}.reject { |k,v| v.to_s == "" }
|
42
38
|
end
|
43
39
|
|
44
40
|
def signature(extra_options = {})
|
45
41
|
OAuth::Signature.sign(@request, { :uri => options[:request_uri],
|
46
|
-
|
47
|
-
|
42
|
+
:consumer => options[:consumer],
|
43
|
+
:token => options[:token] }.merge(extra_options) )
|
48
44
|
end
|
49
45
|
|
50
46
|
def signature_base_string(extra_options = {})
|
51
|
-
OAuth::Signature.signature_base_string(@request, { :uri
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
OAuth::Signature.signature_base_string(@request, { :uri => options[:request_uri],
|
48
|
+
:consumer => options[:consumer],
|
49
|
+
:token => options[:token],
|
50
|
+
:parameters => oauth_parameters}.merge(extra_options) )
|
55
51
|
end
|
56
52
|
|
57
53
|
def header
|
58
54
|
parameters = oauth_parameters
|
59
|
-
parameters.merge!(
|
55
|
+
parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))
|
60
56
|
|
61
57
|
header_params_str = parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
|
62
58
|
|
@@ -69,7 +65,7 @@ module OAuth::Client
|
|
69
65
|
end
|
70
66
|
|
71
67
|
def parameters_with_oauth
|
72
|
-
oauth_parameters.merge(
|
68
|
+
oauth_parameters.merge(parameters)
|
73
69
|
end
|
74
70
|
end
|
75
71
|
end
|
@@ -5,43 +5,46 @@ require 'oauth/request_proxy/net_http'
|
|
5
5
|
class Net::HTTPRequest
|
6
6
|
include OAuth::Helper
|
7
7
|
|
8
|
+
attr_reader :oauth_helper
|
9
|
+
|
8
10
|
def oauth!(http, consumer = nil, token = nil, options = {})
|
9
|
-
options = { :request_uri
|
10
|
-
:consumer
|
11
|
-
:token
|
12
|
-
:scheme
|
11
|
+
options = { :request_uri => oauth_full_request_uri(http),
|
12
|
+
:consumer => consumer,
|
13
|
+
:token => token,
|
14
|
+
:scheme => 'header',
|
13
15
|
:signature_method => nil,
|
14
|
-
:nonce
|
15
|
-
:timestamp
|
16
|
+
:nonce => nil,
|
17
|
+
:timestamp => nil }.merge(options)
|
16
18
|
|
17
19
|
@oauth_helper = OAuth::Client::Helper.new(self, options)
|
18
20
|
self.send("set_oauth_#{options[:scheme]}")
|
19
21
|
end
|
20
22
|
|
21
23
|
def signature_base_string(http, consumer = nil, token = nil, options = {})
|
22
|
-
options = { :request_uri
|
23
|
-
:consumer
|
24
|
-
:token
|
25
|
-
:scheme
|
24
|
+
options = { :request_uri => oauth_full_request_uri(http),
|
25
|
+
:consumer => consumer,
|
26
|
+
:token => token,
|
27
|
+
:scheme => 'header',
|
26
28
|
:signature_method => nil,
|
27
|
-
:nonce
|
28
|
-
:timestamp
|
29
|
+
:nonce => nil,
|
30
|
+
:timestamp => nil }.merge(options)
|
29
31
|
|
30
32
|
OAuth::Client::Helper.new(self, options).signature_base_string
|
31
33
|
end
|
32
|
-
|
33
|
-
|
34
|
-
@oauth_helper
|
35
|
-
end
|
36
|
-
private
|
34
|
+
|
35
|
+
private
|
37
36
|
|
38
37
|
def oauth_full_request_uri(http)
|
39
38
|
uri = URI.parse(self.path)
|
40
39
|
uri.host = http.address
|
41
40
|
uri.port = http.port
|
42
|
-
|
43
|
-
|
41
|
+
|
42
|
+
if http.respond_to?(:use_ssl?) && http.use_ssl?
|
43
|
+
uri.scheme = "https"
|
44
|
+
else
|
45
|
+
uri.scheme = "http"
|
44
46
|
end
|
47
|
+
|
45
48
|
uri.to_s
|
46
49
|
end
|
47
50
|
|
@@ -59,10 +62,10 @@ class Net::HTTPRequest
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def set_oauth_query_string
|
62
|
-
oauth_params_str = @oauth_helper.oauth_parameters.map { |k,v|
|
65
|
+
oauth_params_str = @oauth_helper.oauth_parameters.map { |k,v| [escape(k), escape(v)] * "=" }.join("&")
|
63
66
|
|
64
67
|
uri = URI.parse(path)
|
65
|
-
if
|
68
|
+
if uri.query.to_s == ""
|
66
69
|
uri.query = oauth_params_str
|
67
70
|
else
|
68
71
|
uri.query = uri.query + "&" + oauth_params_str
|
@@ -70,6 +73,6 @@ class Net::HTTPRequest
|
|
70
73
|
|
71
74
|
@path = uri.to_s
|
72
75
|
|
73
|
-
@path << "&oauth_signature=#{escape(
|
76
|
+
@path << "&oauth_signature=#{escape(oauth_helper.signature)}"
|
74
77
|
end
|
75
78
|
end
|
data/lib/oauth/consumer.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'net/https'
|
3
3
|
require 'oauth/client/net_http'
|
4
|
+
require 'oauth/errors'
|
5
|
+
|
4
6
|
module OAuth
|
5
7
|
class Consumer
|
6
|
-
|
7
|
-
|
8
|
+
# determine the certificate authority path to verify SSL certs
|
9
|
+
CA_FILES = %w(/etc/ssl/certs/ca-certificates.crt /usr/share/curl/curl-ca-bundle.crt)
|
10
|
+
CA_FILES.each do |ca_file|
|
11
|
+
if File.exists?(ca_file)
|
12
|
+
CA_FILE = ca_file
|
13
|
+
break
|
14
|
+
end
|
15
|
+
end
|
16
|
+
CA_FILE = nil unless defined?(CA_FILE)
|
17
|
+
|
18
|
+
@@default_options = {
|
8
19
|
# Signature method used by server. Defaults to HMAC-SHA1
|
9
|
-
:signature_method
|
10
|
-
|
20
|
+
:signature_method => 'HMAC-SHA1',
|
21
|
+
|
11
22
|
# default paths on site. These are the same as the defaults set up by the generators
|
12
|
-
:request_token_path=>'/oauth/request_token',
|
13
|
-
:authorize_path=>'/oauth/authorize',
|
14
|
-
:access_token_path=>'/oauth/access_token',
|
15
|
-
|
16
|
-
# How do we send the oauth values to the server see
|
23
|
+
:request_token_path => '/oauth/request_token',
|
24
|
+
:authorize_path => '/oauth/authorize',
|
25
|
+
:access_token_path => '/oauth/access_token',
|
26
|
+
|
27
|
+
# How do we send the oauth values to the server see
|
17
28
|
# http://oauth.net/core/1.0/#consumer_req_param for more info
|
18
29
|
#
|
19
30
|
# Possible values:
|
@@ -21,123 +32,150 @@ module OAuth
|
|
21
32
|
# :header - via the Authorize header (Default) ( option 1. in spec)
|
22
33
|
# :body - url form encoded in body of POST request ( option 2. in spec)
|
23
34
|
# :query_string - via the query part of the url ( option 3. in spec)
|
24
|
-
:scheme
|
25
|
-
|
35
|
+
:scheme => :header,
|
36
|
+
|
26
37
|
# Default http method used for OAuth Token Requests (defaults to :post)
|
27
|
-
:http_method
|
28
|
-
|
29
|
-
:oauth_version=>"1.0"
|
38
|
+
:http_method => :post,
|
39
|
+
|
40
|
+
:oauth_version => "1.0"
|
30
41
|
}
|
31
|
-
|
32
|
-
attr_accessor :
|
33
|
-
|
34
|
-
|
42
|
+
|
43
|
+
attr_accessor :options, :key, :secret
|
44
|
+
attr_writer :site, :http
|
45
|
+
|
35
46
|
# Create a new consumer instance by passing it a configuration hash:
|
36
47
|
#
|
37
|
-
# @consumer=OAuth::Consumer.new(
|
38
|
-
# :site=>"http://term.ie",
|
39
|
-
# :scheme
|
40
|
-
# :http_method
|
41
|
-
# :request_token_path=>"/oauth/example/request_token.php",
|
42
|
-
# :access_token_path=>"/oauth/example/access_token.php",
|
43
|
-
# :authorize_path=>"/oauth/example/authorize.php"
|
48
|
+
# @consumer = OAuth::Consumer.new(key, secret, {
|
49
|
+
# :site => "http://term.ie",
|
50
|
+
# :scheme => :header,
|
51
|
+
# :http_method => :post,
|
52
|
+
# :request_token_path => "/oauth/example/request_token.php",
|
53
|
+
# :access_token_path => "/oauth/example/access_token.php",
|
54
|
+
# :authorize_path => "/oauth/example/authorize.php"
|
44
55
|
# })
|
45
56
|
#
|
46
57
|
# Start the process by requesting a token
|
47
58
|
#
|
48
|
-
# @request_token
|
49
|
-
# session[:request_token]
|
59
|
+
# @request_token = @consumer.get_request_token
|
60
|
+
# session[:request_token] = @request_token
|
50
61
|
# redirect_to @request_token.authorize_url
|
51
62
|
#
|
52
63
|
# When user returns create an access_token
|
53
64
|
#
|
54
|
-
# @access_token
|
65
|
+
# @access_token = @request_token.get_access_token
|
55
66
|
# @photos=@access_token.get('/photos.xml')
|
56
67
|
#
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
def initialize(consumer_key, consumer_secret, options = {})
|
69
|
+
@key = consumer_key
|
70
|
+
@secret = consumer_secret
|
71
|
+
|
60
72
|
# ensure that keys are symbols
|
61
|
-
@options
|
73
|
+
@options = @@default_options.merge(options.inject({}) { |options, (key, value)|
|
62
74
|
options[key.to_sym] = value
|
63
75
|
options
|
64
|
-
|
65
|
-
@key = consumer_key
|
66
|
-
@secret = consumer_secret
|
76
|
+
})
|
67
77
|
end
|
68
|
-
|
78
|
+
|
69
79
|
# The default http method
|
70
80
|
def http_method
|
71
|
-
@http_method
|
81
|
+
@http_method ||= @options[:http_method] || :post
|
72
82
|
end
|
73
|
-
|
83
|
+
|
74
84
|
# The HTTP object for the site. The HTTP Object is what you get when you do Net::HTTP.new
|
75
85
|
def http
|
76
86
|
@http ||= create_http
|
77
87
|
end
|
78
|
-
|
88
|
+
|
79
89
|
# Contains the root URI for this site
|
80
|
-
def uri(custom_uri=nil)
|
90
|
+
def uri(custom_uri = nil)
|
81
91
|
if custom_uri
|
82
|
-
@uri
|
92
|
+
@uri = custom_uri
|
83
93
|
@http = create_http # yike, oh well. less intrusive this way
|
84
94
|
else # if no custom passed, we use existing, which, if unset, is set to site uri
|
85
95
|
@uri ||= URI.parse(site)
|
86
96
|
end
|
87
97
|
end
|
88
|
-
|
98
|
+
|
89
99
|
# Makes a request to the service for a new OAuth::RequestToken
|
90
|
-
#
|
91
|
-
# @request_token=@consumer.get_request_token
|
92
100
|
#
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
# @request_token = @consumer.get_request_token
|
102
|
+
#
|
103
|
+
def get_request_token(request_options = {}, *arguments)
|
104
|
+
response = token_request(http_method, (request_token_url? ? request_token_url : request_token_path), nil, request_options, *arguments)
|
105
|
+
OAuth::RequestToken.new(self, response[:oauth_token], response[:oauth_token_secret])
|
96
106
|
end
|
97
|
-
|
107
|
+
|
98
108
|
# Creates, signs and performs an http request.
|
99
109
|
# It's recommended to use the OAuth::Token classes to set this up correctly.
|
100
110
|
# The arguments parameters are a hash or string encoded set of parameters if it's a post request as well as optional http headers.
|
101
|
-
#
|
102
|
-
# @consumer.request(:get,'/people',@token,{:scheme=>:query_string})
|
103
|
-
# @consumer.request(:post,'/people',@token,{},@person.to_xml,{ 'Content-Type' => 'application/xml' })
|
104
111
|
#
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
+
# @consumer.request(:get, '/people', @token, { :scheme => :query_string })
|
113
|
+
# @consumer.request(:post, '/people', @token, {}, @person.to_xml, { 'Content-Type' => 'application/xml' })
|
114
|
+
#
|
115
|
+
def request(http_method, path, token = nil, request_options = {}, *arguments)
|
116
|
+
if path !~ /^\//
|
117
|
+
@http = create_http(path)
|
118
|
+
_uri = URI.parse(path)
|
119
|
+
path = "#{_uri.path}#{_uri.query ? "?#{_uri.query}" : ""}"
|
120
|
+
end
|
121
|
+
|
122
|
+
rsp = http.request(create_signed_request(http_method, path, token, request_options, *arguments))
|
123
|
+
|
124
|
+
# check for an error reported by the Problem Reporting extension
|
125
|
+
# (http://wiki.oauth.net/ProblemReporting)
|
126
|
+
# note: a 200 may actually be an error; check for an oauth_problem key to be sure
|
127
|
+
if !(headers = rsp.to_hash["www-authenticate"]).nil? &&
|
128
|
+
(h = headers.select { |h| h =~ /^OAuth / }).any? &&
|
129
|
+
h.first =~ /oauth_problem/
|
130
|
+
|
131
|
+
# puts "Header: #{h.first}"
|
132
|
+
|
133
|
+
# TODO doesn't handle broken responses from api.login.yahoo.com
|
134
|
+
# remove debug code when done
|
135
|
+
params = OAuth::Helper.parse_header(h.first)
|
136
|
+
|
137
|
+
# puts "Params: #{params.inspect}"
|
138
|
+
# puts "Body: #{rsp.body}"
|
139
|
+
|
140
|
+
raise OAuth::Problem.new(params.delete("oauth_problem"), rsp, params)
|
112
141
|
end
|
113
|
-
|
142
|
+
|
143
|
+
rsp
|
114
144
|
end
|
115
|
-
|
145
|
+
|
116
146
|
# Creates and signs an http request.
|
117
147
|
# It's recommended to use the Token classes to set this up correctly
|
118
|
-
def create_signed_request(http_method,path, token=nil,request_options={}
|
119
|
-
request=create_http_request(http_method,path
|
120
|
-
sign!(request,token,request_options)
|
148
|
+
def create_signed_request(http_method, path, token = nil, request_options = {}, *arguments)
|
149
|
+
request = create_http_request(http_method, path, *arguments)
|
150
|
+
sign!(request, token, request_options)
|
121
151
|
request
|
122
152
|
end
|
123
|
-
|
153
|
+
|
124
154
|
# Creates a request and parses the result as url_encoded. This is used internally for the RequestToken and AccessToken requests.
|
125
|
-
def token_request(http_method,path,token=nil,request_options={}
|
126
|
-
response=request(http_method,path,token,request_options
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
155
|
+
def token_request(http_method, path, token = nil, request_options = {}, *arguments)
|
156
|
+
response = request(http_method, path, token, request_options, *arguments)
|
157
|
+
|
158
|
+
case response.code.to_i
|
159
|
+
|
160
|
+
when (200..299)
|
161
|
+
CGI.parse(response.body).inject({}) { |h,(k,v)| h[k.to_sym] = v.first; h }
|
162
|
+
when (300..399)
|
163
|
+
# this is a redirect
|
164
|
+
response.error!
|
165
|
+
when (400..499)
|
166
|
+
raise OAuth::Unauthorized, response
|
167
|
+
else
|
168
|
+
response.error!
|
131
169
|
end
|
132
170
|
end
|
133
171
|
|
134
172
|
# Sign the Request object. Use this if you have an externally generated http request object you want to sign.
|
135
|
-
def sign!(request,token=nil, request_options = {})
|
173
|
+
def sign!(request, token = nil, request_options = {})
|
136
174
|
request.oauth!(http, self, token, options.merge(request_options))
|
137
175
|
end
|
138
|
-
|
176
|
+
|
139
177
|
# Return the signature_base_string
|
140
|
-
def signature_base_string(request,token=nil, request_options = {})
|
178
|
+
def signature_base_string(request, token = nil, request_options = {})
|
141
179
|
request.signature_base_string(http, self, token, options.merge(request_options))
|
142
180
|
end
|
143
181
|
|
@@ -148,90 +186,106 @@ module OAuth
|
|
148
186
|
def scheme
|
149
187
|
@options[:scheme]
|
150
188
|
end
|
151
|
-
|
189
|
+
|
152
190
|
def request_token_path
|
153
191
|
@options[:request_token_path]
|
154
192
|
end
|
155
|
-
|
193
|
+
|
156
194
|
def authorize_path
|
157
195
|
@options[:authorize_path]
|
158
196
|
end
|
159
|
-
|
197
|
+
|
160
198
|
def access_token_path
|
161
199
|
@options[:access_token_path]
|
162
200
|
end
|
163
|
-
|
201
|
+
|
164
202
|
# TODO this is ugly, rewrite
|
165
203
|
def request_token_url
|
166
|
-
@options[:request_token_url]||site+request_token_path
|
204
|
+
@options[:request_token_url] || site + request_token_path
|
167
205
|
end
|
168
206
|
|
169
207
|
def request_token_url?
|
170
|
-
@options
|
208
|
+
@options.has_key?(:request_token_url)
|
171
209
|
end
|
172
|
-
|
210
|
+
|
173
211
|
def authorize_url
|
174
|
-
@options[:authorize_url]||site+authorize_path
|
212
|
+
@options[:authorize_url] || site + authorize_path
|
175
213
|
end
|
176
|
-
|
214
|
+
|
177
215
|
def authorize_url?
|
178
|
-
@options
|
216
|
+
@options.has_key?(:authorize_url)
|
179
217
|
end
|
180
218
|
|
181
219
|
def access_token_url
|
182
|
-
@options[:access_token_url]||site+access_token_path
|
220
|
+
@options[:access_token_url] || site + access_token_path
|
183
221
|
end
|
184
222
|
|
185
223
|
def access_token_url?
|
186
|
-
@options
|
224
|
+
@options.has_key?(:access_token_url)
|
187
225
|
end
|
188
226
|
|
189
|
-
|
190
|
-
|
191
|
-
#Instantiates the http object
|
192
|
-
def create_http(_url=nil)
|
193
|
-
if _url.nil
|
194
|
-
our_uri=URI.parse(site)
|
227
|
+
protected
|
228
|
+
|
229
|
+
# Instantiates the http object
|
230
|
+
def create_http(_url = nil)
|
231
|
+
if _url.nil? || _url[0] =~ /^\//
|
232
|
+
our_uri = URI.parse(site)
|
195
233
|
else
|
196
|
-
our_uri=URI.parse(_url)
|
234
|
+
our_uri = URI.parse(_url)
|
197
235
|
end
|
198
|
-
|
199
|
-
http_object
|
236
|
+
|
237
|
+
http_object = Net::HTTP.new(our_uri.host, our_uri.port)
|
238
|
+
|
239
|
+
http_object.use_ssl = (our_uri.scheme == 'https')
|
240
|
+
|
241
|
+
if CA_FILE
|
242
|
+
http_object.ca_file = CA_FILE
|
243
|
+
http_object.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
244
|
+
http_object.verify_depth = 5
|
245
|
+
else
|
246
|
+
http_object.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
247
|
+
end
|
248
|
+
|
200
249
|
http_object
|
201
250
|
end
|
202
|
-
|
251
|
+
|
203
252
|
# create the http request object for a given http_method and path
|
204
|
-
def create_http_request(http_method,path
|
205
|
-
http_method=http_method.to_sym
|
206
|
-
|
207
|
-
|
253
|
+
def create_http_request(http_method, path, *arguments)
|
254
|
+
http_method = http_method.to_sym
|
255
|
+
|
256
|
+
if [:post, :put].include?(http_method)
|
257
|
+
data = arguments.shift
|
208
258
|
end
|
209
|
-
|
259
|
+
|
260
|
+
headers = arguments.first.is_a?(Hash) ? arguments.shift : {}
|
261
|
+
|
210
262
|
case http_method
|
211
263
|
when :post
|
212
|
-
request=Net::HTTP::Post.new(path,headers)
|
213
|
-
request["Content-Length"]=0 # Default to 0
|
264
|
+
request = Net::HTTP::Post.new(path,headers)
|
265
|
+
request["Content-Length"] = 0 # Default to 0
|
214
266
|
when :put
|
215
|
-
request=Net::HTTP::Put.new(path,headers)
|
216
|
-
request["Content-Length"]=0 # Default to 0
|
267
|
+
request = Net::HTTP::Put.new(path,headers)
|
268
|
+
request["Content-Length"] = 0 # Default to 0
|
217
269
|
when :get
|
218
|
-
request=Net::HTTP::Get.new(path,headers)
|
270
|
+
request = Net::HTTP::Get.new(path,headers)
|
219
271
|
when :delete
|
220
|
-
request=Net::HTTP::Delete.new(path,headers)
|
272
|
+
request = Net::HTTP::Delete.new(path,headers)
|
221
273
|
when :head
|
222
|
-
request=Net::HTTP::Head.new(path,headers)
|
274
|
+
request = Net::HTTP::Head.new(path,headers)
|
223
275
|
else
|
224
276
|
raise ArgumentError, "Don't know how to handle http_method: :#{http_method.to_s}"
|
225
277
|
end
|
278
|
+
|
226
279
|
if data.is_a?(Hash)
|
227
280
|
request.set_form_data(data)
|
228
281
|
elsif data
|
229
|
-
request.body=data.to_s
|
230
|
-
request["Content-Length"]=request.body.length
|
282
|
+
request.body = data.to_s
|
283
|
+
request["Content-Length"] = request.body.length
|
231
284
|
end
|
285
|
+
|
232
286
|
request
|
233
287
|
end
|
234
|
-
|
288
|
+
|
235
289
|
# Unset cached http instance because it cannot be marshalled when
|
236
290
|
# it has already been used and use_ssl is set to true
|
237
291
|
def marshal_dump(*args)
|