Sha256: e23c0b831bbf329028885c945a59391ab9b687bf4f947637ddbbc6947a3efd91

Contents?: true

Size: 715 Bytes

Versions: 1

Compression:

Stored size: 715 Bytes

Contents

module ChgkRating
  module Request
    include ChgkRating::Connection

    def get(path, params = {})
      respond perform_get(path, params)
    end

    private

    def perform_get(path, params)
      connection.get do |req|
        req.url path
        req.params = params
      end
    end

    def respond(response)
      begin
        body = MultiJson.load response.body
        raise MultiJson::ParseError if body.respond_to?(:has_key?) && body.has_key?('error')
        body
      rescue MultiJson::ParseError
        respond_with_error response.status, response.body
      end
    end

    def respond_with_error(code, body)
      fail ChgkRating::Error::ERRORS[code].from_response(body)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chgk_rating-1.0.0.rc1 lib/chgk_rating/request.rb