Sha256: 58f44d3b2eacf7087bdfce95501ebe4e72c0c381e0810fa5f92abbc31ce127b4

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'oauth'
require "addressable/uri"

class Hash
  def to_params
    uri = Addressable::URI.new
    uri.query_values = self 
    uri.query
  end
end

class Net::HTTPGenericRequest
  def oauth_body_hash_required?
    puts 'pac oac'

    return false
  end
end

class TwoPerformant
  class OAuth
    attr_accessor :access_token, :consumer

    def initialize(options, host)
      consumer = ::OAuth::Consumer.new(options[:consumer_token], options[:consumer_secret], {:site => host})
      @access_token = ::OAuth::AccessToken.new(consumer, options[:access_token], options[:access_secret])
      @headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }
    end

    def get(path, params_hash) 
      params_hash ||= {}
      response = access_token.get("#{path}?#{params_hash.to_params}")
      JSON.parse(response.body)
    end

    def post(path, params_hash)
      response = access_token.post(path, params_hash, @headers)
      JSON.parse(response.body)
    end

    def put(path, params_hash) 
      response = access_token.put(path, params_hash, @headers)
      JSON.parse(response.body)
    end

    def delete(path, params) 
      response = access_token.delete("#{path}?#{params.to_params}")
      JSON.parse(response.body)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
2Performant-0.1.1 lib/two_performant/oauth.rb