Class: ApiAiRuby::Client
- Inherits:
-
Object
- Object
- ApiAiRuby::Client
- Defined in:
- lib/api-ai-ruby/client.rb
Instance Attribute Summary collapse
- #api_base_url ⇒ Object
- #api_lang ⇒ Object
- #api_session_id ⇒ Object
- #api_version ⇒ Object
-
#client_access_token ⇒ Object
Returns the value of attribute client_access_token.
-
#subscription_key ⇒ Object
Returns the value of attribute subscription_key.
- #user_agent ⇒ String
Instance Method Summary collapse
- #credentials ⇒ Hash
- #credentials? ⇒ Boolean
-
#initialize(options = {}) {|_self| ... } ⇒ ApiAiRuby::Client
constructor
Initializes a new Client object.
- #text_request(query = '', options = {}) ⇒ Object
- #user_entities_request ⇒ Object
- #voice_request(file_stream, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ ApiAiRuby::Client
Initializes a new Client object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/api-ai-ruby/client.rb', line 12 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end if !(.key? :api_session_id) @api_session_id = SecureRandom.uuid end yield(self) if block_given? end |
Instance Attribute Details
#api_base_url ⇒ Object
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_lang ⇒ Object
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_id ⇒ Object
41 42 43 |
# File 'lib/api-ai-ruby/client.rb', line 41 def api_session_id @api_session_id end |
#api_version ⇒ Object
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_token ⇒ Object
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_key ⇒ Object
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 |
Instance Method Details
#credentials ⇒ 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
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 = '', = {}) raise ApiAiRuby::ClientError.new('Credentials missing') if !credentials? [:query] = query ApiAiRuby::TextRequest.new(self, ).perform end |
#user_entities_request ⇒ Object
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, = {}) raise ApiAiRuby::ClientError.new('Credentials missing') if !credentials? [:file] = file_stream ApiAiRuby::VoiceRequest.new(self, ).perform end |