Class: Nervion::OAuthHeader
- Inherits:
-
Object
- Object
- Nervion::OAuthHeader
- Defined in:
- lib/nervion/oauth_header.rb
Constant Summary collapse
- PARAMETERS_INCLUDED =
%w{ oauth_consumer_key oauth_nonce oauth_signature oauth_signature_method oauth_timestamp oauth_token oauth_version }
Class Method Summary collapse
Instance Method Summary collapse
- #consumer_key ⇒ Object
- #consumer_secret ⇒ Object
-
#initialize(http_method, base_url, params, oauth_params) ⇒ OAuthHeader
constructor
A new instance of OAuthHeader.
- #nonce ⇒ Object
- #oauth_info ⇒ Object
- #secrets ⇒ Object
- #signature ⇒ Object
- #signature_method ⇒ Object
- #timestamp ⇒ Object
- #to_s ⇒ Object
- #token ⇒ Object
- #token_secret ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(http_method, base_url, params, oauth_params) ⇒ OAuthHeader
Returns a new instance of OAuthHeader.
13 14 15 16 |
# File 'lib/nervion/oauth_header.rb', line 13 def initialize(http_method, base_url, params, oauth_params) @http_method, @base_url = http_method, base_url @params, @oauth_params = params, oauth_params end |
Class Method Details
.for(request) ⇒ Object
9 10 11 |
# File 'lib/nervion/oauth_header.rb', line 9 def self.for(request) new(request.http_method, request.uri, request.params, request.oauth_params).to_s end |
Instance Method Details
#consumer_key ⇒ Object
33 34 35 |
# File 'lib/nervion/oauth_header.rb', line 33 def consumer_key @oauth_params[:consumer_key] end |
#consumer_secret ⇒ Object
37 38 39 |
# File 'lib/nervion/oauth_header.rb', line 37 def consumer_secret @oauth_params[:consumer_secret] end |
#nonce ⇒ Object
49 50 51 |
# File 'lib/nervion/oauth_header.rb', line 49 def nonce Digest::MD5.hexdigest "#{consumer_key}#{token}#{}" end |
#oauth_info ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/nervion/oauth_header.rb', line 69 def oauth_info { oauth_consumer_key: consumer_key, oauth_nonce: nonce, oauth_signature_method: signature_method, oauth_timestamp: , oauth_token: token, oauth_version: version } end |
#secrets ⇒ Object
80 81 82 83 84 85 |
# File 'lib/nervion/oauth_header.rb', line 80 def secrets { consumer_secret: consumer_secret, access_token_secret: token_secret } end |
#signature ⇒ Object
65 66 67 |
# File 'lib/nervion/oauth_header.rb', line 65 def signature OAuthSignature.for @http_method, @base_url, @params, oauth_info, secrets end |
#signature_method ⇒ Object
57 58 59 |
# File 'lib/nervion/oauth_header.rb', line 57 def signature_method 'HMAC-SHA1' end |
#timestamp ⇒ Object
53 54 55 |
# File 'lib/nervion/oauth_header.rb', line 53 def Time.now.to_i.to_s end |
#to_s ⇒ Object
26 27 28 29 30 31 |
# File 'lib/nervion/oauth_header.rb', line 26 def to_s 'OAuth ' << PARAMETERS_INCLUDED.map do |param| method_name = param.gsub /^oauth_/, '' "#{param}=\"#{PercentEncoder.encode(send(method_name))}\"" end.join(', ') end |
#token ⇒ Object
41 42 43 |
# File 'lib/nervion/oauth_header.rb', line 41 def token @oauth_params[:access_token] end |
#token_secret ⇒ Object
45 46 47 |
# File 'lib/nervion/oauth_header.rb', line 45 def token_secret @oauth_params[:access_token_secret] end |
#version ⇒ Object
61 62 63 |
# File 'lib/nervion/oauth_header.rb', line 61 def version '1.0' end |