Sha256: 9e4240bbb522dd955c820200b76e8282d5331f3f62d19ad70bb715de86305fb8

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

require 'json'
module Oauth
  module Models
    module Consumers
      # This is just a simple
      class SimpleClient
        attr_reader :token

        def initialize(token)
          @token = token
        end


        def put(path,params={})
          parse(token.put(path,params, {'Accept' => 'application/json'}))
        end

        def delete(path)
          parse(token.delete(path, {'Accept' => 'application/json'}))
        end

        def post(path,params={})
          parse(token.post(path,params, {'Accept' => 'application/json'}))
        end

        def get(path)
          parse(token.get(path, {'Accept' => 'application/json'}))
        end

        protected

        def parse(response)
          return false unless response
          if ["200","201"].include? response.code
            unless response.body.blank?
              JSON.parse(response.body)
            else
              true
            end
          else
            logger.debug "Got Response code: #{response.code}"
            false
          end

        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
oauth_consumer-0.1.3 lib/oauth/models/consumers/simple_client.rb
oauth_consumer-0.1.2 lib/oauth/models/consumers/simple_client.rb
oauth_consumer-0.1.1 lib/oauth/models/consumers/simple_client.rb
oauth_consumer-0.1.0 lib/oauth/models/consumers/simple_client.rb