Class: OAuth::Client::Helper
Instance Method Summary
collapse
Methods included from Helper
#escape, #generate_key, #generate_timestamp, #normalize, #normalize_nested_query, #parse_header, #stringify_keys, #unescape
Constructor Details
#initialize(request, options = {}) ⇒ Helper
Returns a new instance of Helper.
11
12
13
14
15
|
# File 'lib/oauth/client/helper.rb', line 11
def initialize(request, options = {})
@request = request
@options = options
@options[:signature_method] ||= 'HMAC-SHA1'
end
|
Instance Method Details
63
64
65
66
67
68
69
70
71
|
# File 'lib/oauth/client/helper.rb', line 63
def ()
@oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
if ['User-Agent'] && ['User-Agent'] != 'Ruby'
['User-Agent'] += " (#{@oauth_ua_string})"
else
['User-Agent'] = @oauth_ua_string
end
end
|
#hash_body ⇒ Object
59
60
61
|
# File 'lib/oauth/client/helper.rb', line 59
def hash_body
@options[:body_hash] = OAuth::Signature.body_hash(@request, :parameters => oauth_parameters)
end
|
73
74
75
76
77
78
79
80
81
|
# File 'lib/oauth/client/helper.rb', line 73
def
parameters = oauth_parameters
parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))
= parameters.sort.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')
realm = "realm=\"#{options[:realm]}\", " if options[:realm]
"OAuth #{realm}#{}"
end
|
21
22
23
|
# File 'lib/oauth/client/helper.rb', line 21
def nonce
options[:nonce] ||= generate_key
end
|
#oauth_parameters ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/oauth/client/helper.rb', line 29
def oauth_parameters
{
'oauth_body_hash' => options[:body_hash],
'oauth_callback' => options[:oauth_callback],
'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_verifier' => options[:oauth_verifier],
'oauth_version' => (options[:oauth_version] || '1.0'),
'oauth_session_handle' => options[:oauth_session_handle]
}.reject { |k,v| v.to_s == "" }
end
|
17
18
19
|
# File 'lib/oauth/client/helper.rb', line 17
def options
@options
end
|
#parameters ⇒ Object
83
84
85
|
# File 'lib/oauth/client/helper.rb', line 83
def parameters
OAuth::RequestProxy.proxy(@request).parameters
end
|
#parameters_with_oauth ⇒ Object
87
88
89
|
# File 'lib/oauth/client/helper.rb', line 87
def parameters_with_oauth
oauth_parameters.merge(parameters)
end
|
#signature(extra_options = {}) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/oauth/client/helper.rb', line 44
def signature( = {})
OAuth::Signature.sign(@request, { :uri => options[:request_uri],
:consumer => options[:consumer],
:token => options[:token],
:unsigned_parameters => options[:unsigned_parameters]
}.merge() )
end
|
#signature_base_string(extra_options = {}) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/oauth/client/helper.rb', line 52
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
25
26
27
|
# File 'lib/oauth/client/helper.rb', line 25
def timestamp
options[:timestamp] ||= generate_timestamp
end
|