Sha256: 1da0430582e3338de729aff04e3ead7a96b16ebfafe2166ac4aa74855e250cd4

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

  require 'oauth/request_proxy/base'
require 'curb'
require 'uri'
require 'cgi'

module OAuth::RequestProxy::Curl
  class Easy < OAuth::RequestProxy::Base
    # Proxy for signing Curl::Easy requests
    # Usage example:
    # oauth_params = {:consumer => oauth_consumer, :token => access_token}
    # req = Curl::Easy.new(uri)
    # oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => uri))
    # req.headers.merge!({"Authorization" => oauth_helper.header})
    # req.http_get
    # response = req.body_str
    proxies ::Curl::Easy

    def method
      nil
    end

    def uri
      options[:uri].to_s
    end

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

    private

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

    def post_parameters
      post_body = {}

      # Post params are only used if posting form data
      if (request.headers['Content-Type'] && request.headers['Content-Type'].downcase == 'application/x-www-form-urlencoded')

        request.post_body.split("&").each do |str|
          param = str.split("=")
          post_body[param[0]] = param[1]
        end
      end
      post_body
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
sayso-oauth-0.4.4.001 lib/oauth/request_proxy/curb_request.rb
oauth-0.4.4 lib/oauth/request_proxy/curb_request.rb
oauth-0.4.3 lib/oauth/request_proxy/curb_request.rb