Class: Kairos::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kairos/client.rb', line 10

def initialize(options={})
  # Merge the config values from the module and those passed
  # to the client.
  merged_options = Kairos.options.merge(options)

  # Copy the merged values to this client and ignore those
  # not part of our configuration
  Configuration::VALID_CONFIG_KEYS.each do |key|
    send("#{key}=", merged_options[key])
  end
end

Instance Method Details

#detect(options = {}) ⇒ Object

Detect faces in Image

Example Usage:

- require 'kairos'
- client = Kairos::Client.new(:app_id => '1234', :app_key => 'abcde1234')
- client.detect(:url => 'https://some.url.com/to_some_other_image.jpg', :selector => 'FULL')


58
59
60
# File 'lib/kairos/client.rb', line 58

def detect(options={})
  post_to_api(Kairos::Configuration::DETECT, options)
end

#enroll(options = {}) ⇒ Object

Enroll an Image

Example Usage:

- require 'kairos'
- client = Kairos::Client.new(:app_id => '1234', :app_key => 'abcde1234')
- client.enroll(:url => 'https://some.url.com/to_some.jpg', :subject_id => 'gemtest', :gallery_name => 'testgallery')


28
29
30
# File 'lib/kairos/client.rb', line 28

def enroll(options={})
  post_to_api(Kairos::Configuration::ENROLL, options)
end

List all Galleries

Example Usage:

- require 'kairos'
- client = Kairos::Client.new(:app_id => '1234', :app_key => 'abcde1234')
- client.gallery_list_all


68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kairos/client.rb', line 68

def gallery_list_all
  # ToDo: Research why Typhoeus works better than Faraday for this endpoint
  request = Typhoeus::Request.new(
    "#{Kairos::Configuration::GALLERY_LIST_ALL}",
    method: :post,
    headers: { "Content-Type" => "application/x-www-form-urlencoded",
               "app_id"       => "#{@app_id}",
               "app_key"      => "#{@app_key}" }
  )
  response = request.run
  JSON.parse(response.body) rescue "INVALID_JSON: #{response.body}"
end

Remove Subject from Gallery

Example Usage:

- require 'kairos'
- client = Kairos::Client.new(:app_id => '1234', :app_key => 'abcde1234')
- client.gallery_remove_subject(:gallery_name => 'testgallery', :subject_id => 'gemtest')


48
49
50
# File 'lib/kairos/client.rb', line 48

def gallery_remove_subject(options={})
  post_to_api(Kairos::Configuration::GALLERY_REMOVE_SUBJECT, options)
end

View subjects in Gallery

Example Usage:

- require 'kairos'
- client = Kairos::Client.new(:app_id => '1234', :app_key => 'abcde1234')
- client.gallery_view(:gallery_name => 'testgallery')


87
88
89
# File 'lib/kairos/client.rb', line 87

def gallery_view(options={})
  post_to_api(Kairos::Configuration::GALLERY_VIEW, options)
end

#recognize(options = {}) ⇒ Object

Recognize an Image

Example Usage:

- require 'kairos'
- client = Kairos::Client.new(:app_id => '1234', :app_key => 'abcde1234')
- client.recognize(:url => 'https://some.url.com/to_some_other_image.jpg', :gallery_name => 'testgallery', :threshold => '.2', :max_num_results => '5')


38
39
40
# File 'lib/kairos/client.rb', line 38

def recognize(options={})
  post_to_api(Kairos::Configuration::RECOGNIZE, options)
end