Sha256: ce1d132a3078d79fd53627947c87c705f6ef8b268209b7f7547ae4065595faf1

Contents?: true

Size: 713 Bytes

Versions: 2

Compression:

Stored size: 713 Bytes

Contents

require 'json'

module Tumblr
  module Request

    #Performs a get request
    def get(path, params={})
      response = connection.get do |req|
        req.url path 
        req.params = params
      end
      #Check for errors and encapsulate
      respond(response)
    end
    
    #Performs post request
    def post(path, params={})
      response = connection.post do |req|
        req.url path
        req.body = params unless params.empty?
      end
      #Check for errors and encapsulate
      respond(response)
    end

    def respond(response)
      if [201, 200].include?(response.status)
        response.body['response']
      else
        response.body['meta']
      end
    end
    
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
tumblr_client-0.6.8 lib/tumblr/request.rb
tumblr_client_faraday_0_8-0.6.7.1 lib/tumblr/request.rb