From 222eafe1af4c15facaf2af8bfecac90789996cb5 Mon Sep 17 00:00:00 2001 From: Mamoon Raja Date: Fri, 30 Aug 2019 11:45:53 -0400 Subject: [PATCH] feat(Auth): update auth methods to use authenticators --- lib/ibm_watson.rb | 2 - lib/ibm_watson/assistant_v1.rb | 142 ++++++++------- lib/ibm_watson/assistant_v2.rb | 20 +-- lib/ibm_watson/compare_comply_v1.rb | 39 +++-- lib/ibm_watson/discovery_v1.rb | 162 ++++++++++++------ lib/ibm_watson/language_translator_v3.rb | 44 +++-- .../natural_language_classifier_v1.rb | 39 ++--- .../natural_language_understanding_v1.rb | 20 +-- lib/ibm_watson/personality_insights_v3.rb | 36 ++-- lib/ibm_watson/speech_to_text_v1.rb | 144 ++++++++++------ lib/ibm_watson/text_to_speech_v1.rb | 70 ++++---- lib/ibm_watson/tone_analyzer_v3.rb | 37 ++-- lib/ibm_watson/visual_recognition_v3.rb | 62 ++++--- 13 files changed, 452 insertions(+), 365 deletions(-) diff --git a/lib/ibm_watson.rb b/lib/ibm_watson.rb index 782e343..479cfb8 100644 --- a/lib/ibm_watson.rb +++ b/lib/ibm_watson.rb @@ -6,8 +6,6 @@ module IBMWatson ApiException = IBMCloudSdkCore::ApiException DetailedResponse = IBMCloudSdkCore::DetailedResponse - IAMTokenManager = IBMCloudSdkCore::IAMTokenManager - ICP4DTokenManager = IBMCloudSdkCore::ICP4DTokenManager require_relative("./ibm_watson/personality_insights_v3.rb") require_relative("./ibm_watson/tone_analyzer_v3.rb") diff --git a/lib/ibm_watson/assistant_v1.rb b/lib/ibm_watson/assistant_v1.rb index 86decc8..c78ea29 100644 --- a/lib/ibm_watson/assistant_v1.rb +++ b/lib/ibm_watson/assistant_v1.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -82,21 +82,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/assistant/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "conversation" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Assistant" super - @version = args[:version] end ######################### @@ -155,6 +148,7 @@ def message(workspace_id:, input: nil, intents: nil, entities: nil, alternate_in method_url = "/v1/workspaces/%s/message" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -170,21 +164,20 @@ def message(workspace_id:, input: nil, intents: nil, entities: nil, alternate_in ######################### ## - # @!method list_workspaces(page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_workspaces(page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List workspaces. # List the workspaces associated with a Watson Assistant service instance. # # This operation is limited to 500 requests per 30 minutes. For more information, # see **Rate limiting**. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned workspaces will be sorted. To reverse the sort # order, prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_workspaces(page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_workspaces(page_limit: nil, sort: nil, cursor: nil, include_audit: nil) headers = { } sdk_headers = Common.new.get_sdk_headers("conversation", "V1", "list_workspaces") @@ -193,7 +186,6 @@ def list_workspaces(page_limit: nil, include_count: nil, sort: nil, cursor: nil, params = { "version" => @version, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -201,6 +193,7 @@ def list_workspaces(page_limit: nil, include_count: nil, sort: nil, cursor: nil, method_url = "/v1/workspaces" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -260,6 +253,7 @@ def create_workspace(name: nil, description: nil, language: nil, metadata: nil, method_url = "/v1/workspaces" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -306,6 +300,7 @@ def get_workspace(workspace_id:, export: nil, include_audit: nil, sort: nil) method_url = "/v1/workspaces/%s" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -378,6 +373,7 @@ def update_workspace(workspace_id:, name: nil, description: nil, language: nil, method_url = "/v1/workspaces/%s" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -412,6 +408,7 @@ def delete_workspace(workspace_id:) method_url = "/v1/workspaces/%s" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -426,7 +423,7 @@ def delete_workspace(workspace_id:) ######################### ## - # @!method list_intents(workspace_id:, export: nil, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_intents(workspace_id:, export: nil, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List intents. # List the intents for a workspace. # @@ -438,14 +435,13 @@ def delete_workspace(workspace_id:) # **export**=`false`, the returned data includes only information about the element # itself. If **export**=`true`, all content, including subelements, is included. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned intents will be sorted. To reverse the sort order, # prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_intents(workspace_id:, export: nil, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_intents(workspace_id:, export: nil, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? headers = { @@ -457,7 +453,6 @@ def list_intents(workspace_id:, export: nil, page_limit: nil, include_count: nil "version" => @version, "export" => export, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -465,6 +460,7 @@ def list_intents(workspace_id:, export: nil, page_limit: nil, include_count: nil method_url = "/v1/workspaces/%s/intents" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -516,6 +512,7 @@ def create_intent(workspace_id:, intent:, description: nil, examples: nil) method_url = "/v1/workspaces/%s/intents" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -561,6 +558,7 @@ def get_intent(workspace_id:, intent:, export: nil, include_audit: nil) method_url = "/v1/workspaces/%s/intents/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -614,6 +612,7 @@ def update_intent(workspace_id:, intent:, new_intent: nil, new_description: nil, method_url = "/v1/workspaces/%s/intents/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -651,6 +650,7 @@ def delete_intent(workspace_id:, intent:) method_url = "/v1/workspaces/%s/intents/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -665,7 +665,7 @@ def delete_intent(workspace_id:, intent:) ######################### ## - # @!method list_examples(workspace_id:, intent:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_examples(workspace_id:, intent:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List user input examples. # List the user input examples for an intent, optionally including contextual entity # mentions. @@ -675,14 +675,13 @@ def delete_intent(workspace_id:, intent:) # @param workspace_id [String] Unique identifier of the workspace. # @param intent [String] The intent name. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned examples will be sorted. To reverse the sort # order, prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_examples(workspace_id:, intent:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_examples(workspace_id:, intent:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? raise ArgumentError.new("intent must be provided") if intent.nil? @@ -695,7 +694,6 @@ def list_examples(workspace_id:, intent:, page_limit: nil, include_count: nil, s params = { "version" => @version, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -703,6 +701,7 @@ def list_examples(workspace_id:, intent:, page_limit: nil, include_count: nil, s method_url = "/v1/workspaces/%s/intents/%s/examples" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -754,6 +753,7 @@ def create_example(workspace_id:, intent:, text:, mentions: nil) method_url = "/v1/workspaces/%s/intents/%s/examples" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -797,6 +797,7 @@ def get_example(workspace_id:, intent:, text:, include_audit: nil) method_url = "/v1/workspaces/%s/intents/%s/examples/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent), ERB::Util.url_encode(text)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -849,6 +850,7 @@ def update_example(workspace_id:, intent:, text:, new_text: nil, new_mentions: n method_url = "/v1/workspaces/%s/intents/%s/examples/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent), ERB::Util.url_encode(text)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -889,6 +891,7 @@ def delete_example(workspace_id:, intent:, text:) method_url = "/v1/workspaces/%s/intents/%s/examples/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(intent), ERB::Util.url_encode(text)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -903,7 +906,7 @@ def delete_example(workspace_id:, intent:, text:) ######################### ## - # @!method list_counterexamples(workspace_id:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_counterexamples(workspace_id:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List counterexamples. # List the counterexamples for a workspace. Counterexamples are examples that have # been marked as irrelevant input. @@ -912,14 +915,13 @@ def delete_example(workspace_id:, intent:, text:) # see **Rate limiting**. # @param workspace_id [String] Unique identifier of the workspace. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned counterexamples will be sorted. To reverse the # sort order, prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_counterexamples(workspace_id:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_counterexamples(workspace_id:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? headers = { @@ -930,7 +932,6 @@ def list_counterexamples(workspace_id:, page_limit: nil, include_count: nil, sor params = { "version" => @version, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -938,6 +939,7 @@ def list_counterexamples(workspace_id:, page_limit: nil, include_count: nil, sor method_url = "/v1/workspaces/%s/counterexamples" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -985,6 +987,7 @@ def create_counterexample(workspace_id:, text:) method_url = "/v1/workspaces/%s/counterexamples" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1026,6 +1029,7 @@ def get_counterexample(workspace_id:, text:, include_audit: nil) method_url = "/v1/workspaces/%s/counterexamples/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(text)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1074,6 +1078,7 @@ def update_counterexample(workspace_id:, text:, new_text: nil) method_url = "/v1/workspaces/%s/counterexamples/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(text)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1112,6 +1117,7 @@ def delete_counterexample(workspace_id:, text:) method_url = "/v1/workspaces/%s/counterexamples/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(text)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1126,7 +1132,7 @@ def delete_counterexample(workspace_id:, text:) ######################### ## - # @!method list_entities(workspace_id:, export: nil, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_entities(workspace_id:, export: nil, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List entities. # List the entities for a workspace. # @@ -1138,14 +1144,13 @@ def delete_counterexample(workspace_id:, text:) # **export**=`false`, the returned data includes only information about the element # itself. If **export**=`true`, all content, including subelements, is included. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned entities will be sorted. To reverse the sort # order, prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_entities(workspace_id:, export: nil, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_entities(workspace_id:, export: nil, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? headers = { @@ -1157,7 +1162,6 @@ def list_entities(workspace_id:, export: nil, page_limit: nil, include_count: ni "version" => @version, "export" => export, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -1165,6 +1169,7 @@ def list_entities(workspace_id:, export: nil, page_limit: nil, include_count: ni method_url = "/v1/workspaces/%s/entities" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1221,6 +1226,7 @@ def create_entity(workspace_id:, entity:, description: nil, metadata: nil, fuzzy method_url = "/v1/workspaces/%s/entities" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1266,6 +1272,7 @@ def get_entity(workspace_id:, entity:, export: nil, include_audit: nil) method_url = "/v1/workspaces/%s/entities/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1322,6 +1329,7 @@ def update_entity(workspace_id:, entity:, new_entity: nil, new_description: nil, method_url = "/v1/workspaces/%s/entities/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1359,6 +1367,7 @@ def delete_entity(workspace_id:, entity:) method_url = "/v1/workspaces/%s/entities/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1406,6 +1415,7 @@ def list_mentions(workspace_id:, entity:, export: nil, include_audit: nil) method_url = "/v1/workspaces/%s/entities/%s/mentions" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1420,7 +1430,7 @@ def list_mentions(workspace_id:, entity:, export: nil, include_audit: nil) ######################### ## - # @!method list_values(workspace_id:, entity:, export: nil, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_values(workspace_id:, entity:, export: nil, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List entity values. # List the values for an entity. # @@ -1432,14 +1442,13 @@ def list_mentions(workspace_id:, entity:, export: nil, include_audit: nil) # **export**=`false`, the returned data includes only information about the element # itself. If **export**=`true`, all content, including subelements, is included. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned entity values will be sorted. To reverse the sort # order, prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_values(workspace_id:, entity:, export: nil, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_values(workspace_id:, entity:, export: nil, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? raise ArgumentError.new("entity must be provided") if entity.nil? @@ -1453,7 +1462,6 @@ def list_values(workspace_id:, entity:, export: nil, page_limit: nil, include_co "version" => @version, "export" => export, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -1461,6 +1469,7 @@ def list_values(workspace_id:, entity:, export: nil, page_limit: nil, include_co method_url = "/v1/workspaces/%s/entities/%s/values" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1472,7 +1481,7 @@ def list_values(workspace_id:, entity:, export: nil, page_limit: nil, include_co end ## - # @!method create_value(workspace_id:, entity:, value:, metadata: nil, value_type: nil, synonyms: nil, patterns: nil) + # @!method create_value(workspace_id:, entity:, value:, metadata: nil, type: nil, synonyms: nil, patterns: nil) # Create entity value. # Create a new value for an entity. # @@ -1488,7 +1497,7 @@ def list_values(workspace_id:, entity:, export: nil, page_limit: nil, include_co # - It cannot contain carriage return, newline, or tab characters. # - It cannot consist of only whitespace characters. # @param metadata [Hash] Any metadata related to the entity value. - # @param value_type [String] Specifies the type of entity value. + # @param type [String] Specifies the type of entity value. # @param synonyms [Array[String]] An array of synonyms for the entity value. A value can specify either synonyms or # patterns (depending on the value type), but not both. A synonym must conform to # the following resrictions: @@ -1499,7 +1508,7 @@ def list_values(workspace_id:, entity:, export: nil, page_limit: nil, include_co # expression; for more information about how to specify a pattern, see the # [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-entities#entities-create-dictionary-based). # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def create_value(workspace_id:, entity:, value:, metadata: nil, value_type: nil, synonyms: nil, patterns: nil) + def create_value(workspace_id:, entity:, value:, metadata: nil, type: nil, synonyms: nil, patterns: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? raise ArgumentError.new("entity must be provided") if entity.nil? @@ -1518,13 +1527,14 @@ def create_value(workspace_id:, entity:, value:, metadata: nil, value_type: nil, data = { "value" => value, "metadata" => metadata, - "type" => value_type, + "type" => type, "synonyms" => synonyms, "patterns" => patterns } method_url = "/v1/workspaces/%s/entities/%s/values" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1572,6 +1582,7 @@ def get_value(workspace_id:, entity:, value:, export: nil, include_audit: nil) method_url = "/v1/workspaces/%s/entities/%s/values/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1583,7 +1594,7 @@ def get_value(workspace_id:, entity:, value:, export: nil, include_audit: nil) end ## - # @!method update_value(workspace_id:, entity:, value:, new_value: nil, new_metadata: nil, new_value_type: nil, new_synonyms: nil, new_patterns: nil) + # @!method update_value(workspace_id:, entity:, value:, new_value: nil, new_metadata: nil, new_type: nil, new_synonyms: nil, new_patterns: nil) # Update entity value. # Update an existing entity value with new or modified data. You must provide # component objects defining the content of the updated entity value. @@ -1601,7 +1612,7 @@ def get_value(workspace_id:, entity:, value:, export: nil, include_audit: nil) # - It cannot contain carriage return, newline, or tab characters. # - It cannot consist of only whitespace characters. # @param new_metadata [Hash] Any metadata related to the entity value. - # @param new_value_type [String] Specifies the type of entity value. + # @param new_type [String] Specifies the type of entity value. # @param new_synonyms [Array[String]] An array of synonyms for the entity value. A value can specify either synonyms or # patterns (depending on the value type), but not both. A synonym must conform to # the following resrictions: @@ -1612,7 +1623,7 @@ def get_value(workspace_id:, entity:, value:, export: nil, include_audit: nil) # expression; for more information about how to specify a pattern, see the # [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-entities#entities-create-dictionary-based). # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def update_value(workspace_id:, entity:, value:, new_value: nil, new_metadata: nil, new_value_type: nil, new_synonyms: nil, new_patterns: nil) + def update_value(workspace_id:, entity:, value:, new_value: nil, new_metadata: nil, new_type: nil, new_synonyms: nil, new_patterns: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? raise ArgumentError.new("entity must be provided") if entity.nil? @@ -1631,13 +1642,14 @@ def update_value(workspace_id:, entity:, value:, new_value: nil, new_metadata: n data = { "value" => new_value, "metadata" => new_metadata, - "type" => new_value_type, + "type" => new_type, "synonyms" => new_synonyms, "patterns" => new_patterns } method_url = "/v1/workspaces/%s/entities/%s/values/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1678,6 +1690,7 @@ def delete_value(workspace_id:, entity:, value:) method_url = "/v1/workspaces/%s/entities/%s/values/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1692,7 +1705,7 @@ def delete_value(workspace_id:, entity:, value:) ######################### ## - # @!method list_synonyms(workspace_id:, entity:, value:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_synonyms(workspace_id:, entity:, value:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List entity value synonyms. # List the synonyms for an entity value. # @@ -1702,14 +1715,13 @@ def delete_value(workspace_id:, entity:, value:) # @param entity [String] The name of the entity. # @param value [String] The text of the entity value. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned entity value synonyms will be sorted. To reverse # the sort order, prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_synonyms(workspace_id:, entity:, value:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_synonyms(workspace_id:, entity:, value:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? raise ArgumentError.new("entity must be provided") if entity.nil? @@ -1724,7 +1736,6 @@ def list_synonyms(workspace_id:, entity:, value:, page_limit: nil, include_count params = { "version" => @version, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -1732,6 +1743,7 @@ def list_synonyms(workspace_id:, entity:, value:, page_limit: nil, include_count method_url = "/v1/workspaces/%s/entities/%s/values/%s/synonyms" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1784,6 +1796,7 @@ def create_synonym(workspace_id:, entity:, value:, synonym:) method_url = "/v1/workspaces/%s/entities/%s/values/%s/synonyms" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1830,6 +1843,7 @@ def get_synonym(workspace_id:, entity:, value:, synonym:, include_audit: nil) method_url = "/v1/workspaces/%s/entities/%s/values/%s/synonyms/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value), ERB::Util.url_encode(synonym)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1883,6 +1897,7 @@ def update_synonym(workspace_id:, entity:, value:, synonym:, new_synonym: nil) method_url = "/v1/workspaces/%s/entities/%s/values/%s/synonyms/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value), ERB::Util.url_encode(synonym)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1926,6 +1941,7 @@ def delete_synonym(workspace_id:, entity:, value:, synonym:) method_url = "/v1/workspaces/%s/entities/%s/values/%s/synonyms/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(entity), ERB::Util.url_encode(value), ERB::Util.url_encode(synonym)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1940,7 +1956,7 @@ def delete_synonym(workspace_id:, entity:, value:, synonym:) ######################### ## - # @!method list_dialog_nodes(workspace_id:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + # @!method list_dialog_nodes(workspace_id:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) # List dialog nodes. # List the dialog nodes for a workspace. # @@ -1948,14 +1964,13 @@ def delete_synonym(workspace_id:, entity:, value:, synonym:) # see **Rate limiting**. # @param workspace_id [String] Unique identifier of the workspace. # @param page_limit [Fixnum] The number of records to return in each page of results. - # @param include_count [Boolean] Whether to include information about the number of records returned. # @param sort [String] The attribute by which returned dialog nodes will be sorted. To reverse the sort # order, prefix the value with a minus sign (`-`). # @param cursor [String] A token identifying the page of results to retrieve. # @param include_audit [Boolean] Whether to include the audit properties (`created` and `updated` timestamps) in # the response. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_dialog_nodes(workspace_id:, page_limit: nil, include_count: nil, sort: nil, cursor: nil, include_audit: nil) + def list_dialog_nodes(workspace_id:, page_limit: nil, sort: nil, cursor: nil, include_audit: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? headers = { @@ -1966,7 +1981,6 @@ def list_dialog_nodes(workspace_id:, page_limit: nil, include_count: nil, sort: params = { "version" => @version, "page_limit" => page_limit, - "include_count" => include_count, "sort" => sort, "cursor" => cursor, "include_audit" => include_audit @@ -1974,6 +1988,7 @@ def list_dialog_nodes(workspace_id:, page_limit: nil, include_count: nil, sort: method_url = "/v1/workspaces/%s/dialog_nodes" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1985,7 +2000,7 @@ def list_dialog_nodes(workspace_id:, page_limit: nil, include_count: nil, sort: end ## - # @!method create_dialog_node(workspace_id:, dialog_node:, description: nil, conditions: nil, parent: nil, previous_sibling: nil, output: nil, context: nil, metadata: nil, next_step: nil, title: nil, node_type: nil, event_name: nil, variable: nil, actions: nil, digress_in: nil, digress_out: nil, digress_out_slots: nil, user_label: nil) + # @!method create_dialog_node(workspace_id:, dialog_node:, description: nil, conditions: nil, parent: nil, previous_sibling: nil, output: nil, context: nil, metadata: nil, next_step: nil, title: nil, type: nil, event_name: nil, variable: nil, actions: nil, digress_in: nil, digress_out: nil, digress_out_slots: nil, user_label: nil) # Create dialog node. # Create a new dialog node. # @@ -2016,7 +2031,7 @@ def list_dialog_nodes(workspace_id:, page_limit: nil, include_count: nil, sort: # following restrictions: # - It can contain only Unicode alphanumeric, space, underscore, hyphen, and dot # characters. - # @param node_type [String] How the dialog node is processed. + # @param type [String] How the dialog node is processed. # @param event_name [String] How an `event_handler` node is processed. # @param variable [String] The location in the dialog context where output is stored. # @param actions [Array[DialogNodeAction]] An array of objects describing any actions to be invoked by the dialog node. @@ -2026,7 +2041,7 @@ def list_dialog_nodes(workspace_id:, page_limit: nil, include_count: nil, sort: # @param user_label [String] A label that can be displayed externally to describe the purpose of the node to # users. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def create_dialog_node(workspace_id:, dialog_node:, description: nil, conditions: nil, parent: nil, previous_sibling: nil, output: nil, context: nil, metadata: nil, next_step: nil, title: nil, node_type: nil, event_name: nil, variable: nil, actions: nil, digress_in: nil, digress_out: nil, digress_out_slots: nil, user_label: nil) + def create_dialog_node(workspace_id:, dialog_node:, description: nil, conditions: nil, parent: nil, previous_sibling: nil, output: nil, context: nil, metadata: nil, next_step: nil, title: nil, type: nil, event_name: nil, variable: nil, actions: nil, digress_in: nil, digress_out: nil, digress_out_slots: nil, user_label: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? raise ArgumentError.new("dialog_node must be provided") if dialog_node.nil? @@ -2051,7 +2066,7 @@ def create_dialog_node(workspace_id:, dialog_node:, description: nil, conditions "metadata" => metadata, "next_step" => next_step, "title" => title, - "type" => node_type, + "type" => type, "event_name" => event_name, "variable" => variable, "actions" => actions, @@ -2063,6 +2078,7 @@ def create_dialog_node(workspace_id:, dialog_node:, description: nil, conditions method_url = "/v1/workspaces/%s/dialog_nodes" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2103,6 +2119,7 @@ def get_dialog_node(workspace_id:, dialog_node:, include_audit: nil) method_url = "/v1/workspaces/%s/dialog_nodes/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(dialog_node)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2114,7 +2131,7 @@ def get_dialog_node(workspace_id:, dialog_node:, include_audit: nil) end ## - # @!method update_dialog_node(workspace_id:, dialog_node:, new_dialog_node: nil, new_description: nil, new_conditions: nil, new_parent: nil, new_previous_sibling: nil, new_output: nil, new_context: nil, new_metadata: nil, new_next_step: nil, new_title: nil, new_node_type: nil, new_event_name: nil, new_variable: nil, new_actions: nil, new_digress_in: nil, new_digress_out: nil, new_digress_out_slots: nil, new_user_label: nil) + # @!method update_dialog_node(workspace_id:, dialog_node:, new_dialog_node: nil, new_description: nil, new_conditions: nil, new_parent: nil, new_previous_sibling: nil, new_output: nil, new_context: nil, new_metadata: nil, new_next_step: nil, new_title: nil, new_type: nil, new_event_name: nil, new_variable: nil, new_actions: nil, new_digress_in: nil, new_digress_out: nil, new_digress_out_slots: nil, new_user_label: nil) # Update dialog node. # Update an existing dialog node with new or modified data. # @@ -2146,7 +2163,7 @@ def get_dialog_node(workspace_id:, dialog_node:, include_audit: nil) # following restrictions: # - It can contain only Unicode alphanumeric, space, underscore, hyphen, and dot # characters. - # @param new_node_type [String] How the dialog node is processed. + # @param new_type [String] How the dialog node is processed. # @param new_event_name [String] How an `event_handler` node is processed. # @param new_variable [String] The location in the dialog context where output is stored. # @param new_actions [Array[DialogNodeAction]] An array of objects describing any actions to be invoked by the dialog node. @@ -2156,7 +2173,7 @@ def get_dialog_node(workspace_id:, dialog_node:, include_audit: nil) # @param new_user_label [String] A label that can be displayed externally to describe the purpose of the node to # users. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def update_dialog_node(workspace_id:, dialog_node:, new_dialog_node: nil, new_description: nil, new_conditions: nil, new_parent: nil, new_previous_sibling: nil, new_output: nil, new_context: nil, new_metadata: nil, new_next_step: nil, new_title: nil, new_node_type: nil, new_event_name: nil, new_variable: nil, new_actions: nil, new_digress_in: nil, new_digress_out: nil, new_digress_out_slots: nil, new_user_label: nil) + def update_dialog_node(workspace_id:, dialog_node:, new_dialog_node: nil, new_description: nil, new_conditions: nil, new_parent: nil, new_previous_sibling: nil, new_output: nil, new_context: nil, new_metadata: nil, new_next_step: nil, new_title: nil, new_type: nil, new_event_name: nil, new_variable: nil, new_actions: nil, new_digress_in: nil, new_digress_out: nil, new_digress_out_slots: nil, new_user_label: nil) raise ArgumentError.new("workspace_id must be provided") if workspace_id.nil? raise ArgumentError.new("dialog_node must be provided") if dialog_node.nil? @@ -2181,7 +2198,7 @@ def update_dialog_node(workspace_id:, dialog_node:, new_dialog_node: nil, new_de "metadata" => new_metadata, "next_step" => new_next_step, "title" => new_title, - "type" => new_node_type, + "type" => new_type, "event_name" => new_event_name, "variable" => new_variable, "actions" => new_actions, @@ -2193,6 +2210,7 @@ def update_dialog_node(workspace_id:, dialog_node:, new_dialog_node: nil, new_de method_url = "/v1/workspaces/%s/dialog_nodes/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(dialog_node)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2230,6 +2248,7 @@ def delete_dialog_node(workspace_id:, dialog_node:) method_url = "/v1/workspaces/%s/dialog_nodes/%s" % [ERB::Util.url_encode(workspace_id), ERB::Util.url_encode(dialog_node)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2278,6 +2297,7 @@ def list_logs(workspace_id:, sort: nil, filter: nil, page_limit: nil, cursor: ni method_url = "/v1/workspaces/%s/logs" % [ERB::Util.url_encode(workspace_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2324,6 +2344,7 @@ def list_all_logs(filter:, sort: nil, page_limit: nil, cursor: nil) method_url = "/v1/logs" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2364,6 +2385,7 @@ def delete_user_data(customer_id:) method_url = "/v1/user_data" + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, diff --git a/lib/ibm_watson/assistant_v2.rb b/lib/ibm_watson/assistant_v2.rb index 0f43c49..2f031b1 100644 --- a/lib/ibm_watson/assistant_v2.rb +++ b/lib/ibm_watson/assistant_v2.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -82,21 +82,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/assistant/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "conversation" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Assistant" super - @version = args[:version] end ######################### @@ -129,6 +122,7 @@ def create_session(assistant_id:) method_url = "/v2/assistants/%s/sessions" % [ERB::Util.url_encode(assistant_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -167,6 +161,7 @@ def delete_session(assistant_id:, session_id:) method_url = "/v2/assistants/%s/sessions/%s" % [ERB::Util.url_encode(assistant_id), ERB::Util.url_encode(session_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -219,6 +214,7 @@ def message(assistant_id:, session_id:, input: nil, context: nil) method_url = "/v2/assistants/%s/sessions/%s/message" % [ERB::Util.url_encode(assistant_id), ERB::Util.url_encode(session_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, diff --git a/lib/ibm_watson/compare_comply_v1.rb b/lib/ibm_watson/compare_comply_v1.rb index caf767e..4c0c9ac 100644 --- a/lib/ibm_watson/compare_comply_v1.rb +++ b/lib/ibm_watson/compare_comply_v1.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -81,21 +81,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/compare-comply/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "compare-comply" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Compare Comply" super - @version = args[:version] end ######################### @@ -103,18 +96,17 @@ def initialize(args = {}) ######################### ## - # @!method convert_to_html(file:, filename: nil, file_content_type: nil, model: nil) + # @!method convert_to_html(file:, file_content_type: nil, model: nil) # Convert document to HTML. # Converts a document to HTML. # @param file [File] The document to convert. - # @param filename [String] The filename for file. # @param file_content_type [String] The content type of file. # @param model [String] The analysis model to be used by the service. For the **Element classification** # and **Compare two documents** methods, the default is `contracts`. For the # **Extract tables** method, the default is `tables`. These defaults apply to the # standalone methods as well as to the methods' use in batch-processing requests. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def convert_to_html(file:, filename: nil, file_content_type: nil, model: nil) + def convert_to_html(file:, file_content_type: nil, model: nil) raise ArgumentError.new("file must be provided") if file.nil? headers = { @@ -132,11 +124,11 @@ def convert_to_html(file:, filename: nil, file_content_type: nil, model: nil) unless file.instance_of?(StringIO) || file.instance_of?(File) file = file.respond_to?(:to_json) ? StringIO.new(file.to_json) : StringIO.new(file) end - filename = file.path if filename.nil? && file.respond_to?(:path) - form_data[:file] = HTTP::FormData::File.new(file, content_type: file_content_type.nil? ? "application/octet-stream" : file_content_type, filename: filename) + form_data[:file] = HTTP::FormData::File.new(file, content_type: file_content_type.nil? ? "application/octet-stream" : file_content_type, filename: file.respond_to?(:path) ? file.path : nil) method_url = "/v1/html_conversion" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -184,6 +176,7 @@ def classify_elements(file:, file_content_type: nil, model: nil) method_url = "/v1/element_classification" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -231,6 +224,7 @@ def extract_tables(file:, file_content_type: nil, model: nil) method_url = "/v1/tables" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -291,6 +285,7 @@ def compare_documents(file_1:, file_2:, file_1_content_type: nil, file_2_content method_url = "/v1/comparison" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -337,6 +332,7 @@ def add_feedback(feedback_data:, user_id: nil, comment: nil) method_url = "/v1/feedback" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -364,7 +360,7 @@ def add_feedback(feedback_data:, user_id: nil, comment: nil) # specified `model_id`. The only permitted value is `contracts`. # @param model_version [String] An optional string that filters the output to include only feedback with the # specified `model_version`. - # @param category_removed [String] An optional string in the form of a comma-separated list of categories. If this is + # @param category_removed [String] An optional string in the form of a comma-separated list of categories. If it is # specified, the service filters the output to include only feedback that has at # least one category from the list removed. # @param category_added [String] An optional string in the form of a comma-separated list of categories. If this is @@ -422,6 +418,7 @@ def list_feedback(feedback_type: nil, before: nil, after: nil, document_title: n method_url = "/v1/feedback" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -457,6 +454,7 @@ def get_feedback(feedback_id:, model: nil) method_url = "/v1/feedback/%s" % [ERB::Util.url_encode(feedback_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -492,6 +490,7 @@ def delete_feedback(feedback_id:, model: nil) method_url = "/v1/feedback/%s" % [ERB::Util.url_encode(feedback_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, @@ -583,6 +582,7 @@ def create_batch(function:, input_credentials_file:, input_bucket_location:, inp method_url = "/v1/batches" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -611,6 +611,7 @@ def list_batches method_url = "/v1/batches" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -641,6 +642,7 @@ def get_batch(batch_id:) method_url = "/v1/batches/%s" % [ERB::Util.url_encode(batch_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -681,6 +683,7 @@ def update_batch(batch_id:, action:, model: nil) method_url = "/v1/batches/%s" % [ERB::Util.url_encode(batch_id)] + headers = authenticator.authenticate(headers) response = request( method: "PUT", url: method_url, diff --git a/lib/ibm_watson/discovery_v1.rb b/lib/ibm_watson/discovery_v1.rb index 37d5447..5cd1f63 100644 --- a/lib/ibm_watson/discovery_v1.rb +++ b/lib/ibm_watson/discovery_v1.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -84,21 +84,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/discovery/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "discovery" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Discovery" super - @version = args[:version] end ######################### @@ -138,6 +131,7 @@ def create_environment(name:, description: nil, size: nil) method_url = "/v1/environments" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -168,6 +162,7 @@ def list_environments(name: nil) method_url = "/v1/environments" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -197,6 +192,7 @@ def get_environment(environment_id:) method_url = "/v1/environments/%s" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -239,6 +235,7 @@ def update_environment(environment_id:, name: nil, description: nil, size: nil) method_url = "/v1/environments/%s" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "PUT", url: method_url, @@ -269,6 +266,7 @@ def delete_environment(environment_id:) method_url = "/v1/environments/%s" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, @@ -304,6 +302,7 @@ def list_fields(environment_id:, collection_ids:) method_url = "/v1/environments/%s/fields" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -367,6 +366,7 @@ def create_configuration(environment_id:, name:, description: nil, conversions: method_url = "/v1/environments/%s/configurations" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -400,6 +400,7 @@ def list_configurations(environment_id:, name: nil) method_url = "/v1/environments/%s/configurations" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -432,6 +433,7 @@ def get_configuration(environment_id:, configuration_id:) method_url = "/v1/environments/%s/configurations/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(configuration_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -492,6 +494,7 @@ def update_configuration(environment_id:, configuration_id:, name:, description: method_url = "/v1/environments/%s/configurations/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(configuration_id)] + headers = authenticator.authenticate(headers) response = request( method: "PUT", url: method_url, @@ -531,6 +534,7 @@ def delete_configuration(environment_id:, configuration_id:) method_url = "/v1/environments/%s/configurations/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(configuration_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, @@ -558,9 +562,8 @@ def delete_configuration(environment_id:, configuration_id:) # the provided configuration is used to process the document. If the # **configuration_id** is also provided (both are present at the same time), then # request is rejected. The maximum supported configuration size is 1 MB. - # Configuration parts larger than 1 MB are rejected. - # See the `GET /configurations/{configuration_id}` operation for an example - # configuration. + # Configuration parts larger than 1 MB are rejected. See the `GET + # /configurations/{configuration_id}` operation for an example configuration. # @param file [File] The content of the document to ingest. The maximum supported file size when adding # a file to a collection is 50 megabytes, the maximum supported file size when # testing a confiruration is 1 megabyte. Files larger than the supported size are @@ -568,10 +571,9 @@ def delete_configuration(environment_id:, configuration_id:) # @param filename [String] The filename for file. # @param file_content_type [String] The content type of file. # @param metadata [String] The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB - # are rejected. - # Example: ``` { - # \"Creator\": \"Johnny Appleseed\", - # \"Subject\": \"Apples\" + # are rejected. Example: ``` { + # "Creator": "Johnny Appleseed", + # "Subject": "Apples" # } ```. # @param step [String] Specify to only run the input document through the given step instead of running # the input document through the entire ingestion workflow. Valid values are @@ -610,6 +612,7 @@ def test_configuration_in_environment(environment_id:, configuration: nil, file: method_url = "/v1/environments/%s/preview" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -657,6 +660,7 @@ def create_collection(environment_id:, name:, description: nil, configuration_id method_url = "/v1/environments/%s/collections" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -690,6 +694,7 @@ def list_collections(environment_id:, name: nil) method_url = "/v1/environments/%s/collections" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -722,6 +727,7 @@ def get_collection(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -763,6 +769,7 @@ def update_collection(environment_id:, collection_id:, name:, description: nil, method_url = "/v1/environments/%s/collections/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "PUT", url: method_url, @@ -796,6 +803,7 @@ def delete_collection(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, @@ -829,6 +837,7 @@ def list_collection_fields(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/fields" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -866,6 +875,7 @@ def list_expansions(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/expansions" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -880,8 +890,8 @@ def list_expansions(environment_id:, collection_id:) # @!method create_expansions(environment_id:, collection_id:, expansions:) # Create or update expansion list. # Create or replace the Expansion list for this collection. The maximum number of - # expanded terms per collection is `500`. - # The current expansion list is replaced with the uploaded content. + # expanded terms per collection is `500`. The current expansion list is replaced + # with the uploaded content. # @param environment_id [String] The ID of the environment. # @param collection_id [String] The ID of the collection. # @param expansions [Array[Expansion]] An array of query expansion definitions. @@ -923,6 +933,7 @@ def create_expansions(environment_id:, collection_id:, expansions:) method_url = "/v1/environments/%s/collections/%s/expansions" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -958,6 +969,7 @@ def delete_expansions(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/expansions" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -992,6 +1004,7 @@ def get_tokenization_dictionary_status(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/word_lists/tokenization_dictionary" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1032,6 +1045,7 @@ def create_tokenization_dictionary(environment_id:, collection_id:, tokenization method_url = "/v1/environments/%s/collections/%s/word_lists/tokenization_dictionary" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1066,6 +1080,7 @@ def delete_tokenization_dictionary(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/word_lists/tokenization_dictionary" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1099,6 +1114,7 @@ def get_stopword_list_status(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/word_lists/stopwords" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1144,6 +1160,7 @@ def create_stopword_list(environment_id:, collection_id:, stopword_file:, stopwo method_url = "/v1/environments/%s/collections/%s/word_lists/stopwords" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1179,6 +1196,7 @@ def delete_stopword_list(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/word_lists/stopwords" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1232,10 +1250,9 @@ def delete_stopword_list(environment_id:, collection_id:) # @param filename [String] The filename for file. # @param file_content_type [String] The content type of file. # @param metadata [String] The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB - # are rejected. - # Example: ``` { - # \"Creator\": \"Johnny Appleseed\", - # \"Subject\": \"Apples\" + # are rejected. Example: ``` { + # "Creator": "Johnny Appleseed", + # "Subject": "Apples" # } ```. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. def add_document(environment_id:, collection_id:, file: nil, filename: nil, file_content_type: nil, metadata: nil) @@ -1266,6 +1283,7 @@ def add_document(environment_id:, collection_id:, file: nil, filename: nil, file method_url = "/v1/environments/%s/collections/%s/documents" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1306,6 +1324,7 @@ def get_document_status(environment_id:, collection_id:, document_id:) method_url = "/v1/environments/%s/collections/%s/documents/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(document_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1334,10 +1353,9 @@ def get_document_status(environment_id:, collection_id:, document_id:) # @param filename [String] The filename for file. # @param file_content_type [String] The content type of file. # @param metadata [String] The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB - # are rejected. - # Example: ``` { - # \"Creator\": \"Johnny Appleseed\", - # \"Subject\": \"Apples\" + # are rejected. Example: ``` { + # "Creator": "Johnny Appleseed", + # "Subject": "Apples" # } ```. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. def update_document(environment_id:, collection_id:, document_id:, file: nil, filename: nil, file_content_type: nil, metadata: nil) @@ -1370,6 +1388,7 @@ def update_document(environment_id:, collection_id:, document_id:, file: nil, fi method_url = "/v1/environments/%s/collections/%s/documents/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(document_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1409,6 +1428,7 @@ def delete_document(environment_id:, collection_id:, document_id:) method_url = "/v1/environments/%s/collections/%s/documents/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(document_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, @@ -1423,7 +1443,7 @@ def delete_document(environment_id:, collection_id:, document_id:) ######################### ## - # @!method query(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, logging_opt_out: nil) + # @!method query(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, x_watson_logging_opt_out: nil) # Query a collection. # By using this method, you can construct long queries. For details, see the # [Discovery @@ -1443,7 +1463,7 @@ def delete_document(environment_id:, collection_id:, document_id:) # filters. Useful for applications to build lists, tables, and time series. For a # full list of possible aggregations, see the Query reference. # @param count [Fixnum] Number of results to return. - # @param return_fields [String] A comma-separated list of the portion of the document hierarchy to return. + # @param _return [String] A comma-separated list of the portion of the document hierarchy to return. # @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total # number of results that are returned is 10 and the offset is 8, it returns the last # two results. @@ -1484,15 +1504,15 @@ def delete_document(environment_id:, collection_id:, document_id:) # a **number** type field is specified, returned results are biased towards higher # field values. This parameter cannot be used in the same query as the **sort** # parameter. - # @param logging_opt_out [Boolean] If `true`, queries are not stored in the Discovery **Logs** endpoint. + # @param x_watson_logging_opt_out [Boolean] If `true`, queries are not stored in the Discovery **Logs** endpoint. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def query(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, logging_opt_out: nil) + def query(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, x_watson_logging_opt_out: nil) raise ArgumentError.new("environment_id must be provided") if environment_id.nil? raise ArgumentError.new("collection_id must be provided") if collection_id.nil? headers = { - "X-Watson-Logging-Opt-Out" => logging_opt_out + "X-Watson-Logging-Opt-Out" => x_watson_logging_opt_out } sdk_headers = Common.new.get_sdk_headers("discovery", "V1", "query") headers.merge!(sdk_headers) @@ -1508,7 +1528,7 @@ def query(environment_id:, collection_id:, filter: nil, query: nil, natural_lang "passages" => passages, "aggregation" => aggregation, "count" => count, - "return" => return_fields, + "return" => _return, "offset" => offset, "sort" => sort, "highlight" => highlight, @@ -1526,6 +1546,7 @@ def query(environment_id:, collection_id:, filter: nil, query: nil, natural_lang method_url = "/v1/environments/%s/collections/%s/query" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1538,7 +1559,7 @@ def query(environment_id:, collection_id:, filter: nil, query: nil, natural_lang end ## - # @!method query_notices(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) + # @!method query_notices(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) # Query system notices. # Queries for notices (errors or warnings) that might have been generated by the # system. Notices are generated when ingesting documents and performing relevance @@ -1560,7 +1581,7 @@ def query(environment_id:, collection_id:, filter: nil, query: nil, natural_lang # full list of possible aggregations, see the Query reference. # @param count [Fixnum] Number of results to return. The maximum for the **count** and **offset** values # together in any one query is **10000**. - # @param return_fields [Array[String]] A comma-separated list of the portion of the document hierarchy to return. + # @param _return [Array[String]] A comma-separated list of the portion of the document hierarchy to return. # @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total # number of results that are returned is 10 and the offset is 8, it returns the last # two results. The maximum for the **count** and **offset** values together in any @@ -1590,7 +1611,7 @@ def query(environment_id:, collection_id:, filter: nil, query: nil, natural_lang # identify similar documents. If not specified, the entire document is used for # comparison. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) + def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) raise ArgumentError.new("environment_id must be provided") if environment_id.nil? raise ArgumentError.new("collection_id must be provided") if collection_id.nil? @@ -1608,7 +1629,7 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu "passages" => passages, "aggregation" => aggregation, "count" => count, - "return" => return_fields.to_a, + "return" => _return.to_a, "offset" => offset, "sort" => sort.to_a, "highlight" => highlight, @@ -1623,6 +1644,7 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu method_url = "/v1/environments/%s/collections/%s/notices" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1634,7 +1656,7 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu end ## - # @!method federated_query(environment_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, logging_opt_out: nil) + # @!method federated_query(environment_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, x_watson_logging_opt_out: nil) # Query multiple collections. # By using this method, you can construct long queries that search multiple # collection. For details, see the [Discovery @@ -1653,7 +1675,7 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu # filters. Useful for applications to build lists, tables, and time series. For a # full list of possible aggregations, see the Query reference. # @param count [Fixnum] Number of results to return. - # @param return_fields [String] A comma-separated list of the portion of the document hierarchy to return. + # @param _return [String] A comma-separated list of the portion of the document hierarchy to return. # @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total # number of results that are returned is 10 and the offset is 8, it returns the last # two results. @@ -1694,13 +1716,13 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu # a **number** type field is specified, returned results are biased towards higher # field values. This parameter cannot be used in the same query as the **sort** # parameter. - # @param logging_opt_out [Boolean] If `true`, queries are not stored in the Discovery **Logs** endpoint. + # @param x_watson_logging_opt_out [Boolean] If `true`, queries are not stored in the Discovery **Logs** endpoint. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def federated_query(environment_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, logging_opt_out: nil) + def federated_query(environment_id:, filter: nil, query: nil, natural_language_query: nil, passages: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, passages_fields: nil, passages_count: nil, passages_characters: nil, deduplicate: nil, deduplicate_field: nil, collection_ids: nil, similar: nil, similar_document_ids: nil, similar_fields: nil, bias: nil, x_watson_logging_opt_out: nil) raise ArgumentError.new("environment_id must be provided") if environment_id.nil? headers = { - "X-Watson-Logging-Opt-Out" => logging_opt_out + "X-Watson-Logging-Opt-Out" => x_watson_logging_opt_out } sdk_headers = Common.new.get_sdk_headers("discovery", "V1", "federated_query") headers.merge!(sdk_headers) @@ -1716,7 +1738,7 @@ def federated_query(environment_id:, filter: nil, query: nil, natural_language_q "passages" => passages, "aggregation" => aggregation, "count" => count, - "return" => return_fields, + "return" => _return, "offset" => offset, "sort" => sort, "highlight" => highlight, @@ -1734,6 +1756,7 @@ def federated_query(environment_id:, filter: nil, query: nil, natural_language_q method_url = "/v1/environments/%s/query" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1746,7 +1769,7 @@ def federated_query(environment_id:, filter: nil, query: nil, natural_language_q end ## - # @!method federated_query_notices(environment_id:, collection_ids:, filter: nil, query: nil, natural_language_query: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) + # @!method federated_query_notices(environment_id:, collection_ids:, filter: nil, query: nil, natural_language_query: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) # Query multiple collection system notices. # Queries for notices (errors or warnings) that might have been generated by the # system. Notices are generated when ingesting documents and performing relevance @@ -1767,7 +1790,7 @@ def federated_query(environment_id:, filter: nil, query: nil, natural_language_q # full list of possible aggregations, see the Query reference. # @param count [Fixnum] Number of results to return. The maximum for the **count** and **offset** values # together in any one query is **10000**. - # @param return_fields [Array[String]] A comma-separated list of the portion of the document hierarchy to return. + # @param _return [Array[String]] A comma-separated list of the portion of the document hierarchy to return. # @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total # number of results that are returned is 10 and the offset is 8, it returns the last # two results. The maximum for the **count** and **offset** values together in any @@ -1792,7 +1815,7 @@ def federated_query(environment_id:, filter: nil, query: nil, natural_language_q # identify similar documents. If not specified, the entire document is used for # comparison. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def federated_query_notices(environment_id:, collection_ids:, filter: nil, query: nil, natural_language_query: nil, aggregation: nil, count: nil, return_fields: nil, offset: nil, sort: nil, highlight: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) + def federated_query_notices(environment_id:, collection_ids:, filter: nil, query: nil, natural_language_query: nil, aggregation: nil, count: nil, _return: nil, offset: nil, sort: nil, highlight: nil, deduplicate_field: nil, similar: nil, similar_document_ids: nil, similar_fields: nil) raise ArgumentError.new("environment_id must be provided") if environment_id.nil? raise ArgumentError.new("collection_ids must be provided") if collection_ids.nil? @@ -1810,7 +1833,7 @@ def federated_query_notices(environment_id:, collection_ids:, filter: nil, query "natural_language_query" => natural_language_query, "aggregation" => aggregation, "count" => count, - "return" => return_fields.to_a, + "return" => _return.to_a, "offset" => offset, "sort" => sort.to_a, "highlight" => highlight, @@ -1822,6 +1845,7 @@ def federated_query_notices(environment_id:, collection_ids:, filter: nil, query method_url = "/v1/environments/%s/notices" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1874,6 +1898,7 @@ def query_entities(environment_id:, collection_id:, feature: nil, entity: nil, c method_url = "/v1/environments/%s/collections/%s/query_entities" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1931,6 +1956,7 @@ def query_relations(environment_id:, collection_id:, entities: nil, context: nil method_url = "/v1/environments/%s/collections/%s/query_relations" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1968,6 +1994,7 @@ def list_training_data(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/training_data" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2012,6 +2039,7 @@ def add_training_data(environment_id:, collection_id:, natural_language_query: n method_url = "/v1/environments/%s/collections/%s/training_data" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2046,6 +2074,7 @@ def delete_all_training_data(environment_id:, collection_id:) method_url = "/v1/environments/%s/collections/%s/training_data" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2083,6 +2112,7 @@ def get_training_data(environment_id:, collection_id:, query_id:) method_url = "/v1/environments/%s/collections/%s/training_data/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(query_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2120,6 +2150,7 @@ def delete_training_data(environment_id:, collection_id:, query_id:) method_url = "/v1/environments/%s/collections/%s/training_data/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(query_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2156,6 +2187,7 @@ def list_training_examples(environment_id:, collection_id:, query_id:) method_url = "/v1/environments/%s/collections/%s/training_data/%s/examples" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(query_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2201,6 +2233,7 @@ def create_training_example(environment_id:, collection_id:, query_id:, document method_url = "/v1/environments/%s/collections/%s/training_data/%s/examples" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(query_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2241,6 +2274,7 @@ def delete_training_example(environment_id:, collection_id:, query_id:, example_ method_url = "/v1/environments/%s/collections/%s/training_data/%s/examples/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(query_id), ERB::Util.url_encode(example_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2287,6 +2321,7 @@ def update_training_example(environment_id:, collection_id:, query_id:, example_ method_url = "/v1/environments/%s/collections/%s/training_data/%s/examples/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(query_id), ERB::Util.url_encode(example_id)] + headers = authenticator.authenticate(headers) response = request( method: "PUT", url: method_url, @@ -2327,6 +2362,7 @@ def get_training_example(environment_id:, collection_id:, query_id:, example_id: method_url = "/v1/environments/%s/collections/%s/training_data/%s/examples/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(collection_id), ERB::Util.url_encode(query_id), ERB::Util.url_encode(example_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2367,6 +2403,7 @@ def delete_user_data(customer_id:) method_url = "/v1/user_data" + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2385,7 +2422,7 @@ def delete_user_data(customer_id:) # Create event. # The **Events** API can be used to create log entries that are associated with # specific queries. For example, you can record which documents in the results set - # were \"clicked\" by a user and when that click occured. + # were "clicked" by a user and when that click occured. # @param type [String] The event type to be created. # @param data [EventData] Query event data object. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. @@ -2410,6 +2447,7 @@ def create_event(type:, data:) method_url = "/v1/events" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2459,6 +2497,7 @@ def query_log(filter: nil, query: nil, count: nil, offset: nil, sort: nil) method_url = "/v1/logs" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2495,6 +2534,7 @@ def get_metrics_query(start_time: nil, end_time: nil, result_type: nil) method_url = "/v1/metrics/number_of_queries" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2509,7 +2549,7 @@ def get_metrics_query(start_time: nil, end_time: nil, result_type: nil) # @!method get_metrics_query_event(start_time: nil, end_time: nil, result_type: nil) # Number of queries with an event over time. # Total number of queries using the **natural_language_query** parameter that have a - # corresponding \"click\" event over a specified time window. This metric requires + # corresponding "click" event over a specified time window. This metric requires # having integrated event tracking in your application using the **Events** API. # @param start_time [Time] Metric is computed from data recorded after this timestamp; must be in # `YYYY-MM-DDThh:mm:ssZ` format. @@ -2532,6 +2572,7 @@ def get_metrics_query_event(start_time: nil, end_time: nil, result_type: nil) method_url = "/v1/metrics/number_of_queries_with_event" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2568,6 +2609,7 @@ def get_metrics_query_no_results(start_time: nil, end_time: nil, result_type: ni method_url = "/v1/metrics/number_of_queries_with_no_search_results" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2582,9 +2624,8 @@ def get_metrics_query_no_results(start_time: nil, end_time: nil, result_type: ni # @!method get_metrics_event_rate(start_time: nil, end_time: nil, result_type: nil) # Percentage of queries with an associated event. # The percentage of queries using the **natural_language_query** parameter that have - # a corresponding \"click\" event over a specified time window. This metric - # requires having integrated event tracking in your application using the **Events** - # API. + # a corresponding "click" event over a specified time window. This metric requires + # having integrated event tracking in your application using the **Events** API. # @param start_time [Time] Metric is computed from data recorded after this timestamp; must be in # `YYYY-MM-DDThh:mm:ssZ` format. # @param end_time [Time] Metric is computed from data recorded before this timestamp; must be in @@ -2606,6 +2647,7 @@ def get_metrics_event_rate(start_time: nil, end_time: nil, result_type: nil) method_url = "/v1/metrics/event_rate" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2620,7 +2662,7 @@ def get_metrics_event_rate(start_time: nil, end_time: nil, result_type: nil) # @!method get_metrics_query_token_event(count: nil) # Most frequent query tokens with an event. # The most frequent query tokens parsed from the **natural_language_query** - # parameter and their corresponding \"click\" event rate within the recording period + # parameter and their corresponding "click" event rate within the recording period # (queries and events are stored for 30 days). A query token is an individual word # or unigram within the query string. # @param count [Fixnum] Number of results to return. The maximum for the **count** and **offset** values @@ -2639,6 +2681,7 @@ def get_metrics_query_token_event(count: nil) method_url = "/v1/metrics/top_query_tokens_with_event_rate" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2675,6 +2718,7 @@ def list_credentials(environment_id:) method_url = "/v1/environments/%s/credentials" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2731,6 +2775,7 @@ def create_credentials(environment_id:, source_type: nil, credential_details: ni method_url = "/v1/environments/%s/credentials" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2768,6 +2813,7 @@ def get_credentials(environment_id:, credential_id:) method_url = "/v1/environments/%s/credentials/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(credential_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2826,6 +2872,7 @@ def update_credentials(environment_id:, credential_id:, source_type: nil, creden method_url = "/v1/environments/%s/credentials/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(credential_id)] + headers = authenticator.authenticate(headers) response = request( method: "PUT", url: method_url, @@ -2860,6 +2907,7 @@ def delete_credentials(environment_id:, credential_id:) method_url = "/v1/environments/%s/credentials/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(credential_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, @@ -2893,6 +2941,7 @@ def list_gateways(environment_id:) method_url = "/v1/environments/%s/gateways" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2928,6 +2977,7 @@ def create_gateway(environment_id:, name: nil) method_url = "/v1/environments/%s/gateways" % [ERB::Util.url_encode(environment_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2962,6 +3012,7 @@ def get_gateway(environment_id:, gateway_id:) method_url = "/v1/environments/%s/gateways/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(gateway_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2995,6 +3046,7 @@ def delete_gateway(environment_id:, gateway_id:) method_url = "/v1/environments/%s/gateways/%s" % [ERB::Util.url_encode(environment_id), ERB::Util.url_encode(gateway_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, diff --git a/lib/ibm_watson/language_translator_v3.rb b/lib/ibm_watson/language_translator_v3.rb index 33a2b72..f0bf7ce 100644 --- a/lib/ibm_watson/language_translator_v3.rb +++ b/lib/ibm_watson/language_translator_v3.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -71,12 +71,6 @@ class LanguageTranslatorV3 < IBMCloudSdkCore::BaseService # 'https://iam.cloud.ibm.com/identity/token'. # @option args iam_client_id [String] An optional client id for the IAM service API. # @option args iam_client_secret [String] An optional client secret for the IAM service API. - # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is - # fully managed by the application. Responsibility falls on the application to - # refresh the token, either before it expires or reactively upon receiving a 401 - # from the service as any requests made with an expired token will fail. - # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this - # URL must be passed in. # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it # takes are basic, iam or icp4d. def initialize(args = {}) @@ -84,21 +78,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/language-translator/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "language_translator" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Language Translator" super - @version = args[:version] end ######################### @@ -137,6 +124,7 @@ def translate(text:, model_id: nil, source: nil, target: nil) method_url = "/v3/translate" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -169,6 +157,7 @@ def list_identifiable_languages method_url = "/v3/identifiable_languages" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -202,6 +191,7 @@ def identify(text:) method_url = "/v3/identify" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -217,17 +207,17 @@ def identify(text:) ######################### ## - # @!method list_models(source: nil, target: nil, default_models: nil) + # @!method list_models(source: nil, target: nil, default: nil) # List models. # Lists available translation models. # @param source [String] Specify a language code to filter results by source language. # @param target [String] Specify a language code to filter results by target language. - # @param default_models [Boolean] If the default parameter isn't specified, the service will return all models + # @param default [Boolean] If the default parameter isn't specified, the service will return all models # (default and non-default) for each language pair. To return only default models, # set this to `true`. To return only non-default models, set this to `false`. There # is exactly one default model per language pair, the IBM provided base model. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def list_models(source: nil, target: nil, default_models: nil) + def list_models(source: nil, target: nil, default: nil) headers = { } sdk_headers = Common.new.get_sdk_headers("language_translator", "V3", "list_models") @@ -237,11 +227,12 @@ def list_models(source: nil, target: nil, default_models: nil) "version" => @version, "source" => source, "target" => target, - "default" => default_models + "default" => default } method_url = "/v3/models" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -318,6 +309,7 @@ def create_model(base_model_id:, forced_glossary: nil, parallel_corpus: nil, nam method_url = "/v3/models" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -349,6 +341,7 @@ def delete_model(model_id:) method_url = "/v3/models/%s" % [ERB::Util.url_encode(model_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, @@ -381,6 +374,7 @@ def get_model(model_id:) method_url = "/v3/models/%s" % [ERB::Util.url_encode(model_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -411,6 +405,7 @@ def list_documents method_url = "/v3/documents" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -444,7 +439,6 @@ def list_documents # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. def translate_document(file:, filename: nil, file_content_type: nil, model_id: nil, source: nil, target: nil, document_id: nil) raise ArgumentError.new("file must be provided") if file.nil? - raise ArgumentError.new("filename must be provided") if filename.nil? headers = { } @@ -473,6 +467,7 @@ def translate_document(file:, filename: nil, file_content_type: nil, model_id: n method_url = "/v3/documents" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -504,6 +499,7 @@ def get_document_status(document_id:) method_url = "/v3/documents/%s" % [ERB::Util.url_encode(document_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -534,6 +530,7 @@ def delete_document(document_id:) method_url = "/v3/documents/%s" % [ERB::Util.url_encode(document_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -578,6 +575,7 @@ def get_translated_document(document_id:, accept: nil) method_url = "/v3/documents/%s/translated_document" % [ERB::Util.url_encode(document_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, diff --git a/lib/ibm_watson/natural_language_classifier_v1.rb b/lib/ibm_watson/natural_language_classifier_v1.rb index 6c8345b..a2927d8 100644 --- a/lib/ibm_watson/natural_language_classifier_v1.rb +++ b/lib/ibm_watson/natural_language_classifier_v1.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -60,30 +60,15 @@ class NaturalLanguageClassifierV1 < IBMCloudSdkCore::BaseService # 'https://iam.cloud.ibm.com/identity/token'. # @option args iam_client_id [String] An optional client id for the IAM service API. # @option args iam_client_secret [String] An optional client secret for the IAM service API. - # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is - # fully managed by the application. Responsibility falls on the application to - # refresh the token, either before it expires or reactively upon receiving a 401 - # from the service as any requests made with an expired token will fail. - # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this - # URL must be passed in. # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it # takes are basic, iam or icp4d. def initialize(args = {}) @__async_initialized__ = false defaults = {} defaults[:url] = "https://gateway.watsonplatform.net/natural-language-classifier/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "natural_language_classifier" args[:display_name] = "Natural Language Classifier" super end @@ -116,6 +101,7 @@ def classify(classifier_id:, text:) method_url = "/v1/classifiers/%s/classify" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -152,6 +138,7 @@ def classify_collection(classifier_id:, collection:) method_url = "/v1/classifiers/%s/classify_collection" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -166,11 +153,11 @@ def classify_collection(classifier_id:, collection:) ######################### ## - # @!method create_classifier(metadata:, training_data:) + # @!method create_classifier(training_metadata:, training_data:) # Create classifier. # Sends data to create and train a classifier and returns information about the new # classifier. - # @param metadata [File] Metadata in JSON format. The metadata identifies the language of the data, and an + # @param training_metadata [File] Metadata in JSON format. The metadata identifies the language of the data, and an # optional name to identify the classifier. Specify the language with the 2-letter # primary language code as assigned in ISO standard 639. # @@ -181,8 +168,8 @@ def classify_collection(classifier_id:, collection:) # data can include up to 3,000 classes and 20,000 records. For details, see [Data # preparation](https://cloud.ibm.com/docs/services/natural-language-classifier?topic=natural-language-classifier-using-your-data). # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def create_classifier(metadata:, training_data:) - raise ArgumentError.new("metadata must be provided") if metadata.nil? + def create_classifier(training_metadata:, training_data:) + raise ArgumentError.new("training_metadata must be provided") if training_metadata.nil? raise ArgumentError.new("training_data must be provided") if training_data.nil? @@ -193,10 +180,10 @@ def create_classifier(metadata:, training_data:) form_data = {} - unless metadata.instance_of?(StringIO) || metadata.instance_of?(File) - metadata = metadata.respond_to?(:to_json) ? StringIO.new(metadata.to_json) : StringIO.new(metadata) + unless training_metadata.instance_of?(StringIO) || training_metadata.instance_of?(File) + training_metadata = training_metadata.respond_to?(:to_json) ? StringIO.new(training_metadata.to_json) : StringIO.new(training_metadata) end - form_data[:training_metadata] = HTTP::FormData::File.new(metadata, content_type: "application/json", filename: metadata.respond_to?(:path) ? metadata.path : nil) + form_data[:training_metadata] = HTTP::FormData::File.new(training_metadata, content_type: "application/json", filename: training_metadata.respond_to?(:path) ? training_metadata.path : nil) unless training_data.instance_of?(StringIO) || training_data.instance_of?(File) training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data) @@ -205,6 +192,7 @@ def create_classifier(metadata:, training_data:) method_url = "/v1/classifiers" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -228,6 +216,7 @@ def list_classifiers method_url = "/v1/classifiers" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -253,6 +242,7 @@ def get_classifier(classifier_id:) method_url = "/v1/classifiers/%s" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -277,6 +267,7 @@ def delete_classifier(classifier_id:) method_url = "/v1/classifiers/%s" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, diff --git a/lib/ibm_watson/natural_language_understanding_v1.rb b/lib/ibm_watson/natural_language_understanding_v1.rb index 99bc2d4..bc53994 100644 --- a/lib/ibm_watson/natural_language_understanding_v1.rb +++ b/lib/ibm_watson/natural_language_understanding_v1.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -88,21 +88,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/natural-language-understanding/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "natural-language-understanding" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Natural Language Understanding" super - @version = args[:version] end ######################### @@ -175,6 +168,7 @@ def analyze(features:, text: nil, html: nil, url: nil, clean: nil, xpath: nil, f method_url = "/v1/analyze" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -208,6 +202,7 @@ def list_models method_url = "/v1/models" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -238,6 +233,7 @@ def delete_model(model_id:) method_url = "/v1/models/%s" % [ERB::Util.url_encode(model_id)] + headers = authenticator.authenticate(headers) response = request( method: "DELETE", url: method_url, diff --git a/lib/ibm_watson/personality_insights_v3.rb b/lib/ibm_watson/personality_insights_v3.rb index b1d7625..2e53125 100644 --- a/lib/ibm_watson/personality_insights_v3.rb +++ b/lib/ibm_watson/personality_insights_v3.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -86,12 +86,6 @@ class PersonalityInsightsV3 < IBMCloudSdkCore::BaseService # 'https://iam.cloud.ibm.com/identity/token'. # @option args iam_client_id [String] An optional client id for the IAM service API. # @option args iam_client_secret [String] An optional client secret for the IAM service API. - # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is - # fully managed by the application. Responsibility falls on the application to - # refresh the token, either before it expires or reactively upon receiving a 401 - # from the service as any requests made with an expired token will fail. - # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this - # URL must be passed in. # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it # takes are basic, iam or icp4d. def initialize(args = {}) @@ -99,21 +93,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/personality-insights/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "personality_insights" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Personality Insights" super - @version = args[:version] end ######################### @@ -121,7 +108,7 @@ def initialize(args = {}) ######################### ## - # @!method profile(content:, accept:, content_language: nil, accept_language: nil, raw_scores: nil, csv_headers: nil, consumption_preferences: nil, content_type: nil) + # @!method profile(content:, accept:, content_type: nil, content_language: nil, accept_language: nil, raw_scores: nil, csv_headers: nil, consumption_preferences: nil) # Get profile. # Generates a personality profile for the author of the input text. The service # accepts a maximum of 20 MB of input content, but it requires much less text to @@ -172,6 +159,8 @@ def initialize(args = {}) # For JSON input, provide an object of type `Content`. # @param accept [String] The type of the response. For more information, see **Accept types** in the method # description. + # @param content_type [String] The type of the input. For more information, see **Content types** in the method + # description. # @param content_language [String] The language of the input text for the request: Arabic, English, Japanese, Korean, # or Spanish. Regional variants are treated as their parent language; for example, # `en-US` is interpreted as `en`. @@ -196,19 +185,17 @@ def initialize(args = {}) # (`text/csv`). # @param consumption_preferences [Boolean] Indicates whether consumption preferences are returned with the results. By # default, no consumption preferences are returned. - # @param content_type [String] The type of the input. For more information, see **Content types** in the method - # description. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def profile(content:, accept:, content_language: nil, accept_language: nil, raw_scores: nil, csv_headers: nil, consumption_preferences: nil, content_type: nil) + def profile(content:, accept:, content_type: nil, content_language: nil, accept_language: nil, raw_scores: nil, csv_headers: nil, consumption_preferences: nil) raise ArgumentError.new("content must be provided") if content.nil? raise ArgumentError.new("accept must be provided") if accept.nil? headers = { "Accept" => accept, + "Content-Type" => content_type, "Content-Language" => content_language, - "Accept-Language" => accept_language, - "Content-Type" => content_type + "Accept-Language" => accept_language } sdk_headers = Common.new.get_sdk_headers("personality_insights", "V3", "profile") headers.merge!(sdk_headers) @@ -228,6 +215,7 @@ def profile(content:, accept:, content_language: nil, accept_language: nil, raw_ method_url = "/v3/profile" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, diff --git a/lib/ibm_watson/speech_to_text_v1.rb b/lib/ibm_watson/speech_to_text_v1.rb index 60ec966..87ca9f4 100644 --- a/lib/ibm_watson/speech_to_text_v1.rb +++ b/lib/ibm_watson/speech_to_text_v1.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -91,18 +91,9 @@ def initialize(args = {}) @__async_initialized__ = false defaults = {} defaults[:url] = "https://stream.watsonplatform.net/speech-to-text/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "speech_to_text" args[:display_name] = "Speech to Text" super end @@ -129,6 +120,7 @@ def list_models method_url = "/v1/models" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -160,6 +152,7 @@ def get_model(model_id:) method_url = "/v1/models/%s" % [ERB::Util.url_encode(model_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -173,7 +166,7 @@ def get_model(model_id:) ######################### ## - # @!method recognize(audio:, model: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, audio_metrics: nil, content_type: nil) + # @!method recognize(audio:, content_type: nil, model: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, audio_metrics: nil) # Recognize audio. # Sends audio and returns transcription results for a recognition request. You can # pass a maximum of 100 MB and a minimum of 100 bytes of audio with a request. The @@ -212,7 +205,7 @@ def get_model(model_id:) # * For all other formats, you can omit the `Content-Type` header or specify # `application/octet-stream` with the header to have the service automatically # detect the format of the audio. (With the `curl` command, you can specify either - # `\"Content-Type:\"` or `\"Content-Type: application/octet-stream\"`.) + # `"Content-Type:"` or `"Content-Type: application/octet-stream"`.) # # Where indicated, the format that you specify must include the sampling rate and # can optionally include the number of channels and the endianness of the audio. @@ -262,6 +255,8 @@ def get_model(model_id:) # **See also:** [Making a multipart HTTP # request](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-http#HTTP-multi). # @param audio [String] The audio to transcribe. + # @param content_type [String] The format (MIME type) of the audio. For more information about specifying an + # audio format, see **Audio formats (content types)** in the method description. # @param model [String] The identifier of the model that is to be used for the recognition request. See # [Languages and # models](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-models#models). @@ -327,7 +322,7 @@ def get_model(model_id:) # the service uses the default value, `1`. See [Maximum # alternatives](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#max_alternatives). # @param word_alternatives_threshold [Float] A confidence value that is the lower bound for identifying a hypothesis as a - # possible word alternative (also known as \"Confusion Networks\"). An alternative + # possible word alternative (also known as "Confusion Networks"). An alternative # word is considered if its confidence is greater than or equal to the threshold. # Specify a probability between 0.0 and 1.0. By default, the service computes no # alternative words. See [Word @@ -359,7 +354,8 @@ def get_model(model_id:) # parameter to be `true`, regardless of whether you specify `false` for the # parameter. # - # **Note:** Applies to US English, Japanese, and Spanish transcription only. To + # **Note:** Applies to US English, Japanese, and Spanish (both broadband and + # narrowband models) and UK English (narrowband model) transcription only. To # determine whether a language model supports speaker labels, you can also use the # **Get a model** method and check that the attribute `speaker_labels` is set to # `true`. @@ -393,10 +389,8 @@ def get_model(model_id:) # @param audio_metrics [Boolean] If `true`, requests detailed information about the signal characteristics of the # input audio. The service returns audio metrics with the final transcription # results. By default, the service returns no audio metrics. - # @param content_type [String] The format (MIME type) of the audio. For more information about specifying an - # audio format, see **Audio formats (content types)** in the method description. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def recognize(audio:, model: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, audio_metrics: nil, content_type: nil) + def recognize(audio:, content_type: nil, model: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, audio_metrics: nil) raise ArgumentError.new("audio must be provided") if audio.nil? headers = { @@ -432,6 +426,7 @@ def recognize(audio:, model: nil, language_customization_id: nil, acoustic_custo method_url = "/v1/recognize" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -541,12 +536,7 @@ def recognize_using_websocket( require_relative("./websocket/speech_to_text_websocket_listener.rb") headers = {} headers = conn.default_options.headers.to_hash unless conn.default_options.headers.to_hash.empty? - if !token_manager.nil? - access_token = token_manager.token - headers["Authorization"] = "Bearer #{access_token}" - elsif !username.nil? && !password.nil? - headers["Authorization"] = "Basic " + Base64.strict_encode64("#{username}:#{password}") - end + headers = authenticator.authenticate(headers) url = @url.gsub("https:", "wss:") params = { "model" => model, @@ -697,6 +687,7 @@ def register_callback(callback_url:, user_secret: nil) method_url = "/v1/register_callback" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -732,6 +723,7 @@ def unregister_callback(callback_url:) method_url = "/v1/unregister_callback" + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -743,7 +735,7 @@ def unregister_callback(callback_url:) end ## - # @!method create_job(audio:, model: nil, callback_url: nil, events: nil, user_token: nil, results_ttl: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, audio_metrics: nil, content_type: nil) + # @!method create_job(audio:, content_type: nil, model: nil, callback_url: nil, events: nil, user_token: nil, results_ttl: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, processing_metrics: nil, processing_metrics_interval: nil, audio_metrics: nil) # Create a job. # Creates a job for a new asynchronous recognition request. The job is owned by the # instance of the service whose credentials are used to create it. How you learn the @@ -811,7 +803,7 @@ def unregister_callback(callback_url:) # * For all other formats, you can omit the `Content-Type` header or specify # `application/octet-stream` with the header to have the service automatically # detect the format of the audio. (With the `curl` command, you can specify either - # `\"Content-Type:\"` or `\"Content-Type: application/octet-stream\"`.) + # `"Content-Type:"` or `"Content-Type: application/octet-stream"`.) # # Where indicated, the format that you specify must include the sampling rate and # can optionally include the number of channels and the endianness of the audio. @@ -842,6 +834,8 @@ def unregister_callback(callback_url:) # **See also:** [Audio # formats](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-audio-formats#audio-formats). # @param audio [String] The audio to transcribe. + # @param content_type [String] The format (MIME type) of the audio. For more information about specifying an + # audio format, see **Audio formats (content types)** in the method description. # @param model [String] The identifier of the model that is to be used for the recognition request. See # [Languages and # models](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-models#models). @@ -941,7 +935,7 @@ def unregister_callback(callback_url:) # the service uses the default value, `1`. See [Maximum # alternatives](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#max_alternatives). # @param word_alternatives_threshold [Float] A confidence value that is the lower bound for identifying a hypothesis as a - # possible word alternative (also known as \"Confusion Networks\"). An alternative + # possible word alternative (also known as "Confusion Networks"). An alternative # word is considered if its confidence is greater than or equal to the threshold. # Specify a probability between 0.0 and 1.0. By default, the service computes no # alternative words. See [Word @@ -973,7 +967,8 @@ def unregister_callback(callback_url:) # parameter to be `true`, regardless of whether you specify `false` for the # parameter. # - # **Note:** Applies to US English, Japanese, and Spanish transcription only. To + # **Note:** Applies to US English, Japanese, and Spanish (both broadband and + # narrowband models) and UK English (narrowband model) transcription only. To # determine whether a language model supports speaker labels, you can also use the # **Get a model** method and check that the attribute `speaker_labels` is set to # `true`. @@ -1004,7 +999,6 @@ def unregister_callback(callback_url:) # # See [Numeric # redaction](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-output#redaction). - # # @param processing_metrics [Boolean] If `true`, requests processing metrics about the service's transcription of the # input audio. The service returns processing metrics at the interval specified by # the `processing_metrics_interval` parameter. It also returns processing metrics @@ -1012,7 +1006,7 @@ def unregister_callback(callback_url:) # the service returns no processing metrics. # @param processing_metrics_interval [Float] Specifies the interval in real wall-clock seconds at which the service is to # return processing metrics. The parameter is ignored unless the - # `processing_metrics` parameter is set to `true`. # The parameter accepts a minimum value of 0.1 seconds. The level of precision is + # `processing_metrics` parameter is set to `true`. # # The parameter accepts a minimum value of 0.1 seconds. The level of precision is # not restricted, so you can specify values such as 0.25 and 0.125. @@ -1024,10 +1018,8 @@ def unregister_callback(callback_url:) # @param audio_metrics [Boolean] If `true`, requests detailed information about the signal characteristics of the # input audio. The service returns audio metrics with the final transcription # results. By default, the service returns no audio metrics. - # @param content_type [String] The format (MIME type) of the audio. For more information about specifying an - # audio format, see **Audio formats (content types)** in the method description. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def create_job(audio:, model: nil, callback_url: nil, events: nil, user_token: nil, results_ttl: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, processing_metrics: nil, processing_metrics_interval: nil, audio_metrics: nil, content_type: nil) + def create_job(audio:, content_type: nil, model: nil, callback_url: nil, events: nil, user_token: nil, results_ttl: nil, language_customization_id: nil, acoustic_customization_id: nil, base_model_version: nil, customization_weight: nil, inactivity_timeout: nil, keywords: nil, keywords_threshold: nil, max_alternatives: nil, word_alternatives_threshold: nil, word_confidence: nil, timestamps: nil, profanity_filter: nil, smart_formatting: nil, speaker_labels: nil, customization_id: nil, grammar_name: nil, redaction: nil, processing_metrics: nil, processing_metrics_interval: nil, audio_metrics: nil) raise ArgumentError.new("audio must be provided") if audio.nil? headers = { @@ -1068,6 +1060,7 @@ def create_job(audio:, model: nil, callback_url: nil, events: nil, user_token: n method_url = "/v1/recognitions" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1102,6 +1095,7 @@ def check_jobs method_url = "/v1/recognitions" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1142,6 +1136,7 @@ def check_job(id:) method_url = "/v1/recognitions/%s" % [ERB::Util.url_encode(id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1176,6 +1171,7 @@ def delete_job(id:) method_url = "/v1/recognitions/%s" % [ERB::Util.url_encode(id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1211,16 +1207,24 @@ def delete_job(id:) # to `true`. You can also refer to [Language support for # customization](https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-customization#languageSupport). # @param dialect [String] The dialect of the specified language that is to be used with the custom language - # model. The parameter is meaningful only for Spanish models, for which the service - # creates a custom language model that is suited for speech in one of the following - # dialects: - # * `es-ES` for Castilian Spanish (the default) - # * `es-LA` for Latin American Spanish - # * `es-US` for North American (Mexican) Spanish - # - # A specified dialect must be valid for the base model. By default, the dialect - # matches the language of the base model; for example, `en-US` for either of the US - # English language models. + # model. For most languages, the dialect matches the language of the base model by + # default. For example, `en-US` is used for either of the US English language + # models. + # + # For a Spanish language, the service creates a custom language model that is suited + # for speech in one of the following dialects: + # * `es-ES` for Castilian Spanish (`es-ES` models) + # * `es-LA` for Latin American Spanish (`es-AR`, `es-CL`, `es-CO`, and `es-PE` + # models) + # * `es-US` for Mexican (North American) Spanish (`es-MX` models) + # + # The parameter is meaningful only for Spanish models, for which you can always + # safely omit the parameter to have the service create the correct mapping. + # + # If you specify the `dialect` parameter for non-Spanish language models, its value + # must match the language of the base model. If you specify the `dialect` for + # Spanish language models, its value must match one of the defined mappings as + # indicated (`es-ES`, `es-LA`, or `es-MX`). All dialect values are case-insensitive. # @param description [String] A description of the new custom language model. Use a localized description that # matches the language of the custom model. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. @@ -1243,6 +1247,7 @@ def create_language_model(name:, base_model_name:, dialect: nil, description: ni method_url = "/v1/customizations" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1280,6 +1285,7 @@ def list_language_models(language: nil) method_url = "/v1/customizations" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1312,6 +1318,7 @@ def get_language_model(customization_id:) method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1345,6 +1352,7 @@ def delete_language_model(customization_id:) method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1433,6 +1441,7 @@ def train_language_model(customization_id:, word_type_to_add: nil, customization method_url = "/v1/customizations/%s/train" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -1469,6 +1478,7 @@ def reset_language_model(customization_id:) method_url = "/v1/customizations/%s/reset" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -1513,6 +1523,7 @@ def upgrade_language_model(customization_id:) method_url = "/v1/customizations/%s/upgrade_model" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -1549,6 +1560,7 @@ def list_corpora(customization_id:) method_url = "/v1/customizations/%s/corpora" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1665,6 +1677,7 @@ def add_corpus(customization_id:, corpus_name:, corpus_file:, allow_overwrite: n method_url = "/v1/customizations/%s/corpora/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(corpus_name)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -1703,6 +1716,7 @@ def get_corpus(customization_id:, corpus_name:) method_url = "/v1/customizations/%s/corpora/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(corpus_name)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1743,6 +1757,7 @@ def delete_corpus(customization_id:, corpus_name:) method_url = "/v1/customizations/%s/corpora/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(corpus_name)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -1799,6 +1814,7 @@ def list_words(customization_id:, word_type: nil, sort: nil) method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -1890,6 +1906,7 @@ def add_words(customization_id:, words:) method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -1986,6 +2003,7 @@ def add_word(customization_id:, word_name:, word: nil, sounds_like: nil, display method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word_name)] + headers = authenticator.authenticate(headers) request( method: "PUT", url: method_url, @@ -2024,6 +2042,7 @@ def get_word(customization_id:, word_name:) method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word_name)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2065,6 +2084,7 @@ def delete_word(customization_id:, word_name:) method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word_name)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2101,6 +2121,7 @@ def list_grammars(customization_id:) method_url = "/v1/customizations/%s/grammars" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2212,6 +2233,7 @@ def add_grammar(customization_id:, grammar_name:, grammar_file:, content_type:, method_url = "/v1/customizations/%s/grammars/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(grammar_name)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -2250,6 +2272,7 @@ def get_grammar(customization_id:, grammar_name:) method_url = "/v1/customizations/%s/grammars/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(grammar_name)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2289,6 +2312,7 @@ def delete_grammar(customization_id:, grammar_name:) method_url = "/v1/customizations/%s/grammars/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(grammar_name)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2344,6 +2368,7 @@ def create_acoustic_model(name:, base_model_name:, description: nil) method_url = "/v1/acoustic_customizations" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2381,6 +2406,7 @@ def list_acoustic_models(language: nil) method_url = "/v1/acoustic_customizations" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2413,6 +2439,7 @@ def get_acoustic_model(customization_id:) method_url = "/v1/acoustic_customizations/%s" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2446,6 +2473,7 @@ def delete_acoustic_model(customization_id:) method_url = "/v1/acoustic_customizations/%s" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -2537,6 +2565,7 @@ def train_acoustic_model(customization_id:, custom_language_model_id: nil) method_url = "/v1/acoustic_customizations/%s/train" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -2575,6 +2604,7 @@ def reset_acoustic_model(customization_id:) method_url = "/v1/acoustic_customizations/%s/reset" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -2643,6 +2673,7 @@ def upgrade_acoustic_model(customization_id:, custom_language_model_id: nil, for method_url = "/v1/acoustic_customizations/%s/upgrade_model" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -2682,6 +2713,7 @@ def list_audio(customization_id:) method_url = "/v1/acoustic_customizations/%s/audio" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2692,7 +2724,7 @@ def list_audio(customization_id:) end ## - # @!method add_audio(customization_id:, audio_name:, audio_resource:, contained_content_type: nil, allow_overwrite: nil, content_type: nil) + # @!method add_audio(customization_id:, audio_name:, audio_resource:, content_type: nil, contained_content_type: nil, allow_overwrite: nil) # Add an audio resource. # Adds an audio resource to a custom acoustic model. Add audio content that reflects # the acoustic characteristics of the audio that you plan to transcribe. You must @@ -2816,6 +2848,13 @@ def list_audio(customization_id:) # # With the `curl` command, use the `--data-binary` option to upload the file for the # request. + # @param content_type [String] For an audio-type resource, the format (MIME type) of the audio. For more + # information, see **Content types for audio-type resources** in the method + # description. + # + # For an archive-type resource, the media type of the archive file. For more + # information, see **Content types for archive-type resources** in the method + # description. # @param contained_content_type [String] **For an archive-type resource,** specify the format of the audio files that are # contained in the archive file if they are of type `audio/alaw`, `audio/basic`, # `audio/l16`, or `audio/mulaw`. Include the `rate`, `channels`, and `endianness` @@ -2835,15 +2874,8 @@ def list_audio(customization_id:) # the same name. If `false`, the request fails if an audio resource with the same # name already exists. The parameter has no effect if an audio resource with the # same name does not already exist. - # @param content_type [String] For an audio-type resource, the format (MIME type) of the audio. For more - # information, see **Content types for audio-type resources** in the method - # description. - # - # For an archive-type resource, the media type of the archive file. For more - # information, see **Content types for archive-type resources** in the method - # description. # @return [nil] - def add_audio(customization_id:, audio_name:, audio_resource:, contained_content_type: nil, allow_overwrite: nil, content_type: nil) + def add_audio(customization_id:, audio_name:, audio_resource:, content_type: nil, contained_content_type: nil, allow_overwrite: nil) raise ArgumentError.new("customization_id must be provided") if customization_id.nil? raise ArgumentError.new("audio_name must be provided") if audio_name.nil? @@ -2851,8 +2883,8 @@ def add_audio(customization_id:, audio_name:, audio_resource:, contained_content raise ArgumentError.new("audio_resource must be provided") if audio_resource.nil? headers = { - "Contained-Content-Type" => contained_content_type, - "Content-Type" => content_type + "Content-Type" => content_type, + "Contained-Content-Type" => contained_content_type } sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "add_audio") headers.merge!(sdk_headers) @@ -2865,6 +2897,7 @@ def add_audio(customization_id:, audio_name:, audio_resource:, contained_content method_url = "/v1/acoustic_customizations/%s/audio/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(audio_name)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -2919,6 +2952,7 @@ def get_audio(customization_id:, audio_name:) method_url = "/v1/acoustic_customizations/%s/audio/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(audio_name)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -2960,6 +2994,7 @@ def delete_audio(customization_id:, audio_name:) method_url = "/v1/acoustic_customizations/%s/audio/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(audio_name)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -3002,6 +3037,7 @@ def delete_user_data(customer_id:) method_url = "/v1/user_data" + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, diff --git a/lib/ibm_watson/text_to_speech_v1.rb b/lib/ibm_watson/text_to_speech_v1.rb index 825ac17..cf5fbd2 100644 --- a/lib/ibm_watson/text_to_speech_v1.rb +++ b/lib/ibm_watson/text_to_speech_v1.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -85,18 +85,9 @@ def initialize(args = {}) @__async_initialized__ = false defaults = {} defaults[:url] = "https://stream.watsonplatform.net/text-to-speech/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "text_to_speech" args[:display_name] = "Text to Speech" super end @@ -123,6 +114,7 @@ def list_voices method_url = "/v1/voices" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -163,6 +155,7 @@ def get_voice(voice:, customization_id: nil) method_url = "/v1/voices/%s" % [ERB::Util.url_encode(voice)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -177,7 +170,7 @@ def get_voice(voice:, customization_id: nil) ######################### ## - # @!method synthesize(text:, voice: nil, customization_id: nil, accept: nil) + # @!method synthesize(text:, accept: nil, voice: nil, customization_id: nil) # Synthesize audio. # Synthesizes text to audio that is spoken in the specified voice. The service bases # its understanding of the language for the input text on the specified voice. Use a @@ -265,22 +258,22 @@ def get_voice(voice:, customization_id: nil) # If a request includes invalid query parameters, the service returns a `Warnings` # response header that provides messages about the invalid parameters. The warning # includes a descriptive message and a list of invalid argument strings. For - # example, a message such as `\"Unknown arguments:\"` or `\"Unknown url query - # arguments:\"` followed by a list of the form `\"{invalid_arg_1}, - # {invalid_arg_2}.\"` The request succeeds despite the warnings. + # example, a message such as `"Unknown arguments:"` or `"Unknown url query + # arguments:"` followed by a list of the form `"{invalid_arg_1}, {invalid_arg_2}."` + # The request succeeds despite the warnings. # @param text [String] The text to synthesize. + # @param accept [String] The requested format (MIME type) of the audio. You can use the `Accept` header or + # the `accept` parameter to specify the audio format. For more information about + # specifying an audio format, see **Audio formats (accept types)** in the method + # description. # @param voice [String] The voice to use for synthesis. # @param customization_id [String] The customization ID (GUID) of a custom voice model to use for the synthesis. If a # custom voice model is specified, it is guaranteed to work only if it matches the # language of the indicated voice. You must make the request with credentials for # the instance of the service that owns the custom model. Omit the parameter to use # the specified voice with no customization. - # @param accept [String] The requested format (MIME type) of the audio. You can use the `Accept` header or - # the `accept` parameter to specify the audio format. For more information about - # specifying an audio format, see **Audio formats (accept types)** in the method - # description. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def synthesize(text:, voice: nil, customization_id: nil, accept: nil) + def synthesize(text:, accept: nil, voice: nil, customization_id: nil) raise ArgumentError.new("text must be provided") if text.nil? headers = { @@ -300,6 +293,7 @@ def synthesize(text:, voice: nil, customization_id: nil, accept: nil) method_url = "/v1/synthesize" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -357,6 +351,7 @@ def get_pronunciation(text:, voice: nil, format: nil, customization_id: nil) method_url = "/v1/pronunciation" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -404,6 +399,7 @@ def create_voice_model(name:, language: nil, description: nil) method_url = "/v1/customizations" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -444,6 +440,7 @@ def list_voice_models(language: nil) method_url = "/v1/customizations" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -470,13 +467,13 @@ def list_voice_models(language: nil) # a word. You can specify them in standard International Phonetic Alphabet (IPA) # representation # - # <phoneme alphabet=\"ipa\" - # ph=\"təmˈɑto\"></phoneme> + # <phoneme alphabet="ipa" + # ph="təmˈɑto"></phoneme> # # or in the proprietary IBM Symbolic Phonetic Representation (SPR) # - # <phoneme alphabet=\"ibm\" - # ph=\"1gAstroEntxrYFXs\"></phoneme> + # <phoneme alphabet="ibm" + # ph="1gAstroEntxrYFXs"></phoneme> # # **Note:** This method is currently a beta release. # @@ -511,6 +508,7 @@ def update_voice_model(customization_id:, name: nil, description: nil, words: ni method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -546,6 +544,7 @@ def get_voice_model(customization_id:) method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -578,6 +577,7 @@ def delete_voice_model(customization_id:) method_url = "/v1/customizations/%s" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -605,13 +605,13 @@ def delete_voice_model(customization_id:) # a word. You can specify them in standard International Phonetic Alphabet (IPA) # representation # - # <phoneme alphabet=\"ipa\" - # ph=\"təmˈɑto\"></phoneme> + # <phoneme alphabet="ipa" + # ph="təmˈɑto"></phoneme> # # or in the proprietary IBM Symbolic Phonetic Representation (SPR) # - # <phoneme alphabet=\"ibm\" - # ph=\"1gAstroEntxrYFXs\"></phoneme> + # <phoneme alphabet="ibm" + # ph="1gAstroEntxrYFXs"></phoneme> # # **Note:** This method is currently a beta release. # @@ -649,6 +649,7 @@ def add_words(customization_id:, words:) method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) request( method: "POST", url: method_url, @@ -684,6 +685,7 @@ def list_words(customization_id:) method_url = "/v1/customizations/%s/words" % [ERB::Util.url_encode(customization_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -708,13 +710,13 @@ def list_words(customization_id:) # a word. You can specify them in standard International Phonetic Alphabet (IPA) # representation # - # <phoneme alphabet=\"ipa\" - # ph=\"təmˈɑto\"></phoneme> + # <phoneme alphabet="ipa" + # ph="təmˈɑto"></phoneme> # # or in the proprietary IBM Symbolic Phonetic Representation (SPR) # - # <phoneme alphabet=\"ibm\" - # ph=\"1gAstroEntxrYFXs\"></phoneme> + # <phoneme alphabet="ibm" + # ph="1gAstroEntxrYFXs"></phoneme> # # **Note:** This method is currently a beta release. # @@ -758,6 +760,7 @@ def add_word(customization_id:, word:, translation:, part_of_speech: nil) method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)] + headers = authenticator.authenticate(headers) request( method: "PUT", url: method_url, @@ -795,6 +798,7 @@ def get_word(customization_id:, word:) method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -831,6 +835,7 @@ def delete_word(customization_id:, word:) method_url = "/v1/customizations/%s/words/%s" % [ERB::Util.url_encode(customization_id), ERB::Util.url_encode(word)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -873,6 +878,7 @@ def delete_user_data(customer_id:) method_url = "/v1/user_data" + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, diff --git a/lib/ibm_watson/tone_analyzer_v3.rb b/lib/ibm_watson/tone_analyzer_v3.rb index 21e2b4a..fcbaf4a 100644 --- a/lib/ibm_watson/tone_analyzer_v3.rb +++ b/lib/ibm_watson/tone_analyzer_v3.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -77,12 +77,6 @@ class ToneAnalyzerV3 < IBMCloudSdkCore::BaseService # 'https://iam.cloud.ibm.com/identity/token'. # @option args iam_client_id [String] An optional client id for the IAM service API. # @option args iam_client_secret [String] An optional client secret for the IAM service API. - # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is - # fully managed by the application. Responsibility falls on the application to - # refresh the token, either before it expires or reactively upon receiving a 401 - # from the service as any requests made with an expired token will fail. - # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this - # URL must be passed in. # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it # takes are basic, iam or icp4d. def initialize(args = {}) @@ -90,21 +84,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/tone-analyzer/api" - defaults[:username] = nil - defaults[:password] = nil - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "tone_analyzer" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Tone Analyzer" super - @version = args[:version] end ######################### @@ -112,7 +99,7 @@ def initialize(args = {}) ######################### ## - # @!method tone(tone_input:, sentences: nil, tones: nil, content_language: nil, accept_language: nil, content_type: nil) + # @!method tone(tone_input:, content_type: nil, sentences: nil, tones: nil, content_language: nil, accept_language: nil) # Analyze general tone. # Use the general-purpose endpoint to analyze the tone of your input content. The # service analyzes the content for emotional and language tones. The method always @@ -136,6 +123,8 @@ def initialize(args = {}) # endpoint](https://cloud.ibm.com/docs/services/tone-analyzer?topic=tone-analyzer-utgpe#utgpe). # @param tone_input [ToneInput] JSON, plain text, or HTML input that contains the content to be analyzed. For JSON # input, provide an object of type `ToneInput`. + # @param content_type [String] The type of the input. A character encoding can be specified by including a + # `charset` parameter. For example, 'text/plain;charset=utf-8'. # @param sentences [Boolean] Indicates whether the service is to return an analysis of each individual sentence # in addition to its analysis of the full document. If `true` (the default), the # service returns results for each sentence. @@ -157,16 +146,14 @@ def initialize(args = {}) # variants are treated as their parent language; for example, `en-US` is interpreted # as `en`. You can use different languages for **Content-Language** and # **Accept-Language**. - # @param content_type [String] The type of the input. A character encoding can be specified by including a - # `charset` parameter. For example, 'text/plain;charset=utf-8'. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. - def tone(tone_input:, sentences: nil, tones: nil, content_language: nil, accept_language: nil, content_type: nil) + def tone(tone_input:, content_type: nil, sentences: nil, tones: nil, content_language: nil, accept_language: nil) raise ArgumentError.new("tone_input must be provided") if tone_input.nil? headers = { + "Content-Type" => content_type, "Content-Language" => content_language, - "Accept-Language" => accept_language, - "Content-Type" => content_type + "Accept-Language" => accept_language } sdk_headers = Common.new.get_sdk_headers("tone_analyzer", "V3", "tone") headers.merge!(sdk_headers) @@ -185,6 +172,7 @@ def tone(tone_input:, sentences: nil, tones: nil, content_language: nil, accept_ method_url = "/v3/tone" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -247,6 +235,7 @@ def tone_chat(utterances:, content_language: nil, accept_language: nil) method_url = "/v3/tone_chat" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, diff --git a/lib/ibm_watson/visual_recognition_v3.rb b/lib/ibm_watson/visual_recognition_v3.rb index ddc284c..5916694 100644 --- a/lib/ibm_watson/visual_recognition_v3.rb +++ b/lib/ibm_watson/visual_recognition_v3.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# Copyright 2018 IBM All Rights Reserved. +# (C) Copyright IBM Corp. 2019. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -59,12 +59,6 @@ class VisualRecognitionV3 < IBMCloudSdkCore::BaseService # 'https://iam.cloud.ibm.com/identity/token'. # @option args iam_client_id [String] An optional client id for the IAM service API. # @option args iam_client_secret [String] An optional client secret for the IAM service API. - # @option args icp4d_access_token [STRING] A ICP4D(IBM Cloud Pak for Data) access token is - # fully managed by the application. Responsibility falls on the application to - # refresh the token, either before it expires or reactively upon receiving a 401 - # from the service as any requests made with an expired token will fail. - # @option args icp4d_url [STRING] In order to use an SDK-managed token with ICP4D authentication, this - # URL must be passed in. # @option args authentication_type [STRING] Specifies the authentication pattern to use. Values that it # takes are basic, iam or icp4d. def initialize(args = {}) @@ -72,19 +66,14 @@ def initialize(args = {}) defaults = {} defaults[:version] = nil defaults[:url] = "https://gateway.watsonplatform.net/visual-recognition/api" - defaults[:iam_apikey] = nil - defaults[:iam_access_token] = nil - defaults[:iam_url] = nil - defaults[:iam_client_id] = nil - defaults[:iam_client_secret] = nil - defaults[:icp4d_access_token] = nil - defaults[:icp4d_url] = nil + defaults[:authenticator] = nil defaults[:authentication_type] = nil args = defaults.merge(args) - args[:vcap_services_name] = "watson_vision_combined" + @version = args[:version] + raise ArgumentError.new("version must be provided") if @version.nil? + args[:display_name] = "Visual Recognition" super - @version = args[:version] end ######################### @@ -163,6 +152,7 @@ def classify(images_file: nil, images_filename: nil, images_file_content_type: n method_url = "/v3/classify" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -236,6 +226,7 @@ def detect_faces(images_file: nil, images_filename: nil, images_file_content_typ method_url = "/v3/detect_faces" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -254,11 +245,18 @@ def detect_faces(images_file: nil, images_filename: nil, images_file_content_typ # @!method create_classifier(name:, positive_examples:, negative_examples: nil, negative_examples_filename: nil) # Create a classifier. # Train a new multi-faceted classifier on the uploaded image data. Create your - # custom classifier with positive or negative examples. Include at least two sets of - # examples, either two positive example files or one positive and one negative file. - # You can upload a maximum of 256 MB per call. + # custom classifier with positive or negative example training images. Include at + # least two sets of examples, either two positive example files or one positive and + # one negative file. You can upload a maximum of 256 MB per call. # - # Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image + # **Tips when creating:** + # + # - If you set the **X-Watson-Learning-Opt-Out** header parameter to `true` when you + # create a classifier, the example training images are not stored. Save your + # training images locally. For more information, see [Data + # collection](#data-collection). + # + # - Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image # file names, and classifier and class names). The service assumes UTF-8 encoding if # it encounters non-ASCII characters. # @param name [String] The name of the new classifier. Encode special characters in UTF-8. @@ -318,6 +316,7 @@ def create_classifier(name:, positive_examples:, negative_examples: nil, negativ method_url = "/v3/classifiers" + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -348,6 +347,7 @@ def list_classifiers(verbose: nil) method_url = "/v3/classifiers" + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -378,6 +378,7 @@ def get_classifier(classifier_id:) method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -400,10 +401,17 @@ def get_classifier(classifier_id:) # file names, and classifier and class names). The service assumes UTF-8 encoding if # it encounters non-ASCII characters. # - # **Tip:** Don't make retraining calls on a classifier until the status is ready. - # When you submit retraining requests in parallel, the last request overwrites the - # previous requests. The retrained property shows the last time the classifier - # retraining finished. + # **Tips about retraining:** + # + # - You can't update the classifier if the **X-Watson-Learning-Opt-Out** header + # parameter was set to `true` when the classifier was created. Training images are + # not stored in that case. Instead, create another classifier. For more information, + # see [Data collection](#data-collection). + # + # - Don't make retraining calls on a classifier until the status is ready. When you + # submit retraining requests in parallel, the last request overwrites the previous + # requests. The `retrained` property shows the last time the classifier retraining + # finished. # @param classifier_id [String] The ID of the classifier. # @param positive_examples [File] A .zip file of images that depict the visual subject of a class in the classifier. # The positive examples create or update classes in the classifier. You can include @@ -459,6 +467,7 @@ def update_classifier(classifier_id:, positive_examples: nil, negative_examples: method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) response = request( method: "POST", url: method_url, @@ -489,6 +498,7 @@ def delete_classifier(classifier_id:) method_url = "/v3/classifiers/%s" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url, @@ -506,7 +516,7 @@ def delete_classifier(classifier_id:) # @!method get_core_ml_model(classifier_id:) # Retrieve a Core ML model of a classifier. # Download a Core ML model file (.mlmodel) of a custom classifier that returns - # \"core_ml_enabled\": true in the classifier details. + # "core_ml_enabled": true in the classifier details. # @param classifier_id [String] The ID of the classifier. # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response. def get_core_ml_model(classifier_id:) @@ -523,6 +533,7 @@ def get_core_ml_model(classifier_id:) method_url = "/v3/classifiers/%s/core_ml_model" % [ERB::Util.url_encode(classifier_id)] + headers = authenticator.authenticate(headers) response = request( method: "GET", url: method_url, @@ -563,6 +574,7 @@ def delete_user_data(customer_id:) method_url = "/v3/user_data" + headers = authenticator.authenticate(headers) request( method: "DELETE", url: method_url,