class WipApi::Client

Constants

API_URL

Attributes

api_key[W]
api_key[R]

Public Instance Methods

make_request(query) click to toggle source
# File lib/wip_api/client.rb, line 16
def make_request(query)
  http = Net::HTTP.new(api_uri.host, api_uri.port)
  http.use_ssl = true
  header = {
    "Authorization" => "bearer #{api_key}",
    "Content-Type" => "application/json"
  }
  request = Net::HTTP::Post.new(api_uri.request_uri, header)
  request.body = { query: query }.to_json

  # Send the request
  response = http.request(request)

  raise ChangeRejectedError.new(response.message) if response.class.eql?(Net::HTTPUnprocessableEntity)


  json = JSON.parse(response.body)
  if json.has_key? "errors"
    raise json["errors"].first["message"]
  end
  json
end

Private Instance Methods

api_uri() click to toggle source
# File lib/wip_api/client.rb, line 43
def api_uri
  @uri ||= URI.parse(API_URL)
end