Class: Imagga::Categorization::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/imagga/categorization/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/imagga/categorization/client.rb', line 11

def initialize(options={})
  # Merge the config values from the module and those passed
  # to the client.
  merged_options = Categorization.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

  # set the endpoint for HTTParty
  self.class.base_uri self.endpoint.to_s

  # set a default api_key parameter for each HTTParty request
  @options = {
    query: { api_key: self.api_key }
  }
end

Instance Method Details

#classify(classifier_id, options = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/imagga/categorization/client.rb', line 31

def classify(classifier_id, options={})
  default_options = { async: 1 }
  options.merge!(default_options)
  options = @options.merge({ body: options.to_query })
  self.class.post "/draft/classify/#{classifier_id}", options
end

#classify_result(ticket_id) ⇒ Object



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

def classify_result(ticket_id)
  self.class.get "/draft/classify/result/#{ticket_id}", @options
end

#task_result(task_id) ⇒ Object



42
43
44
# File 'lib/imagga/categorization/client.rb', line 42

def task_result(task_id)
  self.class.get "/draft/tasks/#{task_id}", @options
end