Class: Openlayer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/openlayer/client.rb

Constant Summary collapse

BASE_URL =
"https://api.openlayer.com/v1/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
# File 'lib/openlayer/client.rb', line 12

def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
  @api_key = api_key
  @adapter = adapter
  @stubs = stubs
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



10
11
12
# File 'lib/openlayer/client.rb', line 10

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



10
11
12
# File 'lib/openlayer/client.rb', line 10

def api_key
  @api_key
end

Instance Method Details

#connectionObject



37
38
39
40
41
42
43
44
45
# File 'lib/openlayer/client.rb', line 37

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = BASE_URL
    conn.request :authorization, "Bearer", api_key
    conn.request :json
    conn.response :json, content_type: "application/json"
    conn.adapter adapter, @stubs
  end
end

#inference_pipeline(inference_pipeline_id) ⇒ Object



18
19
20
# File 'lib/openlayer/client.rb', line 18

def inference_pipeline(inference_pipeline_id)
  InferencePipeline.new(self, inference_pipeline_id)
end

#load_project(name:) ⇒ Object



22
23
24
# File 'lib/openlayer/client.rb', line 22

def load_project(name:)
  Project.from_response self, connection.get("projects", project_search_params(name: name))
end

#load_project_version(id:, payload: {}) ⇒ Object



33
34
35
# File 'lib/openlayer/client.rb', line 33

def load_project_version(id:, payload: {})
  ProjectVersion.from_response self, connection.post("projects/#{id}/versions", payload)
end

#presigned_url(object_name: nil, workspace_id: nil) ⇒ Object



26
27
28
29
30
31
# File 'lib/openlayer/client.rb', line 26

def presigned_url(object_name: nil, workspace_id: nil)
  handle_response connection.post(
    "storage/presigned-url?objectName=staging", presigned_url_params(object_name: object_name,
                                                                     workspace_id: workspace_id)
  )
end