Sha256: 146fec0cd079eacab54bf2528bbc75a51c593763783fb4b7f068680f634c7f5f

Contents?: true

Size: 1.32 KB

Versions: 13

Compression:

Stored size: 1.32 KB

Contents

require 'oauth/request_proxy/base'
require 'rest-client'
require 'uri'
require 'cgi'

module OAuth::RequestProxy::RestClient
  class Request < OAuth::RequestProxy::Base
    proxies RestClient::Request
    
      def method
        request.method.to_s.upcase
      end

      def uri
        request.url
      end

      def parameters
        if options[:clobber_request]
          options[:parameters] || {}
        else
          post_parameters.merge(query_params).merge(options[:parameters] || {})
        end
      end

    protected

      def query_params
        query = URI.parse(request.url).query
        query ? CGI.parse(query) : {}
      end

      def request_params
      end
      
      def post_parameters
        # Post params are only used if posting form data
        if method == 'POST' || method == 'PUT'
          OAuth::Helper.stringify_keys(query_string_to_hash(request.payload.to_s) || {})
        else
          {}
        end
      end
      
   private
      
      def query_string_to_hash(query)
        keyvals = query.split('&').inject({}) do |result, q| 
          k,v = q.split('=')
          if !v.nil?
             result.merge({k => v})
          elsif !result.key?(k)
            result.merge({k => true})
          else
            result
          end
        end
        keyvals
      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/rest_client_request.rb
oauth-0.5.6 lib/oauth/request_proxy/rest_client_request.rb
oauth-0.5.5 lib/oauth/request_proxy/rest_client_request.rb
tdiary-5.0.8 vendor/bundle/gems/oauth-0.5.4/lib/oauth/request_proxy/rest_client_request.rb
oauth-0.5.4 lib/oauth/request_proxy/rest_client_request.rb
tdiary-5.0.5 vendor/bundle/gems/oauth-0.5.3/lib/oauth/request_proxy/rest_client_request.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/oauth-0.5.1/lib/oauth/request_proxy/rest_client_request.rb
tdiary-5.0.5 vendor/bundle/gems/oauth-0.5.1/lib/oauth/request_proxy/rest_client_request.rb
oauth-0.5.3 lib/oauth/request_proxy/rest_client_request.rb
oauth-0.5.2 lib/oauth/request_proxy/rest_client_request.rb
tdiary-5.0.4 vendor/bundle/gems/oauth-0.5.1/lib/oauth/request_proxy/rest_client_request.rb
oauth-0.5.1 lib/oauth/request_proxy/rest_client_request.rb
oauth-0.5.0 lib/oauth/request_proxy/rest_client_request.rb