Class: VoxableApiAiRuby::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Client object

Parameters:

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

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
# File 'lib/voxable-api-ai-ruby/client.rb', line 10

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

Instance Attribute Details

#api_base_urlObject



22
23
24
# File 'lib/voxable-api-ai-ruby/client.rb', line 22

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

#api_langObject



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

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

#api_versionObject



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

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

#client_access_tokenObject

Returns the value of attribute client_access_token.



3
4
5
# File 'lib/voxable-api-ai-ruby/client.rb', line 3

def client_access_token
  @client_access_token
end

#developer_access_tokenObject

Returns the value of attribute developer_access_token.



3
4
5
# File 'lib/voxable-api-ai-ruby/client.rb', line 3

def developer_access_token
  @developer_access_token
end

#user_agentString

Returns:

  • (String)


18
19
20
# File 'lib/voxable-api-ai-ruby/client.rb', line 18

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

Instance Method Details

#client_credentials?Boolean

Returns true if the client credentials are present.

Returns:

  • (Boolean)

    true if the client credentials are present



43
44
45
# File 'lib/voxable-api-ai-ruby/client.rb', line 43

def client_credentials?
  credentials[:client_access_token]
end

#credentialsHash

Returns:

  • (Hash)


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

def credentials
  {
      client_access_token: client_access_token,
      developer_access_token: developer_access_token
  }
end

#developer_credentials?Boolean

Returns true if the developer credentials are present.

Returns:

  • (Boolean)

    true if the developer credentials are present



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

def developer_credentials?
  credentials[:developer_access_token]
end

#get_entities_request(options = {}) ⇒ Object



95
96
97
98
# File 'lib/voxable-api-ai-ruby/client.rb', line 95

def get_entities_request(options = {})
  raise VoxableApiAiRuby::ClientError.new('Credentials missing') if !developer_credentials?
  VoxableApiAiRuby::GetEntityRequest.new(self, options).perform
end

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



89
90
91
92
93
# File 'lib/voxable-api-ai-ruby/client.rb', line 89

def get_entity_request(eid, options = {})
  raise VoxableApiAiRuby::ClientError.new('Credentials missing') if !developer_credentials?
  options[:eid] = eid
  VoxableApiAiRuby::GetEntityRequest.new(self, options).perform
end

#get_intent_request(iid, options = {}) ⇒ Object



78
79
80
81
82
# File 'lib/voxable-api-ai-ruby/client.rb', line 78

def get_intent_request(iid, options = {})
  raise VoxableApiAiRuby::ClientError.new('Credentials missing') if !developer_credentials?
  options[:iid] = iid
  VoxableApiAiRuby::GetIntentRequest.new(self, options).perform
end

#get_intents_request(options = {}) ⇒ Object



84
85
86
87
# File 'lib/voxable-api-ai-ruby/client.rb', line 84

def get_intents_request(options = {})
  raise VoxableApiAiRuby::ClientError.new('Credentials missing') if !developer_credentials?
  VoxableApiAiRuby::GetIntentRequest.new(self, options).perform
end

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



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

def text_request (query = '', options = {})
  raise VoxableApiAiRuby::ClientError.new('Credentials missing') if !client_credentials?
  options[:params] ||= {}
  options[:params] = options[:params].merge({ query: query })
  VoxableApiAiRuby::TextRequest.new(self, options).perform
end

#update_entities_request(entities, options = {}) ⇒ Object



66
67
68
69
70
# File 'lib/voxable-api-ai-ruby/client.rb', line 66

def update_entities_request(entities, options = {})
  raise VoxableApiAiRuby::ClientError.new('Credentials missing') if !developer_credentials?
  options[:json] = entities
  VoxableApiAiRuby::UpdateEntitiesRequest.new(self, options).perform
end

#update_intent_request(intent, options = {}) ⇒ Object



72
73
74
75
76
# File 'lib/voxable-api-ai-ruby/client.rb', line 72

def update_intent_request(intent, options = {})
  raise VoxableApiAiRuby::ClientError.new('Credentials missing') if !developer_credentials?
  options[:json] = intent
  VoxableApiAiRuby::UpdateIntentRequest.new(self, options).perform
end

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



59
60
61
62
63
64
# File 'lib/voxable-api-ai-ruby/client.rb', line 59

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