class Eclaircir::Client

Attributes

api_key[R]

Public Class Methods

new(api_key) click to toggle source
# File lib/eclaircir/client.rb, line 11
def initialize(api_key)
  @api_key = api_key
end

Public Instance Methods

models(options = {}) click to toggle source
# File lib/eclaircir/client.rb, line 15
def models(options = {})
  get('/models', query: options)
end
predict_outputs(model, inputs) click to toggle source
# File lib/eclaircir/client.rb, line 19
def predict_outputs(model, inputs)
  with_response_parsing do
    validate post("/models/#{model.id}/outputs", body: {
      inputs: Array(inputs).map(&:to_api_hash)
    }.to_json)
  end
end

Protected Instance Methods

authorization_headers() click to toggle source
# File lib/eclaircir/client.rb, line 30
def authorization_headers
  @authorization_headers ||= {
    'Authorization' => "Key #{api_key}"
  }
end
delete(path, query: nil, body: nil) click to toggle source
# File lib/eclaircir/client.rb, line 56
def delete(path, query: nil, body: nil)
  self.class.delete(path,
    headers: authorization_headers,
    query: query,
    body: body)
end
get(path, query: nil) click to toggle source
# File lib/eclaircir/client.rb, line 36
def get(path, query: nil)
  self.class.get(path,
    headers: authorization_headers,
    query: query)
end
patch(path, query: nil, body: nil) click to toggle source
# File lib/eclaircir/client.rb, line 49
def patch(path, query: nil, body: nil)
  self.class.patch(path,
    headers: authorization_headers,
    query: query,
    body: body)
end
post(path, query: nil, body: nil) click to toggle source
# File lib/eclaircir/client.rb, line 42
def post(path, query: nil, body: nil)
  self.class.post(path,
    headers: authorization_headers,
    query: query,
    body: body)
end
raise_status_error(raw_response) click to toggle source
# File lib/eclaircir/client.rb, line 78
def raise_status_error(raw_response)
  status = raw_response['status']
  raise APIError, status['description']
end
validate(response) click to toggle source
# File lib/eclaircir/client.rb, line 69
def validate(response)
  case response.code
  when 200..399
    response.parsed_response
  else
    raise_status_error(response.parsed_response)
  end
end
with_response_parsing() { || ... } click to toggle source
# File lib/eclaircir/client.rb, line 63
def with_response_parsing
  Eclaircir::Response.parse(yield).tap do |response|
    StatusValidator.new(response).validate!
  end
end