Sha256: 89e4280d7ab8ea39d9534e1ead19b70f3e23b662ac881bceed64ca1042f4fecf

Contents?: true

Size: 1.5 KB

Versions: 11

Compression:

Stored size: 1.5 KB

Contents

require 'oauth/request_proxy/base'
require 'net/http'
require 'uri'
require 'cgi'

module OAuth::RequestProxy::Net
  module HTTP
    class HTTPRequest < OAuth::RequestProxy::Base
      proxies ::Net::HTTPRequest

      def method
        request.method
      end

      def uri
        uri = options[:uri]
        uri.to_s
      end

      def parameters
        if options[:clobber_request]
          options[:parameters]
        else
          all_parameters
        end
      end

      private

      def all_parameters
        request_params = CGI.parse(query_string)
        if options[:parameters]
          options[:parameters].each do |k,v|
            if request_params.has_key?(k)
              request_params[k] << v
            else
              request_params[k] = [v].flatten
            end
          end
        end
        request_params
      end

      def query_string
        params = [ query_params, auth_header_params ]
        is_form_urlencoded = request['Content-Type'] != nil && request['Content-Type'].downcase == 'application/x-www-form-urlencoded'
        params << post_params if method.to_s.upcase == 'POST' && is_form_urlencoded
        params.compact.join('&')
      end
      
      def query_params
        URI.parse(request.path).query
      end

      def post_params
        request.body
      end

      def auth_header_params
        return nil unless request['Authorization'] && request['Authorization'][0,5] == 'OAuth'
        auth_params = request['Authorization']
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
monkeyhelper-oauth-0.3.1 lib/oauth/request_proxy/net_http.rb
pelle-oauth-0.3.0 lib/oauth/request_proxy/net_http.rb
pelle-oauth-0.3.1 lib/oauth/request_proxy/net_http.rb
proletarian-oauth-0.3.2 lib/oauth/request_proxy/net_http.rb
proletarian-oauth-0.3.3 lib/oauth/request_proxy/net_http.rb
proletarian-oauth-0.3.4 lib/oauth/request_proxy/net_http.rb
proletarian-oauth-0.3.5 lib/oauth/request_proxy/net_http.rb
proletarian-oauth-0.3.6 lib/oauth/request_proxy/net_http.rb
proletarian-oauth-0.3.7 lib/oauth/request_proxy/net_http.rb
oauth-0.3.0 lib/oauth/request_proxy/net_http.rb
oauth-0.3.1 lib/oauth/request_proxy/net_http.rb