Sha256: 99ac5dc275ac2f3df513fd2c5b90167cc10739c0ad6a87734bdb4bc37cd503b0
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 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? 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}") (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end def post(path, params_hash) response = access_token.post(path, params_hash, @headers) (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end def put(path, params_hash) response = access_token.put(path, params_hash, @headers) (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end def delete(path, params) response = access_token.delete("#{path}?#{params.to_params}") (response.body && response.body.size > 0) ? JSON.parse(response.body) : nil end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
2Performant-0.1.3 | lib/two_performant/oauth.rb |