azure_cognitiveservices_formrecognizer 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer.rb +43 -0
  4. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb +734 -0
  5. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/analyze_result.rb +91 -0
  6. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/error_information.rb +70 -0
  7. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/error_response.rb +48 -0
  8. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_key_value_pair.rb +78 -0
  9. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_page.rb +122 -0
  10. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_table.rb +68 -0
  11. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_table_column.rb +87 -0
  12. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_token.rb +81 -0
  13. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/form_document_report.rb +89 -0
  14. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/form_operation_error.rb +46 -0
  15. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/inner_error.rb +47 -0
  16. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/keys_result.rb +64 -0
  17. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/model_result.rb +80 -0
  18. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/models_result.rb +55 -0
  19. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/train_request.rb +50 -0
  20. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/train_result.rb +89 -0
  21. data/lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/module_definition.rb +9 -0
  22. data/lib/azure_cognitiveservices_formrecognizer.rb +6 -0
  23. data/lib/module_definition.rb +7 -0
  24. data/lib/profiles/latest/formrecognizer_latest_profile_client.rb +38 -0
  25. data/lib/profiles/latest/formrecognizer_module_definition.rb +8 -0
  26. data/lib/profiles/latest/modules/formrecognizer_profile_module.rb +121 -0
  27. data/lib/version.rb +7 -0
  28. metadata +143 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ee9afb848a7f20f089acea06014a67d1002954a
