Skip to content

Commit

Permalink
feat(core): separate core functionalty out of watson sdk
Browse files Browse the repository at this point in the history
port core functionality from ibm_cloud_sdk_core
  • Loading branch information
mamoonraja committed Mar 18, 2019
1 parent f317fdb commit 272ce04
Show file tree
Hide file tree
Showing 26 changed files with 434 additions and 1,121 deletions.
1 change: 1 addition & 0 deletions ibm_watson.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "eventmachine", "~> 1.2"
spec.add_runtime_dependency "faye-websocket", "~> 0.10"
spec.add_runtime_dependency "http", "~> 4.1.0"
spec.add_runtime_dependency "ibm_cloud_sdk_core", "~> 0.1.1"

spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "codecov", "~> 0.1"
Expand Down
169 changes: 84 additions & 85 deletions lib/ibm_watson/assistant_v1.rb

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions lib/ibm_watson/assistant_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
require "concurrent"
require "erb"
require "json"
require_relative "./detailed_response"
require_relative "./common.rb"

require_relative "./watson_service"
require "ibm_cloud_sdk_core"
require_relative "./common.rb"

# Module for the Watson APIs
module IBMWatson
##
# The Assistant V2 service.
class AssistantV2 < WatsonService
class AssistantV2 < IBMCloudSdkCore::BaseService
include Concurrent::Async
##
# @!method initialize(args)
Expand Down Expand Up @@ -101,13 +100,13 @@ def initialize(args = {})
# [documentation](https://console.bluemix.net/docs/services/assistant/create-assistant.html#creating-assistants).
#
# **Note:** Currently, the v2 API does not support creating assistants.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def create_session(assistant_id:)
raise ArgumentError.new("assistant_id must be provided") if assistant_id.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "conversation", service_version: "V2", operation_id: "create_session")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "conversation", service_version: "V2", operation_id: "create_session")

params = {
"version" => @version
Expand Down Expand Up @@ -144,7 +143,7 @@ def delete_session(assistant_id:, session_id:)

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "conversation", service_version: "V2", operation_id: "delete_session")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "conversation", service_version: "V2", operation_id: "delete_session")

params = {
"version" => @version
Expand Down Expand Up @@ -180,15 +179,15 @@ def delete_session(assistant_id:, session_id:)
# @param session_id [String] Unique identifier of the session.
# @param input [MessageInput] An input object that includes the input text.
# @param context [MessageContext] State information for the conversation.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def message(assistant_id:, session_id:, input: nil, context: nil)
raise ArgumentError.new("assistant_id must be provided") if assistant_id.nil?

raise ArgumentError.new("session_id must be provided") if session_id.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "conversation", service_version: "V2", operation_id: "message")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "conversation", service_version: "V2", operation_id: "message")

params = {
"version" => @version
Expand Down
2 changes: 1 addition & 1 deletion lib/ibm_watson/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module IBMWatson
class Common
def initialize(*); end

def get_default_headers(headers: {}, service_name: nil, service_version: nil, operation_id: nil)
def get_sdk_headers(headers: {}, service_name: nil, service_version: nil, operation_id: nil)
user_agent_string = "watson-apis-ruby-sdk-" + IBMWatson::VERSION + " #{RbConfig::CONFIG["host"]}"
user_agent_string += " #{RbConfig::CONFIG["RUBY_BASE_NAME"]}-#{RbConfig::CONFIG["RUBY_PROGRAM_VERSION"]}"

Expand Down
55 changes: 27 additions & 28 deletions lib/ibm_watson/compare_comply_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
require "concurrent"
require "erb"
require "json"
require_relative "./detailed_response"
require_relative "./common.rb"

require_relative "./watson_service"
require "ibm_cloud_sdk_core"
require_relative "./common.rb"

# Module for the Watson APIs
module IBMWatson
##
# The Compare Comply V1 service.
class CompareComplyV1 < WatsonService
class CompareComplyV1 < IBMCloudSdkCore::BaseService
include Concurrent::Async
##
# @!method initialize(args)
Expand Down Expand Up @@ -88,13 +87,13 @@ def initialize(args = {})
# well as to the methods' use in batch-processing requests.
# @param file_content_type [String] The content type of file.
# @param filename [String] The filename for file.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def convert_to_html(file:, model_id: nil, file_content_type: nil, filename: nil)
raise ArgumentError.new("file must be provided") if file.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "convert_to_html")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "convert_to_html")

params = {
"version" => @version,
Expand Down Expand Up @@ -136,13 +135,13 @@ def convert_to_html(file:, model_id: nil, file_content_type: nil, filename: nil)
# well as to the methods' use in batch-processing requests.
# @param file_content_type [String] The content type of file.
# @param filename [String] The filename for file.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def classify_elements(file:, model_id: nil, file_content_type: nil, filename: nil)
raise ArgumentError.new("file must be provided") if file.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "classify_elements")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "classify_elements")

params = {
"version" => @version,
Expand Down Expand Up @@ -184,13 +183,13 @@ def classify_elements(file:, model_id: nil, file_content_type: nil, filename: ni
# well as to the methods' use in batch-processing requests.
# @param file_content_type [String] The content type of file.
# @param filename [String] The filename for file.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def extract_tables(file:, model_id: nil, file_content_type: nil, filename: nil)
raise ArgumentError.new("file must be provided") if file.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "extract_tables")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "extract_tables")

