Sha256: 8fc74b57e8076c7ce948ab201568d1be4d7eb3a769c5447b71d52ffd4ba088b4

Contents?: true

Size: 1.65 KB

Versions: 13

Compression:

Stored size: 1.65 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::HTTPGenericRequest

      def method
        request.method
      end

      def uri
        options[:uri].to_s
      end

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

      def body
        request.body
      end

    private

      def all_parameters
        request_params = CGI.parse(query_string)
        # request_params.each{|k,v| request_params[k] = [nil] if v == []}

        if options[:parameters]
          options[:parameters].each do |k,v|
            if request_params.has_key?(k) && v
              request_params[k] << v
            else
              request_params[k] = [v]
            end
          end
        end
        request_params
      end

      def query_string
        params = [ query_params, auth_header_params ]
        params << post_params if (method.to_s.upcase == 'POST' || method.to_s.upcase == 'PUT') && form_url_encoded?
        params.compact.join('&')
      end

      def form_url_encoded?
        request['Content-Type'] != nil && request['Content-Type'].to_s.downcase.start_with?('application/x-www-form-urlencoded')
      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'
        request['Authorization']
      end
    end
  end
end

Version data entries

13 entries across 11 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/oauth-0.5.6/lib/oauth/request_proxy/net_http.rb
oauth-0.5.6 lib/oauth/request_proxy/net_http.rb
oauth-0.5.5 lib/oauth/request_proxy/net_http.rb
tdiary-5.0.8 vendor/bundle/gems/oauth-0.5.4/lib/oauth/request_proxy/net_http.rb
oauth-0.5.4 lib/oauth/request_proxy/net_http.rb
tdiary-5.0.5 vendor/bundle/gems/oauth-0.5.1/lib/oauth/request_proxy/net_http.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/oauth-0.5.1/lib/oauth/request_proxy/net_http.rb
tdiary-5.0.5 vendor/bundle/gems/oauth-0.5.3/lib/oauth/request_proxy/net_http.rb
oauth-0.5.3 lib/oauth/request_proxy/net_http.rb
oauth-0.5.2 lib/oauth/request_proxy/net_http.rb
tdiary-5.0.4 vendor/bundle/gems/oauth-0.5.1/lib/oauth/request_proxy/net_http.rb
oauth-0.5.1 lib/oauth/request_proxy/net_http.rb
oauth-0.5.0 lib/oauth/request_proxy/net_http.rb