4
+ data.tar.gz: eaa2d32975f6b9d4b57b8008f7e1778f47c4cba1
5
+ SHA512:
6
+ metadata.gz: cd908a50c69bb33b65e0ee5453e0f110e93e4c28607d58e09c75d762fb656bfc16781c650b3612769db62ad565b21a602d120b2f8e3472ae8b310e9e9dbe6ac3
7
+ data.tar.gz: 288ad9b4cbbd515b0bfe91e2925c78b3d6418b52fb40b3719ff60e0f1f20be3e83fa317aefe3d250e9382e6ec6ebc6f25905e2451767a77b076832914ac7cfb6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Microsoft Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator.
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ require 'uri'
7
+ require 'cgi'
8
+ require 'date'
9
+ require 'json'
10
+ require 'base64'
11
+ require 'erb'
12
+ require 'securerandom'
13
+ require 'time'
14
+ require 'timeliness'
15
+ require 'faraday'
16
+ require 'faraday-cookie_jar'
17
+ require 'concurrent'
18
+ require 'ms_rest'
19
+ require '1.0-preview/generated/azure_cognitiveservices_formrecognizer/module_definition'
20
+ require 'ms_rest_azure'
21
+
22
+ module Azure::CognitiveServices::FormRecognizer::V1_0_preview
23
+ autoload :FormRecognizerClient, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb'
24
+
25
+ module Models
26
+ autoload :ErrorInformation, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/error_information.rb'
27
+ autoload :TrainRequest, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/train_request.rb'
28
+ autoload :ErrorResponse, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/error_response.rb'
29
+ autoload :FormOperationError, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/form_operation_error.rb'
30
+ autoload :ExtractedToken, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_token.rb'
31
+ autoload :KeysResult, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/keys_result.rb'
32
+ autoload :ExtractedKeyValuePair, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_key_value_pair.rb'
33
+ autoload :ModelsResult, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/models_result.rb'
34
+ autoload :ExtractedTableColumn, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_table_column.rb'
35
+ autoload :FormDocumentReport, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/form_document_report.rb'
36
+ autoload :ExtractedTable, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_table.rb'
37
+ autoload :ModelResult, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/model_result.rb'
38
+ autoload :ExtractedPage, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/extracted_page.rb'
39
+ autoload :TrainResult, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/train_result.rb'
40
+ autoload :AnalyzeResult, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/analyze_result.rb'
41
+ autoload :InnerError, '1.0-preview/generated/azure_cognitiveservices_formrecognizer/models/inner_error.rb'
42
+ end
43
+ end
@@ -0,0 +1,734 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator.
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::CognitiveServices::FormRecognizer::V1_0_preview
7
+ #
8
+ # A service client - single point of access to the REST API.
9
+ #
10
+ class FormRecognizerClient < MsRestAzure::AzureServiceClient
11
+ include MsRestAzure
12
+ include MsRestAzure::Serialization
13
+
14
+ # @return [String] the base URI of the service.
15
+ attr_reader :base_url
16
+
17
+ # @return Credentials needed for the client to connect to Azure.
18
+ attr_reader :credentials1
19
+
20
+ # @return [String] Supported Cognitive Services endpoints (protocol and
21
+ # hostname, for example: https://westus2.api.cognitive.microsoft.com).
22
+ attr_accessor :endpoint
23
+
24
+ # @return Subscription credentials which uniquely identify client
25
+ # subscription.
26
+ attr_accessor :credentials
27
+
28
+ # @return [String] The preferred language for the response.
29
+ attr_accessor :accept_language
30
+
31
+ # @return [Integer] The retry timeout in seconds for Long Running
32
+ # Operations. Default value is 30.
33
+ attr_accessor :long_running_operation_retry_timeout
34
+
35
+ # @return [Boolean] Whether a unique x-ms-client-request-id should be
36
+ # generated. When set to true a unique x-ms-client-request-id value is
37
+ # generated and included in each request. Default is true.
38
+ attr_accessor :generate_client_request_id
39
+
40
+ #
41
+ # Creates initializes a new instance of the FormRecognizerClient class.
42
+ # @param credentials [MsRest::ServiceClientCredentials] credentials to authorize HTTP requests made by the service client.
43
+ # @param options [Array] filters to be applied to the HTTP requests.
44
+ #
45
+ def initialize(credentials = nil, options = nil)
46
+ super(credentials, options)
47
+ @base_url = '{Endpoint}/formrecognizer/v1.0-preview'
48
+
49
+ fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials) unless credentials.nil?
50
+ @credentials = credentials
51
+
52
+ @accept_language = 'en-US'
53
+ @long_running_operation_retry_timeout = 30
54
+ @generate_client_request_id = true
55
+ add_telemetry
56
+ end
57
+
58
+ #
59
+ # Makes a request and returns the body of the response.
60
+ # @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
61
+ # @param path [String] the path, relative to {base_url}.
62
+ # @param options [Hash{String=>String}] specifying any request options like :body.
63
+ # @return [Hash{String=>String}] containing the body of the response.
64
+ # Example:
65
+ #
66
+ # request_content = "{'location':'westus','tags':{'tag1':'val1','tag2':'val2'}}"
67
+ # path = "/path"
68
+ # options = {
69
+ # body: request_content,
70
+ # query_params: {'api-version' => '2016-02-01'}
71
+ # }
72
+ # result = @client.make_request(:put, path, options)
73
+ #
74
+ def make_request(method, path, options = {})
75
+ result = make_request_with_http_info(method, path, options)
76
+ result.body unless result.nil?
77
+ end
78
+
79
+ #
80
+ # Makes a request and returns the operation response.
81
+ # @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
82
+ # @param path [String] the path, relative to {base_url}.
83
+ # @param options [Hash{String=>String}] specifying any request options like :body.
84
+ # @return [MsRestAzure::AzureOperationResponse] Operation response containing the request, response and status.
85
+ #
86
+ def make_request_with_http_info(method, path, options = {})
87
+ result = make_request_async(method, path, options).value!
88
+ result.body = result.response.body.to_s.empty? ? nil : JSON.load(result.response.body)
89
+ result
90
+ end
91
+
92
+ #
93
+ # Makes a request asynchronously.
94
+ # @param method [Symbol] with any of the following values :get, :put, :post, :patch, :delete.
95
+ # @param path [String] the path, relative to {base_url}.
96
+ # @param options [Hash{String=>String}] specifying any request options like :body.
97
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
98
+ #
99
+ def make_request_async(method, path, options = {})
100
+ fail ArgumentError, 'method is nil' if method.nil?
101
+ fail ArgumentError, 'path is nil' if path.nil?
102
+
103
+ request_url = options[:base_url] || @base_url
104
+ if(!options[:headers].nil? && !options[:headers]['Content-Type'].nil?)
105
+ @request_headers['Content-Type'] = options[:headers]['Content-Type']
106
+ end
107
+
108
+ request_headers = @request_headers
109
+ request_headers.merge!({'accept-language' => @accept_language}) unless @accept_language.nil?
110
+ options.merge!({headers: request_headers.merge(options[:headers] || {})})
111
+ options.merge!({credentials: @credentials}) unless @credentials.nil?
112
+
113
+ super(request_url, method, path, options)
114
+ end
115
+
116
+ #
117
+ # Train Model
118
+ #
119
+ # The train request must include a source parameter that is either an
120
+ # externally accessible Azure Storage blob container Uri (preferably a Shared
121
+ # Access Signature Uri) or valid path to a data folder in a locally mounted
122
+ # drive. When local paths are specified, they must follow the Linux/Unix path
123
+ # format and be an absolute path rooted to the input mount configuration
124
+ # setting value e.g., if '{Mounts:Input}' configuration setting value is
125
+ # '/input' then a valid source path would be '/input/contosodataset'. All data
126
+ # to be trained are expected to be under the source. Models are trained using
127
+ # documents that are of the following content type - 'application/pdf',
128
+ # 'image/jpeg' and 'image/png'."
129
+ # Other content is ignored when training a model.
130
+ #
131
+ # @param train_request [TrainRequest] Request object for training.
132
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
133
+ # will be added to the HTTP request.
134
+ #
135
+ # @return [TrainResult] operation results.
136
+ #
137
+ def train_custom_model(train_request, custom_headers:nil)
138
+ response = train_custom_model_async(train_request, custom_headers:custom_headers).value!
139
+ response.body unless response.nil?
140
+ end
141
+
142
+ #
143
+ # Train Model
144
+ #
145
+ # The train request must include a source parameter that is either an
146
+ # externally accessible Azure Storage blob container Uri (preferably a Shared
147
+ # Access Signature Uri) or valid path to a data folder in a locally mounted
148
+ # drive. When local paths are specified, they must follow the Linux/Unix path
149
+ # format and be an absolute path rooted to the input mount configuration
150
+ # setting value e.g., if '{Mounts:Input}' configuration setting value is
151
+ # '/input' then a valid source path would be '/input/contosodataset'. All data
152
+ # to be trained are expected to be under the source. Models are trained using
153
+ # documents that are of the following content type - 'application/pdf',
154
+ # 'image/jpeg' and 'image/png'."
155
+ # Other content is ignored when training a model.
156
+ #
157
+ # @param train_request [TrainRequest] Request object for training.
158
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
159
+ # will be added to the HTTP request.
160
+ #
161
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
162
+ #
163
+ def train_custom_model_with_http_info(train_request, custom_headers:nil)
164
+ train_custom_model_async(train_request, custom_headers:custom_headers).value!
165
+ end
166
+
167
+ #
168
+ # Train Model
169
+ #
170
+ # The train request must include a source parameter that is either an
171
+ # externally accessible Azure Storage blob container Uri (preferably a Shared
172
+ # Access Signature Uri) or valid path to a data folder in a locally mounted
173
+ # drive. When local paths are specified, they must follow the Linux/Unix path
174
+ # format and be an absolute path rooted to the input mount configuration
175
+ # setting value e.g., if '{Mounts:Input}' configuration setting value is
176
+ # '/input' then a valid source path would be '/input/contosodataset'. All data
177
+ # to be trained are expected to be under the source. Models are trained using
178
+ # documents that are of the following content type - 'application/pdf',
179
+ # 'image/jpeg' and 'image/png'."
180
+ # Other content is ignored when training a model.
181
+ #
182
+ # @param train_request [TrainRequest] Request object for training.
183
+ # @param [Hash{String => String}] A hash of custom headers that will be added
184
+ # to the HTTP request.
185
+ #
186
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
187
+ #
188
+ def train_custom_model_async(train_request, custom_headers:nil)
189
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
190
+ fail ArgumentError, 'train_request is nil' if train_request.nil?
191
+
192
+
193
+ request_headers = {}
194
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
195
+
196
+ # Set Headers
197
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
198
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
199
+
200
+ # Serialize Request
201
+ request_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::TrainRequest.mapper()
202
+ request_content = self.serialize(request_mapper, train_request)
203
+ request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
204
+
205
+ path_template = 'custom/train'
206
+
207
+ request_url = @base_url || self.base_url
208
+ request_url = request_url.gsub('{Endpoint}', endpoint)
209
+
210
+ options = {
211
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
212
+ body: request_content,
213
+ headers: request_headers.merge(custom_headers || {}),
214
+ base_url: request_url
215
+ }
216
+ promise = self.make_request_async(:post, path_template, options)
217
+
218
+ promise = promise.then do |result|
219
+ http_response = result.response
220
+ status_code = http_response.status
221
+ response_content = http_response.body
222
+ unless status_code == 200
223
+ error_model = JSON.load(response_content)
224
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
225
+ end
226
+
227
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
228
+ # Deserialize Response
229
+ if status_code == 200
230
+ begin
231
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
232
+ result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::TrainResult.mapper()
233
+ result.body = self.deserialize(result_mapper, parsed_response)
234
+ rescue Exception => e
235
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
236
+ end
237
+ end
238
+
239
+ result
240
+ end
241
+
242
+ promise.execute
243
+ end
244
+
245
+ #
246
+ # Get Keys
247
+ #
248
+ # Use the API to retrieve the keys that were
249
+ # extracted by the specified model.
250
+ #
251
+ # @param id Model identifier.
252
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
253
+ # will be added to the HTTP request.
254
+ #
255
+ # @return [KeysResult] operation results.
256
+ #
257
+ def get_extracted_keys(id, custom_headers:nil)
258
+ response = get_extracted_keys_async(id, custom_headers:custom_headers).value!
259
+ response.body unless response.nil?
260
+ end
261
+
262
+ #
263
+ # Get Keys
264
+ #
265
+ # Use the API to retrieve the keys that were
266
+ # extracted by the specified model.
267
+ #
268
+ # @param id Model identifier.
269
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
270
+ # will be added to the HTTP request.
271
+ #
272
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
273
+ #
274
+ def get_extracted_keys_with_http_info(id, custom_headers:nil)
275
+ get_extracted_keys_async(id, custom_headers:custom_headers).value!
276
+ end
277
+
278
+ #
279
+ # Get Keys
280
+ #
281
+ # Use the API to retrieve the keys that were
282
+ # extracted by the specified model.
283
+ #
284
+ # @param id Model identifier.
285
+ # @param [Hash{String => String}] A hash of custom headers that will be added
286
+ # to the HTTP request.
287
+ #
288
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
289
+ #
290
+ def get_extracted_keys_async(id, custom_headers:nil)
291
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
292
+ fail ArgumentError, 'id is nil' if id.nil?
293
+
294
+
295
+ request_headers = {}
296
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
297
+
298
+ # Set Headers
299
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
300
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
301
+ path_template = 'custom/models/{id}/keys'
302
+
303
+ request_url = @base_url || self.base_url
304
+ request_url = request_url.gsub('{Endpoint}', endpoint)
305
+
306
+ options = {
307
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
308
+ path_params: {'id' => id},
309
+ headers: request_headers.merge(custom_headers || {}),
310
+ base_url: request_url
311
+ }
312
+ promise = self.make_request_async(:get, path_template, options)
313
+
314
+ promise = promise.then do |result|
315
+ http_response = result.response
316
+ status_code = http_response.status
317
+ response_content = http_response.body
318
+ unless status_code == 200
319
+ error_model = JSON.load(response_content)
320
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
321
+ end
322
+
323
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
324
+ # Deserialize Response
325
+ if status_code == 200
326
+ begin
327
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
328
+ result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::KeysResult.mapper()
329
+ result.body = self.deserialize(result_mapper, parsed_response)
330
+ rescue Exception => e
331
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
332
+ end
333
+ end
334
+
335
+ result
336
+ end
337
+
338
+ promise.execute
339
+ end
340
+
341
+ #
342
+ # Get Models
343
+ #
344
+ # Get information about all trained models
345
+ #
346
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
347
+ # will be added to the HTTP request.
348
+ #
349
+ # @return [ModelsResult] operation results.
350
+ #
351
+ def get_custom_models(custom_headers:nil)
352
+ response = get_custom_models_async(custom_headers:custom_headers).value!
353
+ response.body unless response.nil?
354
+ end
355
+
356
+ #
357
+ # Get Models
358
+ #
359
+ # Get information about all trained models
360
+ #
361
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
362
+ # will be added to the HTTP request.
363
+ #
364
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
365
+ #
366
+ def get_custom_models_with_http_info(custom_headers:nil)
367
+ get_custom_models_async(custom_headers:custom_headers).value!
368
+ end
369
+
370
+ #
371
+ # Get Models
372
+ #
373
+ # Get information about all trained models
374
+ #
375
+ # @param [Hash{String => String}] A hash of custom headers that will be added
376
+ # to the HTTP request.
377
+ #
378
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
379
+ #
380
+ def get_custom_models_async(custom_headers:nil)
381
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
382
+
383
+
384
+ request_headers = {}
385
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
386
+
387
+ # Set Headers
388
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
389
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
390
+ path_template = 'custom/models'
391
+
392
+ request_url = @base_url || self.base_url
393
+ request_url = request_url.gsub('{Endpoint}', endpoint)
394
+
395
+ options = {
396
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
397
+ headers: request_headers.merge(custom_headers || {}),
398
+ base_url: request_url
399
+ }
400
+ promise = self.make_request_async(:get, path_template, options)
401
+
402
+ promise = promise.then do |result|
403
+ http_response = result.response
404
+ status_code = http_response.status
405
+ response_content = http_response.body
406
+ unless status_code == 200
407
+ error_model = JSON.load(response_content)
408
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
409
+ end
410
+
411
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
412
+ # Deserialize Response
413
+ if status_code == 200
414
+ begin
415
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
416
+ result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::ModelsResult.mapper()
417
+ result.body = self.deserialize(result_mapper, parsed_response)
418
+ rescue Exception => e
419
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
420
+ end
421
+ end
422
+
423
+ result
424
+ end
425
+
426
+ promise.execute
427
+ end
428
+
429
+ #
430
+ # Get Model
431
+ #
432
+ # Get information about a model.
433
+ #
434
+ # @param id Model identifier.
435
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
436
+ # will be added to the HTTP request.
437
+ #
438
+ # @return [ModelResult] operation results.
439
+ #
440
+ def get_custom_model(id, custom_headers:nil)
441
+ response = get_custom_model_async(id, custom_headers:custom_headers).value!
442
+ response.body unless response.nil?
443
+ end
444
+
445
+ #
446
+ # Get Model
447
+ #
448
+ # Get information about a model.
449
+ #
450
+ # @param id Model identifier.
451
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
452
+ # will be added to the HTTP request.
453
+ #
454
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
455
+ #
456
+ def get_custom_model_with_http_info(id, custom_headers:nil)
457
+ get_custom_model_async(id, custom_headers:custom_headers).value!
458
+ end
459
+
460
+ #
461
+ # Get Model
462
+ #
463
+ # Get information about a model.
464
+ #
465
+ # @param id Model identifier.
466
+ # @param [Hash{String => String}] A hash of custom headers that will be added
467
+ # to the HTTP request.
468
+ #
469
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
470
+ #
471
+ def get_custom_model_async(id, custom_headers:nil)
472
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
473
+ fail ArgumentError, 'id is nil' if id.nil?
474
+
475
+
476
+ request_headers = {}
477
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
478
+
479
+ # Set Headers
480
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
481
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
482
+ path_template = 'custom/models/{id}'
483
+
484
+ request_url = @base_url || self.base_url
485
+ request_url = request_url.gsub('{Endpoint}', endpoint)
486
+
487
+ options = {
488
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
489
+ path_params: {'id' => id},
490
+ headers: request_headers.merge(custom_headers || {}),
491
+ base_url: request_url
492
+ }
493
+ promise = self.make_request_async(:get, path_template, options)
494
+
495
+ promise = promise.then do |result|
496
+ http_response = result.response
497
+ status_code = http_response.status
498
+ response_content = http_response.body
499
+ unless status_code == 200
500
+ error_model = JSON.load(response_content)
501
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
502
+ end
503
+
504
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
505
+ # Deserialize Response
506
+ if status_code == 200
507
+ begin
508
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
509
+ result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::ModelResult.mapper()
510
+ result.body = self.deserialize(result_mapper, parsed_response)
511
+ rescue Exception => e
512
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
513
+ end
514
+ end
515
+
516
+ result
517
+ end
518
+
519
+ promise.execute
520
+ end
521
+
522
+ #
523
+ # Delete Model
524
+ #
525
+ # Delete model artifacts.
526
+ #
527
+ # @param id The identifier of the model to delete.
528
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
529
+ # will be added to the HTTP request.
530
+ #
531
+ #
532
+ def delete_custom_model(id, custom_headers:nil)
533
+ response = delete_custom_model_async(id, custom_headers:custom_headers).value!
534
+ nil
535
+ end
536
+
537
+ #
538
+ # Delete Model
539
+ #
540
+ # Delete model artifacts.
541
+ #
542
+ # @param id The identifier of the model to delete.
543
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
544
+ # will be added to the HTTP request.
545
+ #
546
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
547
+ #
548
+ def delete_custom_model_with_http_info(id, custom_headers:nil)
549
+ delete_custom_model_async(id, custom_headers:custom_headers).value!
550
+ end
551
+
552
+ #
553
+ # Delete Model
554
+ #
555
+ # Delete model artifacts.
556
+ #
557
+ # @param id The identifier of the model to delete.
558
+ # @param [Hash{String => String}] A hash of custom headers that will be added
559
+ # to the HTTP request.
560
+ #
561
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
562
+ #
563
+ def delete_custom_model_async(id, custom_headers:nil)
564
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
565
+ fail ArgumentError, 'id is nil' if id.nil?
566
+
567
+
568
+ request_headers = {}
569
+ request_headers['Content-Type'] = 'application/json; charset=utf-8'
570
+
571
+ # Set Headers
572
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
573
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
574
+ path_template = 'custom/models/{id}'
575
+
576
+ request_url = @base_url || self.base_url
577
+ request_url = request_url.gsub('{Endpoint}', endpoint)
578
+
579
+ options = {
580
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
581
+ path_params: {'id' => id},
582
+ headers: request_headers.merge(custom_headers || {}),
583
+ base_url: request_url
584
+ }
585
+ promise = self.make_request_async(:delete, path_template, options)
586
+
587
+ promise = promise.then do |result|
588
+ http_response = result.response
589
+ status_code = http_response.status
590
+ response_content = http_response.body
591
+ unless status_code == 204
592
+ error_model = JSON.load(response_content)
593
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
594
+ end
595
+
596
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
597
+
598
+ result
599
+ end
600
+
601
+ promise.execute
602
+ end
603
+
604
+ #
605
+ # Analyze Form
606
+ #
607
+ # The document to analyze must be of a supported content type -
608
+ # 'application/pdf', 'image/jpeg' or 'image/png'. The response contains not
609
+ # just the extracted information of the analyzed form but also information
610
+ # about content that was not extracted along with a reason.
611
+ #
612
+ # @param id Model Identifier to analyze the document with.
613
+ # @param form_stream A pdf document or image (jpg,png) file to analyze.
614
+ # @param keys [Array<String>] An optional list of known keys to extract the
615
+ # values for.
616
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
617
+ # will be added to the HTTP request.
618
+ #
619
+ # @return [AnalyzeResult] operation results.
620
+ #
621
+ def analyze_with_custom_model(id, form_stream, keys:nil, custom_headers:nil)
622
+ response = analyze_with_custom_model_async(id, form_stream, keys:keys, custom_headers:custom_headers).value!
623
+ response.body unless response.nil?
624
+ end
625
+
626
+ #
627
+ # Analyze Form
628
+ #
629
+ # The document to analyze must be of a supported content type -
630
+ # 'application/pdf', 'image/jpeg' or 'image/png'. The response contains not
631
+ # just the extracted information of the analyzed form but also information
632
+ # about content that was not extracted along with a reason.
633
+ #
634
+ # @param id Model Identifier to analyze the document with.
635
+ # @param form_stream A pdf document or image (jpg,png) file to analyze.
636
+ # @param keys [Array<String>] An optional list of known keys to extract the
637
+ # values for.
638
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
639
+ # will be added to the HTTP request.
640
+ #
641
+ # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
642
+ #
643
+ def analyze_with_custom_model_with_http_info(id, form_stream, keys:nil, custom_headers:nil)
644
+ analyze_with_custom_model_async(id, form_stream, keys:keys, custom_headers:custom_headers).value!
645
+ end
646
+
647
+ #
648
+ # Analyze Form
649
+ #
650
+ # The document to analyze must be of a supported content type -
651
+ # 'application/pdf', 'image/jpeg' or 'image/png'. The response contains not
652
+ # just the extracted information of the analyzed form but also information
653
+ # about content that was not extracted along with a reason.
654
+ #
655
+ # @param id Model Identifier to analyze the document with.
656
+ # @param form_stream A pdf document or image (jpg,png) file to analyze.
657
+ # @param keys [Array<String>] An optional list of known keys to extract the
658
+ # values for.
659
+ # @param [Hash{String => String}] A hash of custom headers that will be added
660
+ # to the HTTP request.
661
+ #
662
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
663
+ #
664
+ def analyze_with_custom_model_async(id, form_stream, keys:nil, custom_headers:nil)
665
+ fail ArgumentError, 'endpoint is nil' if endpoint.nil?
666
+ fail ArgumentError, 'id is nil' if id.nil?
667
+ fail ArgumentError, 'form_stream is nil' if form_stream.nil?
668
+
669
+
670
+ request_headers = {}
671
+ request_headers['Content-Type'] = 'application/pdf'
672
+
673
+ # Set Headers
674
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
675
+ request_headers['accept-language'] = accept_language unless accept_language.nil?
676
+
677
+ # Set Form Data
678
+ form_data = {}
679
+ form_data['form_stream'] = form_stream.to_s unless form_stream.to_s.nil?
680
+
681
+ path_template = 'custom/models/{id}/analyze'
682
+
683
+ request_url = @base_url || self.base_url
684
+ request_url = request_url.gsub('{Endpoint}', endpoint)
685
+
686
+ options = {
687
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
688
+ path_params: {'id' => id},
689
+ query_params: {'keys' => keys.nil? ? nil : keys.join(',')},
690
+ headers: request_headers.merge(custom_headers || {}),
691
+ body: URI.encode_www_form(form_data),
692
+ base_url: request_url
693
+ }
694
+ promise = self.make_request_async(:post, path_template, options)
695
+
696
+ promise = promise.then do |result|
697
+ http_response = result.response
698
+ status_code = http_response.status
699
+ response_content = http_response.body
700
+ unless status_code == 200
701
+ error_model = JSON.load(response_content)
702
+ fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
703
+ end
704
+
705
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
706
+ # Deserialize Response
707
+ if status_code == 200
708
+ begin
709
+ parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
710
+ result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::AnalyzeResult.mapper()
711
+ result.body = self.deserialize(result_mapper, parsed_response)
712
+ rescue Exception => e
713
+ fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
714
+ end
715
+ end
716
+
717
+ result
718
+ end
719
+
720
+ promise.execute
721
+ end
722
+
723
+
724
+ private
725
+ #
726
+ # Adds telemetry information.
727
+ #
728
+ def add_telemetry
729
+ sdk_information = 'azure_cognitiveservices_formrecognizer'
730
+ sdk_information = "#{sdk_information}/0.17.0"
731
+ add_user_agent_information(sdk_information)
732
+ end
733
+ end
734
+ end