class HttpObservatory::Request

Public Class Methods

api() click to toggle source
# File lib/http_observatory/request.rb, line 33
def api
  Connection.api
end
errors(response) click to toggle source
# File lib/http_observatory/request.rb, line 16
def errors(response)
  error = { errors: { status: response["status"], message: response["message"] } }
  response.merge(error)
end
get(path, query = {}) click to toggle source
# File lib/http_observatory/request.rb, line 6
def get(path, query = {})
  response, status = get_json(path, query)
  status == 200 ? response : errors(response)
end
get_json(root_path, query = {}) click to toggle source
# File lib/http_observatory/request.rb, line 21
def get_json(root_path, query = {})
  query_string = query.map{|k,v| "#{k}=#{v}"}.join("&")
  response = api.get("#{root_path}?#{query_string}")
  [JSON.parse(response.body), response.status]
end
post(path, query) click to toggle source
# File lib/http_observatory/request.rb, line 11
def post(path, query)
  response, status = post_json(path, query)
  status == 201 ? response : errors(response)
end
post_json(root_path, query = {}) click to toggle source
# File lib/http_observatory/request.rb, line 27
def post_json(root_path, query = {})
  query_string = query.map{|k,v| "#{k}=#{v}"}.join("&")
  response = api.post("#{root_path}?#{query_string}")
  [JSON.parse(response.body), response.status]
end