Class: OAuth::RequestProxy::Base
- Inherits:
-
Object
- Object
- OAuth::RequestProxy::Base
show all
- Includes:
- Helper
- Defined in:
- lib/oauth/request_proxy/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helper
#escape, #generate_key, #generate_timestamp, #normalize, #parse_header, #unescape
Constructor Details
#initialize(request, options = {}) ⇒ Base
Returns a new instance of Base.
14
15
16
17
|
# File 'lib/oauth/request_proxy/base.rb', line 14
def initialize(request, options = {})
@request = request
@options = options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
12
13
14
|
# File 'lib/oauth/request_proxy/base.rb', line 12
def options
@options
end
|
#request ⇒ Object
Returns the value of attribute request.
12
13
14
|
# File 'lib/oauth/request_proxy/base.rb', line 12
def request
@request
end
|
Instance Method Details
#non_oauth_parameters ⇒ Object
85
86
87
|
# File 'lib/oauth/request_proxy/base.rb', line 85
def non_oauth_parameters
parameters.reject { |k,v| OAuth::PARAMETERS.include?(k) }
end
|
#normalized_parameters ⇒ Object
See 9.1.1. in specs Normalize Request Parameters
96
97
98
|
# File 'lib/oauth/request_proxy/base.rb', line 96
def normalized_parameters
normalize(parameters_for_signature)
end
|
#normalized_uri ⇒ Object
90
91
92
93
|
# File 'lib/oauth/request_proxy/base.rb', line 90
def normalized_uri
u = URI.parse(uri)
"#{u.scheme.downcase}://#{u.host.downcase}#{(u.scheme.downcase == 'http' && u.port != 80) || (u.scheme.downcase == 'https' && u.port != 443) ? ":#{u.port}" : ""}#{(u.path && u.path != '') ? u.path : '/'}"
end
|
#oauth_callback ⇒ Object
21
22
23
|
# File 'lib/oauth/request_proxy/base.rb', line 21
def oauth_callback
parameters['oauth_callback']
end
|
#oauth_consumer_key ⇒ Object
Also known as:
consumer_key
25
26
27
|
# File 'lib/oauth/request_proxy/base.rb', line 25
def oauth_consumer_key
parameters['oauth_consumer_key']
end
|
Authorization header for OAuth
137
138
139
140
141
142
|
# File 'lib/oauth/request_proxy/base.rb', line 137
def (options = {})
= oauth_parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
realm = "realm=\"#{options[:realm]}\", " if options[:realm]
"OAuth #{realm}#{}"
end
|
#oauth_nonce ⇒ Object
Also known as:
nonce
29
30
31
|
# File 'lib/oauth/request_proxy/base.rb', line 29
def oauth_nonce
parameters['oauth_nonce']
end
|
#oauth_parameters ⇒ Object
81
82
83
|
# File 'lib/oauth/request_proxy/base.rb', line 81
def oauth_parameters
parameters.select { |k,v| OAuth::PARAMETERS.include?(k) }.reject { |k,v| v == "" }
end
|
#oauth_signature ⇒ Object
Also known as:
signature
33
34
35
36
|
# File 'lib/oauth/request_proxy/base.rb', line 33
def oauth_signature
parameters['oauth_signature'] || ""
end
|
#oauth_signature_method ⇒ Object
Also known as:
signature_method
38
39
40
41
42
43
44
45
|
# File 'lib/oauth/request_proxy/base.rb', line 38
def oauth_signature_method
case parameters['oauth_signature_method']
when Array
parameters['oauth_signature_method'].first
else
parameters['oauth_signature_method']
end
end
|
#oauth_timestamp ⇒ Object
Also known as:
timestamp
47
48
49
|
# File 'lib/oauth/request_proxy/base.rb', line 47
def oauth_timestamp
parameters['oauth_timestamp']
end
|
#oauth_token ⇒ Object
Also known as:
token
51
52
53
|
# File 'lib/oauth/request_proxy/base.rb', line 51
def oauth_token
parameters['oauth_token']
end
|
#oauth_verifier ⇒ Object
55
56
57
|
# File 'lib/oauth/request_proxy/base.rb', line 55
def oauth_verifier
parameters['oauth_verifier']
end
|
#oauth_version ⇒ Object
59
60
61
|
# File 'lib/oauth/request_proxy/base.rb', line 59
def oauth_version
parameters["oauth_version"]
end
|
#parameters ⇒ Object
73
74
75
|
# File 'lib/oauth/request_proxy/base.rb', line 73
def parameters
raise NotImplementedError, "Must be implemented by subclasses"
end
|
#parameters_for_signature ⇒ Object
77
78
79
|
# File 'lib/oauth/request_proxy/base.rb', line 77
def parameters_for_signature
parameters.reject { |k,v| k == "oauth_signature" }
end
|
#sign(options = {}) ⇒ Object
100
101
102
|
# File 'lib/oauth/request_proxy/base.rb', line 100
def sign(options = {})
OAuth::Signature.sign(self, options)
end
|
#sign!(options = {}) ⇒ Object
104
105
106
107
108
|
# File 'lib/oauth/request_proxy/base.rb', line 104
def sign!(options = {})
parameters["oauth_signature"] = sign(options)
@signed = true
signature
end
|
#signature_base_string ⇒ Object
111
112
113
114
|
# File 'lib/oauth/request_proxy/base.rb', line 111
def signature_base_string
base = [method, normalized_uri, normalized_parameters]
base.map { |v| escape(v) }.join("&")
end
|
#signed? ⇒ Boolean
Has this request been signed yet?
117
118
119
|
# File 'lib/oauth/request_proxy/base.rb', line 117
def signed?
@signed
end
|
#signed_uri(with_oauth = true) ⇒ Object
URI, including OAuth parameters
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/oauth/request_proxy/base.rb', line 122
def signed_uri(with_oauth = true)
if signed?
if with_oauth
params = parameters
else
params = non_oauth_parameters
end
[uri, normalize(params)] * "?"
else
STDERR.puts "This request has not yet been signed!"
end
end
|