module Tend::Util::Ht::ClassMethods

Public Instance Methods

get(options = {}) click to toggle source
# File lib/tend/util/ht.rb, line 6
def get options = {}
  o = extract_options options
  handle_response( HTTParty.get( uri(o), :basic_auth => o.auth ) )
end
post(attributes, options = {}) click to toggle source
# File lib/tend/util/ht.rb, line 11
def post attributes, options = {}
  o = extract_options options
  o.no_pagination = true
  handle_response( HTTParty.post( uri(o), body: attributes, :basic_auth => o.auth ) )
end

Private Instance Methods

handle_response(response) click to toggle source
# File lib/tend/util/ht.rb, line 20
def handle_response response
  case response.code
  when 200..299
    data = response.parsed_response["data"]
    message = response.parsed_response["message"]
    paginator = response.parsed_response["paginator"]
    {data: data, message: message, paginator: paginator}
  when 422
    HashWithIndifferentAccess.new response.parsed_response
  else
    raise Tend::HttpError.new("#{response.response.message} #{response.code}", response.code, response)
  end
end