Class: ApiAiRuby::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/api-ai-ruby/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ ApiAiRuby::Client

Initializes a new Client object

Parameters:

  • options (Hash) (defaults to: {})

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/api-ai-ruby/client.rb', line 12

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  if !(options.key?  :api_session_id)
    @api_session_id = SecureRandom.uuid
  end

  yield(self) if block_given?
end

Instance Attribute Details

#api_base_urlObject



29
30
31
# File 'lib/api-ai-ruby/client.rb', line 29

def api_base_url
  @api_base_url ||= ApiAiRuby::Constants::DEFAULT_BASE_URL
end

#api_langObject



33
34
35
# File 'lib/api-ai-ruby/client.rb', line 33

def api_lang
  @api_lang ||= ApiAiRuby::Constants::DEFAULT_CLIENT_LANG
end

#api_session_idObject



41
42
43
# File 'lib/api-ai-ruby/client.rb', line 41

def api_session_id
  @api_session_id
end

#api_versionObject



37
38
39
# File 'lib/api-ai-ruby/client.rb', line 37

def api_version
  @api_version ||= ApiAiRuby::Constants::DEFAULT_API_VERSION
end

#client_access_tokenObject

Returns the value of attribute client_access_token.



5
6
7
# File 'lib/api-ai-ruby/client.rb', line 5

def client_access_token
  @client_access_token
end

#subscription_keyObject

Returns the value of attribute subscription_key.



5
6
7
# File 'lib/api-ai-ruby/client.rb', line 5

def subscription_key
  @subscription_key
end

#user_agentString

Returns:

  • (String)


25
26
27
# File 'lib/api-ai-ruby/client.rb', line 25

def user_agent
  @user_agent ||= "ApiAiRubyGem/#{ApiAiRuby::Constants::VERSION}"
end

Instance Method Details

#credentialsHash

Returns:

  • (Hash)


46
47
48
49
50
# File 'lib/api-ai-ruby/client.rb', line 46

def credentials
  {
      client_access_token: client_access_token,
  }
end

#credentials?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/api-ai-ruby/client.rb', line 53

def credentials?
  credentials.values.all?
end

#text_request(query = '', options = {}) ⇒ Object



57
58
59
60
61
# File 'lib/api-ai-ruby/client.rb', line 57

def text_request (query = '', options = {})
  raise ApiAiRuby::ClientError.new('Credentials missing') if !credentials?
  options[:query] = query
  ApiAiRuby::TextRequest.new(self, options).perform
end

#user_entities_requestObject

Parameters:

  • entity_name (String)
  • entries (ApiAiRuby:Entry[])
  • options (Hash)


73
74
75
76
77
78
79
80
81
82
# File 'lib/api-ai-ruby/client.rb', line 73

def user_entities_request #entity_name, entries, options = {}
  ApiAiRuby::UserEntitiesRequest.new(self);
  # raise ApiAiRuby::ClientError.new('Entity name required') if entity_name.nil?
  # raise ApiAiRuby::ClientError.new('Entity entries array required') if !entries.nil? && entries.is_a?(Array)
  # raise ApiAiRuby::ClientError.new('Entity name required') if !(options.has_key?(:entries) && options[:entries].is_a?(Array))
  # options[:name] = entity_name
  # options[:entries] = entries
  # options[:extend] = options[:extend] || false
  # ApiAiRuby::UserEntitiesRequest.new(self, options).perform
end

#voice_request(file_stream, options = {}) ⇒ Object



63
64
65
66
67
# File 'lib/api-ai-ruby/client.rb', line 63

def voice_request(file_stream, options = {})
  raise ApiAiRuby::ClientError.new('Credentials missing') if !credentials?
  options[:file] = file_stream
  ApiAiRuby::VoiceRequest.new(self, options).perform
end