Sha256: f404f565283fdc4950c65116359fa1adb192b10d13c5fba2283c224ff02541b2

Contents?: true

Size: 777 Bytes

Versions: 2

Compression:

Stored size: 777 Bytes

Contents

require 'json'

module Tumblr
  module Request

    # Perform a get request and return the raw response
    def get_response(path, params = {})
      connection.get do |req|
        req.url path
        req.params = params
      end
    end

    # Performs a get request
    def get(path, params={})
      respond get_response(path, params)
    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 & 1 rubygems

Version Path
tumblr_client-0.6.11 lib/tumblr/request.rb
tumblr_client-0.6.9 lib/tumblr/request.rb