Sha256: 9ef2c09fc70e65f79b73cf95f77a72eea9c992fb313dbd0fc1c24f7850b7fc5b

Contents?: true

Size: 1.63 KB

Versions: 4

Compression:

Stored size: 1.63 KB

Contents

require 'active_support'
require 'action_controller/request'
require 'oauth/request_proxy/base'
require 'uri'

module OAuth::RequestProxy
  class ActionControllerRequest < OAuth::RequestProxy::Base
    proxies(defined?(ActionController::AbstractRequest) ? ActionController::AbstractRequest : ActionController::Request)

    def method
      request.method.to_s.upcase
    end

    def uri
      request.url
    end

    def parameters
      if options[:clobber_request]
        options[:parameters] || {}
      else
        params = request_params.merge(query_params).merge(header_params)
        params.stringify_keys! if params.respond_to?(:stringify_keys!)
        params.merge(options[:parameters] || {})
      end
    end

    # Override from OAuth::RequestProxy::Base to avoid roundtrip
    # conversion to Hash or Array and thus preserve the original
    # parameter names
    def parameters_for_signature
      params = []
      params << options[:parameters].to_query if options[:parameters]

      unless options[:clobber_request]
        params << header_params.to_query
        params << request.query_string unless request.query_string.blank?
        if request.post? && request.content_type == Mime::Type.lookup("application/x-www-form-urlencoded")
          params << request.raw_post
        end
      end

      params.
        join('&').split('&').
        reject(&:blank?).
        map { |p| p.split('=').map{|esc| CGI.unescape(esc)} }.
        reject { |kv| kv[0] == 'oauth_signature'}
    end

  protected

    def query_params
      request.query_parameters
    end

    def request_params
      request.request_parameters
    end

  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
mojodna-oauth-0.3.4.1 lib/oauth/request_proxy/action_controller_request.rb
mojodna-oauth-0.3.4 lib/oauth/request_proxy/action_controller_request.rb
mzsanford-oauth-0.3.2.2 lib/oauth/request_proxy/action_controller_request.rb
oauth-0.3.4 lib/oauth/request_proxy/action_controller_request.rb