Class: OAuth::Client::Helper
- Inherits:
-
Object
- Object
- OAuth::Client::Helper
show all
- Includes:
- Helper
- Defined in:
- lib/oauth/client/helper.rb
Instance Method Summary
collapse
Methods included from Helper
#escape, #generate_key, #generate_timestamp, #normalize, #parse_header, #unescape
Constructor Details
#initialize(request, options = {}) ⇒ Helper
Returns a new instance of Helper.
12
13
14
15
16
|
# File 'lib/oauth/client/helper.rb', line 12
def initialize(request, options = {})
@request = request
@options = options
@options[:signature_method] ||= 'HMAC-SHA1'
end
|
Instance Method Details
54
55
56
57
58
59
60
61
|
# File 'lib/oauth/client/helper.rb', line 54
def ()
@oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
if ['User-Agent']
['User-Agent'] += " (#{@oauth_ua_string})"
else
['User-Agent'] = @oauth_ua_string
end
end
|
63
64
65
66
67
68
69
70
71
|
# File 'lib/oauth/client/helper.rb', line 63
def
parameters = oauth_parameters
parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))
= parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
realm = "realm=\"#{options[:realm]}\", " if options[:realm]
"OAuth #{realm}#{}"
end
|
#nonce ⇒ Object
22
23
24
|
# File 'lib/oauth/client/helper.rb', line 22
def nonce
options[:nonce] ||= generate_key
end
|
#oauth_parameters ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/oauth/client/helper.rb', line 30
def oauth_parameters
{
'oauth_consumer_key' => options[:consumer].key,
'oauth_token' => options[:token] ? options[:token].token : '',
'oauth_signature_method' => options[:signature_method],
'oauth_timestamp' => timestamp,
'oauth_nonce' => nonce,
'oauth_version' => '1.0'
}.reject { |k,v| v.to_s == "" }
end
|
#options ⇒ Object
18
19
20
|
# File 'lib/oauth/client/helper.rb', line 18
def options
@options
end
|
#parameters ⇒ Object
73
74
75
|
# File 'lib/oauth/client/helper.rb', line 73
def parameters
OAuth::RequestProxy.proxy(@request).parameters
end
|
#parameters_with_oauth ⇒ Object
77
78
79
|
# File 'lib/oauth/client/helper.rb', line 77
def parameters_with_oauth
oauth_parameters.merge(parameters)
end
|
#signature(extra_options = {}) ⇒ Object
41
42
43
44
45
|
# File 'lib/oauth/client/helper.rb', line 41
def signature( = {})
OAuth::Signature.sign(@request, { :uri => options[:request_uri],
:consumer => options[:consumer],
:token => options[:token] }.merge() )
end
|
#signature_base_string(extra_options = {}) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/oauth/client/helper.rb', line 47
def signature_base_string( = {})
OAuth::Signature.signature_base_string(@request, { :uri => options[:request_uri],
:consumer => options[:consumer],
:token => options[:token],
:parameters => oauth_parameters}.merge() )
end
|
#timestamp ⇒ Object
26
27
28
|
# File 'lib/oauth/client/helper.rb', line 26
def timestamp
options[:timestamp] ||= generate_timestamp
end
|