Sha256: 423e7ddf1c73a42fc5ed7f0c58a8f4aeef01594335af522cac7042c0b0fe6b5d

Contents?: true

Size: 1.5 KB

Versions: 38

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

38 entries across 38 versions & 16 rubygems

Version Path
greut-oauth-0.3.6 lib/oauth/request_proxy/net_http.rb
jwhitmire-oauth-0.3.6.1 lib/oauth/request_proxy/net_http.rb
metavida-oauth-0.3.2.1 lib/oauth/request_proxy/net_http.rb
metavida-oauth-0.3.2 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.1 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.2 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.3 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.4 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.5 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.6 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.7 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.1.8 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.2.1 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.2.2 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.2 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.3 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.4.1 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.4 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.5 lib/oauth/request_proxy/net_http.rb
mojodna-oauth-0.3.6 lib/oauth/request_proxy/net_http.rb