Class: Nervion::OAuthSignature

Inherits:
Object
  • Object
show all
Defined in:
lib/nervion/oauth_signature.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_method, base_url, params, oauth_params, secrets) ⇒ OAuthSignature

Returns a new instance of OAuthSignature.



12
13
14
15
16
17
18
# File 'lib/nervion/oauth_signature.rb', line 12

def initialize(http_method, base_url, params, oauth_params, secrets)
  @http_method = http_method
  @base_url = base_url
  @params = params
  @oauth_params = oauth_params
  @secrets = secrets
end

Class Method Details

.for(http_method, base_url, params, oauth_params, secrets) ⇒ Object



8
9
10
# File 'lib/nervion/oauth_signature.rb', line 8

def self.for(http_method, base_url, params, oauth_params, secrets)
  new(http_method, base_url, params, oauth_params, secrets).to_s
end

Instance Method Details

#base_stringObject



28
29
30
# File 'lib/nervion/oauth_signature.rb', line 28

def base_string
  join @http_method.upcase, encode(@base_url), encode(parameter_string)
end

#encode_pair(key, value) ⇒ Object



36
37
38
# File 'lib/nervion/oauth_signature.rb', line 36

def encode_pair(key, value)
  [encode(key.to_s), encode(value.to_s)].join '='
end

#parameter_stringObject



32
33
34
# File 'lib/nervion/oauth_signature.rb', line 32

def parameter_string
  join signed_params.sort.map { |param_value| encode_pair *param_value }
end

#signing_keyObject



24
25
26
# File 'lib/nervion/oauth_signature.rb', line 24

def signing_key
  join @secrets[:consumer_secret], @secrets[:access_token_secret]
end

#to_sObject



20
21
22
# File 'lib/nervion/oauth_signature.rb', line 20

def to_s
  Base64.encode64(OpenSSL::HMAC.digest('SHA1', signing_key, base_string)).chomp
end