Class: ApiAiWrapper::Trainers::EntityTrainer

Inherits:
Components::TrainerComponent show all
Defined in:
lib/api_ai_wrapper/trainers/entity_trainer.rb

Overview

Instance Attribute Summary

Attributes inherited from Components::Component

#engine

Instance Method Summary collapse

Methods inherited from Components::TrainerComponent

#raise_if_unauthorized, #set_headers

Instance Method Details

#delete_entity(eid) ⇒ Object

api.ai/docs/reference/agent/entities#delete_entitieseid Delete an entity eid can either be the ID or the entity NAME



65
66
67
68
69
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 65

def delete_entity(eid)
  endpoint_url = URI.join(self.engine.base_url, "entities/#{eid}?v=#{self.engine.version}")

  self.delete(endpoint_url, {})
end

#delete_entity_entries(eid, entries) ⇒ Object

api.ai/docs/reference/agent/entities#delete_entitieseidentries Delete an entity’s entries eid can either be the ID or the entity NAME entries is an array of reference values (e.g. [“blue”, “red”] for entity “color”)



75
76
77
78
79
80
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 75

def delete_entity_entries(eid, entries)
  body = { entries: entries }
  endpoint_url = URI.join(self.engine.base_url, "entities/#{eid}/entries?v=#{self.engine.version}")

  self.delete(endpoint_url, body.to_json)
end

#get_entitiesObject

api.ai/docs/reference/agent/entities#get_entities Retrieves all entities for a given token



9
10
11
12
13
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 9

def get_entities
  endpoint_url = URI.join(self.engine.base_url, "entities?v=#{self.engine.version}")

  self.get(endpoint_url, {})
end

#get_entity(eid) ⇒ Object

api.ai/docs/reference/agent/entities#get_entitieseid Retrieves entity info eid can either be the ID or the entity NAME



18
19
20
21
22
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 18

def get_entity(eid)
  endpoint_url = URI.join(self.engine.base_url, "entities/#{eid}?v=#{self.engine.version}")

  self.get(endpoint_url, {})
end

#post_entity(name, entries) ⇒ Object

docs.api.ai/docs/entities#post-entities Creates an entity with the corresponding entries



26
27
28
29
30
31
32
33
34
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 26

def post_entity(name, entries)
  body = {
    name: name,
    entries: entries
  }
  endpoint_url = URI.join(self.engine.base_url, "entities?v=#{self.engine.version}")

  self.post(endpoint_url, body.to_json)
end

#post_entity_entries(eid, entries) ⇒ Object

api.ai/docs/reference/agent/entities#post_entitieseidentries Allows to add entries to en existing entity eid can either be the ID or the entity NAME



39
40
41
42
43
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 39

def post_entity_entries(eid, entries)
  endpoint_url = URI.join(self.engine.base_url, "entities/#{eid}/entries?v=#{self.engine.version}")

  self.post(endpoint_url, entries.to_json)
end

#put_entity(eid, options = {}) ⇒ Object



47
48
49
50
51
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 47

def put_entity(eid, options = {})
  endpoint_url = URI.join(self.engine.base_url, "entities/#{eid}?v=#{self.engine.version}")

  self.put(endpoint_url, options.to_json)
end

#put_entity_entries(eid, entries) ⇒ Object



55
56
57
58
59
60
# File 'lib/api_ai_wrapper/trainers/entity_trainer.rb', line 55

def put_entity_entries(eid, entries)
  body = { entries: entries }
  endpoint_url = URI.join(self.engine.base_url, "entities/#{eid}/entries?v=#{self.engine.version}")

  self.put(endpoint_url, entries.to_json)
end