Class OAuth::Client::Helper
In: lib/oauth/client/helper.rb
Parent: Object

Methods

Included Modules

OAuth::Helper

Public Class methods

[Source]

# File lib/oauth/client/helper.rb, line 12
    def initialize(request, options = {})
      @request = request
      @options = options
      @options[:signature_method] ||= 'HMAC-SHA1'
    end

Public Instance methods

[Source]

# File lib/oauth/client/helper.rb, line 56
    def amend_user_agent_header(headers)
      @oauth_ua_string ||= "OAuth gem v#{OAuth::VERSION}"
      if headers['User-Agent']
        headers['User-Agent'] += " (#{@oauth_ua_string})"
      else
        headers['User-Agent'] = @oauth_ua_string
      end
    end

[Source]

# File lib/oauth/client/helper.rb, line 65
    def header
      parameters = oauth_parameters
      parameters.merge!('oauth_signature' => signature(options.merge(:parameters => parameters)))

      header_params_str = parameters.map { |k,v| "#{k}=\"#{escape(v)}\"" }.join(', ')

      realm = "realm=\"#{options[:realm]}\", " if options[:realm]
      "OAuth #{realm}#{header_params_str}"
    end

[Source]

# File lib/oauth/client/helper.rb, line 22
    def nonce
      options[:nonce] ||= generate_key
    end

[Source]

# File lib/oauth/client/helper.rb, line 30
    def oauth_parameters
      {
        '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'          => '1.0'
      }.reject { |k,v| v.to_s == "" }
    end

[Source]

# File lib/oauth/client/helper.rb, line 18
    def options
      @options
    end

[Source]

# File lib/oauth/client/helper.rb, line 75
    def parameters
      OAuth::RequestProxy.proxy(@request).parameters
    end

[Source]

# File lib/oauth/client/helper.rb, line 79
    def parameters_with_oauth
      oauth_parameters.merge(parameters)
    end

[Source]

# File lib/oauth/client/helper.rb, line 43
    def signature(extra_options = {})
      OAuth::Signature.sign(@request, { :uri      => options[:request_uri],
                                        :consumer => options[:consumer],
                                        :token    => options[:token] }.merge(extra_options) )
    end

[Source]

# File lib/oauth/client/helper.rb, line 49
    def signature_base_string(extra_options = {})
      OAuth::Signature.signature_base_string(@request, { :uri        => options[:request_uri],
                                                         :consumer   => options[:consumer],
                                                         :token      => options[:token],
                                                         :parameters => oauth_parameters}.merge(extra_options) )
    end

[Source]

# File lib/oauth/client/helper.rb, line 26
    def timestamp
      options[:timestamp] ||= generate_timestamp
    end

[Validate]