Method: OAuth::Signature::Base#initialize

Defined in:
lib/oauth/signature/base.rb

#initialize(request, options = {}, &block) ⇒ Base

Returns a new instance of Base.

Raises:

  • (TypeError)

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/oauth/signature/base.rb', line 34

def initialize(request, options = {}, &block)
  raise TypeError unless request.kind_of?(OAuth::RequestProxy::Base)
  @request = request
  @options = options

  ## consumer secret was determined beforehand

  @consumer_secret = options[:consumer].secret if options[:consumer]

  # presence of :consumer_secret option will override any Consumer that's provided
  @consumer_secret = options[:consumer_secret] if options[:consumer_secret]

  ## token secret was determined beforehand

  @token_secret = options[:token].secret if options[:token]

  # presence of :token_secret option will override any Token that's provided
  @token_secret = options[:token_secret] if options[:token_secret]

  # override secrets based on the values returned from the block (if any)
  if block_given?
    # consumer secret and token secret need to be looked up based on pieces of the request
    secrets = yield block.arity == 1 ? request : [token, consumer_key, nonce, request.timestamp]
    if secrets.is_a?(Array) && secrets.size == 2
      @token_secret = secrets[0]
      @consumer_secret = secrets[1]
    end
  end
end