Sha256: f4f0f7c88b5a047ec9a505c1a2ff5aea24b1014a9b8977b2775c8dc32a04580f
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 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 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/x-www-form-urlencoded' } 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.to_json, @headers) JSON.parse(response.body) end def put(path, params_hash) response = access_token.put(path, params_hash.to_json, @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.0 | lib/two_performant/oauth.rb |