Class: ApiAiWrapper::Engine

Inherits:
Object show all
Defined in:
lib/api_ai_wrapper/engine.rb

Constant Summary collapse

AUTOLOAD_CLASSES =
[
  ApiAiWrapper::Trainers::EntityTrainer,
  ApiAiWrapper::Trainers::IntentTrainer,
  ApiAiWrapper::MeaningExtractor
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Engine

Returns a new instance of Engine.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/api_ai_wrapper/engine.rb', line 19

def initialize(options = {})
  self.client = HTTPClient.new
  self.client.receive_timeout = options[:client_timeout].presence || ApiAiWrapper::Constants::DEFAULT_CLIENT_TIMEOUT
  self.locale = options[:locale].presence || ApiAiWrapper::Constants::DEFAULT_LOCALE
  self.base_url = ApiAiWrapper::Constants::DEFAULT_BASE_URL
  self.version = options[:version].presence || ApiAiWrapper::Constants::DEFAULT_VERSION
  self.client_token = options[:client_token].presence
  self.developer_token = options[:developer_token].presence

  # RAISE ERROR IF NO TOKEN PRESENT
  raise ApiAiWrapper::Errors::Engine::MissingTokens.new if self.client_token.blank? && self.developer_token.blank?

  # define entity_trainer and intent_trainer on the fly
  AUTOLOAD_CLASSES.each{ |class_name|
    instance = class_name.new
    instance.engine = self
    self.send("#{class_name.to_s.demodulize.underscore}=", instance)
  }
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def base_url
  @base_url
end

#clientObject

Returns the value of attribute client.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def client
  @client
end

#client_timeoutObject

Returns the value of attribute client_timeout.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def client_timeout
  @client_timeout
end

#client_tokenObject

Returns the value of attribute client_token.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def client_token
  @client_token
end

#developer_tokenObject

Returns the value of attribute developer_token.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def developer_token
  @developer_token
end

#entity_trainerObject

Returns the value of attribute entity_trainer.



17
18
19
# File 'lib/api_ai_wrapper/engine.rb', line 17

def entity_trainer
  @entity_trainer
end

#headersObject

Returns the value of attribute headers.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def headers
  @headers
end

#intent_trainerObject

Returns the value of attribute intent_trainer.



17
18
19
# File 'lib/api_ai_wrapper/engine.rb', line 17

def intent_trainer
  @intent_trainer
end

#localeObject

Returns the value of attribute locale.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def locale
  @locale
end

#meaning_extractorObject

Returns the value of attribute meaning_extractor.



17
18
19
# File 'lib/api_ai_wrapper/engine.rb', line 17

def meaning_extractor
  @meaning_extractor
end

#versionObject

Returns the value of attribute version.



16
17
18
# File 'lib/api_ai_wrapper/engine.rb', line 16

def version
  @version
end