11# frozen_string_literal: true
22
3- # Copyright 2018 IBM All Rights Reserved .
3+ # (C) Copyright IBM Corp. 2019 .
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
@@ -81,40 +81,32 @@ def initialize(args = {})
8181 defaults = { }
8282 defaults [ :version ] = nil
8383 defaults [ :url ] = "https://gateway.watsonplatform.net/compare-comply/api"
84- defaults [ :username ] = nil
85- defaults [ :password ] = nil
86- defaults [ :iam_apikey ] = nil
87- defaults [ :iam_access_token ] = nil
88- defaults [ :iam_url ] = nil
89- defaults [ :iam_client_id ] = nil
90- defaults [ :iam_client_secret ] = nil
91- defaults [ :icp4d_access_token ] = nil
92- defaults [ :icp4d_url ] = nil
84+ defaults [ :authenticator ] = nil
9385 defaults [ :authentication_type ] = nil
9486 args = defaults . merge ( args )
95- args [ :vcap_services_name ] = "compare-comply"
87+ @version = args [ :version ]
88+ raise ArgumentError . new ( "version must be provided" ) if @version . nil?
89+
9690 args [ :display_name ] = "Compare Comply"
9791 super
98- @version = args [ :version ]
9992 end
10093
10194 #########################
10295 # HTML conversion
10396 #########################
10497
10598 ##
106- # @!method convert_to_html(file:, filename: nil, file_content_type: nil, model: nil)
99+ # @!method convert_to_html(file:, file_content_type: nil, model: nil)
107100 # Convert document to HTML.
108101 # Converts a document to HTML.
109102 # @param file [File] The document to convert.
110- # @param filename [String] The filename for file.
111103 # @param file_content_type [String] The content type of file.
112104 # @param model [String] The analysis model to be used by the service. For the **Element classification**
113105 # and **Compare two documents** methods, the default is `contracts`. For the
114106 # **Extract tables** method, the default is `tables`. These defaults apply to the
115107 # standalone methods as well as to the methods' use in batch-processing requests.
116108 # @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
117- def convert_to_html ( file :, filename : nil , file_content_type : nil , model : nil )
109+ def convert_to_html ( file :, file_content_type : nil , model : nil )
118110 raise ArgumentError . new ( "file must be provided" ) if file . nil?
119111
120112 headers = {
@@ -132,11 +124,11 @@ def convert_to_html(file:, filename: nil, file_content_type: nil, model: nil)
132124 unless file . instance_of? ( StringIO ) || file . instance_of? ( File )
133125 file = file . respond_to? ( :to_json ) ? StringIO . new ( file . to_json ) : StringIO . new ( file )
134126 end
135- filename = file . path if filename . nil? && file . respond_to? ( :path )
136- form_data [ :file ] = HTTP ::FormData ::File . new ( file , content_type : file_content_type . nil? ? "application/octet-stream" : file_content_type , filename : filename )
127+ 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 )
137128
138129 method_url = "/v1/html_conversion"
139130
131+ headers = authenticator . authenticate ( headers )
140132 response = request (
141133 method : "POST" ,
142134 url : method_url ,
@@ -184,6 +176,7 @@ def classify_elements(file:, file_content_type: nil, model: nil)
184176
185177 method_url = "/v1/element_classification"
186178
179+ headers = authenticator . authenticate ( headers )
187180 response = request (
188181 method : "POST" ,
189182 url : method_url ,
@@ -231,6 +224,7 @@ def extract_tables(file:, file_content_type: nil, model: nil)
231224
232225 method_url = "/v1/tables"
233226
227+ headers = authenticator . authenticate ( headers )
234228 response = request (
235229 method : "POST" ,
236230 url : method_url ,
@@ -291,6 +285,7 @@ def compare_documents(file_1:, file_2:, file_1_content_type: nil, file_2_content
291285
292286 method_url = "/v1/comparison"
293287
288+ headers = authenticator . authenticate ( headers )
294289 response = request (
295290 method : "POST" ,
296291 url : method_url ,
@@ -337,6 +332,7 @@ def add_feedback(feedback_data:, user_id: nil, comment: nil)
337332
338333 method_url = "/v1/feedback"
339334
335+ headers = authenticator . authenticate ( headers )
340336 response = request (
341337 method : "POST" ,
342338 url : method_url ,
@@ -364,7 +360,7 @@ def add_feedback(feedback_data:, user_id: nil, comment: nil)
364360 # specified `model_id`. The only permitted value is `contracts`.
365361 # @param model_version [String] An optional string that filters the output to include only feedback with the
366362 # specified `model_version`.
367- # @param category_removed [String] An optional string in the form of a comma-separated list of categories. If this is
363+ # @param category_removed [String] An optional string in the form of a comma-separated list of categories. If it is
368364 # specified, the service filters the output to include only feedback that has at
369365 # least one category from the list removed.
370366 # @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
422418
423419 method_url = "/v1/feedback"
424420
421+ headers = authenticator . authenticate ( headers )
425422 response = request (
426423 method : "GET" ,
427424 url : method_url ,
@@ -457,6 +454,7 @@ def get_feedback(feedback_id:, model: nil)
457454
458455 method_url = "/v1/feedback/%s" % [ ERB ::Util . url_encode ( feedback_id ) ]
459456
457+ headers = authenticator . authenticate ( headers )
460458 response = request (
461459 method : "GET" ,
462460 url : method_url ,
@@ -492,6 +490,7 @@ def delete_feedback(feedback_id:, model: nil)
492490
493491 method_url = "/v1/feedback/%s" % [ ERB ::Util . url_encode ( feedback_id ) ]
494492
493+ headers = authenticator . authenticate ( headers )
495494 response = request (
496495 method : "DELETE" ,
497496 url : method_url ,
@@ -583,6 +582,7 @@ def create_batch(function:, input_credentials_file:, input_bucket_location:, inp
583582
584583 method_url = "/v1/batches"
585584
585+ headers = authenticator . authenticate ( headers )
586586 response = request (
587587 method : "POST" ,
588588 url : method_url ,
@@ -611,6 +611,7 @@ def list_batches
611611
612612 method_url = "/v1/batches"
613613
614+ headers = authenticator . authenticate ( headers )
614615 response = request (
615616 method : "GET" ,
616617 url : method_url ,
@@ -641,6 +642,7 @@ def get_batch(batch_id:)
641642
642643 method_url = "/v1/batches/%s" % [ ERB ::Util . url_encode ( batch_id ) ]
643644
645+ headers = authenticator . authenticate ( headers )
644646 response = request (
645647 method : "GET" ,
646648 url : method_url ,
@@ -681,6 +683,7 @@ def update_batch(batch_id:, action:, model: nil)
681683
682684 method_url = "/v1/batches/%s" % [ ERB ::Util . url_encode ( batch_id ) ]
683685
686+ headers = authenticator . authenticate ( headers )
684687 response = request (
685688 method : "PUT" ,
686689 url : method_url ,
0 commit comments