params = {
"version" => @version,
Expand Down Expand Up @@ -237,15 +236,15 @@ def extract_tables(file:, model_id: nil, file_content_type: nil, filename: nil)
# @param file_1_filename [String] The filename for file_1.
# @param file_2_content_type [String] The content type of file_2.
# @param file_2_filename [String] The filename for file_2.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def compare_documents(file_1:, file_2:, file_1_label: nil, file_2_label: nil, model_id: nil, file_1_content_type: nil, file_1_filename: nil, file_2_content_type: nil, file_2_filename: nil)
raise ArgumentError.new("file_1 must be provided") if file_1.nil?

raise ArgumentError.new("file_2 must be provided") if file_2.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "compare_documents")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "compare_documents")

params = {
"version" => @version,
Expand Down Expand Up @@ -295,13 +294,13 @@ def compare_documents(file_1:, file_2:, file_1_label: nil, file_2_label: nil, mo
# @param feedback_data [FeedbackDataInput] Feedback data for submission.
# @param user_id [String] An optional string identifying the user.
# @param comment [String] An optional comment on or description of the feedback.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def add_feedback(feedback_data:, user_id: nil, comment: nil)
raise ArgumentError.new("feedback_data must be provided") if feedback_data.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "add_feedback")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "add_feedback")

params = {
"version" => @version
Expand Down Expand Up @@ -370,11 +369,11 @@ def add_feedback(feedback_data:, user_id: nil, comment: nil)
# @param include_total [Boolean] An optional boolean value. If specified as `true`, the `pagination` object in the
# output includes a value called `total` that gives the total count of feedback
# created.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def list_feedback(feedback_type: nil, before: nil, after: nil, document_title: nil, model_id: nil, model_version: nil, category_removed: nil, category_added: nil, category_not_changed: nil, type_removed: nil, type_added: nil, type_not_changed: nil, page_limit: nil, cursor: nil, sort: nil, include_total: nil)
headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "list_feedback")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "list_feedback")

params = {
"version" => @version,
Expand Down Expand Up @@ -416,13 +415,13 @@ def list_feedback(feedback_type: nil, before: nil, after: nil, document_title: n
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/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 [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def get_feedback(feedback_id:, model_id: nil)
raise ArgumentError.new("feedback_id must be provided") if feedback_id.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "get_feedback")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "get_feedback")

params = {
"version" => @version,
Expand All @@ -449,13 +448,13 @@ def get_feedback(feedback_id:, model_id: nil)
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/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 [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def delete_feedback(feedback_id:, model_id: nil)
raise ArgumentError.new("feedback_id must be provided") if feedback_id.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "delete_feedback")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "delete_feedback")

params = {
"version" => @version,
Expand Down Expand Up @@ -507,7 +506,7 @@ def delete_feedback(feedback_id:, model_id: nil)
# well as to the methods' use in batch-processing requests.
# @param input_credentials_filename [String] The filename for input_credentials_file.
# @param output_credentials_filename [String] The filename for output_credentials_file.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def create_batch(function:, input_credentials_file:, input_bucket_location:, input_bucket_name:, output_credentials_file:, output_bucket_location:, output_bucket_name:, model_id: nil, input_credentials_filename: nil, output_credentials_filename: nil)
raise ArgumentError.new("function must be provided") if function.nil?

Expand All @@ -525,7 +524,7 @@ def create_batch(function:, input_credentials_file:, input_bucket_location:, inp

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "create_batch")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "create_batch")

params = {
"version" => @version,
Expand Down Expand Up @@ -572,11 +571,11 @@ def create_batch(function:, input_credentials_file:, input_bucket_location:, inp
# @!method list_batches
# List submitted batch-processing jobs.
# List the batch-processing jobs submitted by users.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def list_batches
headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "list_batches")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "list_batches")

params = {
"version" => @version
Expand All @@ -599,13 +598,13 @@ def list_batches
# Get information about a specific batch-processing request.
# Get information about a batch-processing request with a specified ID.
# @param batch_id [String] The ID of the batch-processing request whose information you want to retrieve.
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def get_batch(batch_id:)
raise ArgumentError.new("batch_id must be provided") if batch_id.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "get_batch")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "get_batch")

params = {
"version" => @version
Expand Down Expand Up @@ -634,15 +633,15 @@ def get_batch(batch_id:)
# and `/v1/comparison` methods, the default is `contracts`. For the `/v1/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 [DetailedResponse] A `DetailedResponse` object representing the response.
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
def update_batch(batch_id:, action:, model_id: nil)
raise ArgumentError.new("batch_id must be provided") if batch_id.nil?

raise ArgumentError.new("action must be provided") if action.nil?

headers = {
}
headers = Common.new.get_default_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "update_batch")
headers = Common.new.get_sdk_headers(headers: headers, service_name: "compare-comply", service_version: "V1", operation_id: "update_batch")

params = {
"version" => @version,
Expand Down
21 changes: 0 additions & 21 deletions lib/ibm_watson/detailed_response.rb

This file was deleted.

Loading

0 comments on commit 272ce04

Please sign in to comment.