Class: Tama::Neural::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/tama/neural/service.rb

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Service

Returns a new instance of Service.



6
7
8
# File 'lib/tama/neural/service.rb', line 6

def initialize(http)
  @http = http
end

Instance Method Details

#create_class_operation(klass, attributes = nil, headers: {}, timeout: nil, **attribute_keywords) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/tama/neural/service.rb', line 23

def create_class_operation(klass, attributes = nil, headers: {}, timeout: nil, **attribute_keywords)
  @http.validate_namespace!("provision")
  class_id = klass.is_a?(Klass) ? klass.id : klass
  attributes ||= attribute_keywords
  params = attributes.is_a?(OperationParams) ? attributes : OperationParams.parse(attributes)
  path = "neural/classes/#{HTTP.segment(class_id, "class_id")}/operations"
  response = @http.request(:post, path, body: {"operation" => params.to_h}, headers:, timeout:)
  @http.parse_data(response, Operation)
end

#get_class(space, name, headers: {}, timeout: nil) ⇒ Object



16
17
18
19
20
21
# File 'lib/tama/neural/service.rb', line 16

def get_class(space, name, headers: {}, timeout: nil)
  @http.validate_namespace!("provision")
  space_id = space.is_a?(Space) ? space.id : space
  path = "neural/spaces/#{HTTP.segment(space_id, "space_id")}/classes/#{HTTP.segment(name, "name")}"
  @http.parse_data(@http.request(:get, path, headers:, timeout:), Klass)
end

#get_space(slug, headers: {}, timeout: nil) ⇒ Object



10
11
12
13
14
# File 'lib/tama/neural/service.rb', line 10

def get_space(slug, headers: {}, timeout: nil)
  @http.validate_namespace!("provision")
  path = "neural/spaces/#{HTTP.segment(slug, "slug")}"
  @http.parse_data(@http.request(:get, path, headers:, timeout:), Space)
end