Class: Azure::CognitiveServices::FormRecognizer::V1_0_preview::FormRecognizerClient

Inherits:
MsRestAzure::AzureServiceClient
  • Object
show all
Includes:
MsRestAzure, MsRestAzure::Serialization
Defined in:
lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb

Overview

A service client - single point of access to the REST API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials = nil, options = nil) ⇒ FormRecognizerClient

Creates initializes a new instance of the FormRecognizerClient class.

Parameters:

  • credentials (MsRest::ServiceClientCredentials) (defaults to: nil)

    credentials to authorize HTTP requests made by the service client.

  • options (Array) (defaults to: nil)

    filters to be applied to the HTTP requests.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 45

def initialize(credentials = nil, options = nil)
  super(credentials, options)
  @base_url = '{Endpoint}/formrecognizer/v1.0-preview'

  fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials) unless credentials.nil?
  @credentials = credentials

  @accept_language = 'en-US'
  @long_running_operation_retry_timeout = 30
  @generate_client_request_id = true
  add_telemetry
end

Instance Attribute Details

#accept_languageString

Returns The preferred language for the response.

Returns:

  • (String)

    The preferred language for the response.



29
30
31
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 29

def accept_language
  @accept_language
end

#base_urlString (readonly)

Returns the base URI of the service.

Returns:

  • (String)

    the base URI of the service.



15
16
17
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 15

def base_url
  @base_url
end

#credentialsObject

subscription.

Returns:

  • Subscription credentials which uniquely identify client



26
27
28
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 26

def credentials
  @credentials
end

#credentials1Object (readonly)

Returns Credentials needed for the client to connect to Azure.

Returns:

  • Credentials needed for the client to connect to Azure.



18
19
20
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 18

def credentials1
  @credentials1
end

#endpointString

hostname, for example: westus2.api.cognitive.microsoft.com).

Returns:

  • (String)

    Supported Cognitive Services endpoints (protocol and



22
23
24
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 22

def endpoint
  @endpoint
end

#generate_client_request_idBoolean

generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.

Returns:

  • (Boolean)

    Whether a unique x-ms-client-request-id should be



38
39
40
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 38

def generate_client_request_id
  @generate_client_request_id
end

#long_running_operation_retry_timeoutInteger

Operations. Default value is 30.

Returns:

  • (Integer)

    The retry timeout in seconds for Long Running



33
34
35
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 33

def long_running_operation_retry_timeout
  @long_running_operation_retry_timeout
end

Instance Method Details

#analyze_with_custom_model(id, form_stream, keys: nil, custom_headers: nil) ⇒ AnalyzeResult

Analyze Form

Extract key-value pairs from a given document. The input document must be of one of the supported content types - ‘application/pdf’, ‘image/jpeg’ or ‘image/png’. A success response is returned in JSON.

values for. will be added to the HTTP request.

Parameters:

  • id

    Model Identifier to analyze the document with.

  • form_stream

    A pdf document or image (jpg,png) file to analyze.

  • keys (Array<String>) (defaults to: nil)

    An optional list of known keys to extract the

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (AnalyzeResult)

    operation results.



633
634
635
636
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 633

def analyze_with_custom_model(id, form_stream, keys:nil, custom_headers:nil)
  response = analyze_with_custom_model_async(id, form_stream, keys:keys, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#analyze_with_custom_model_async(id, form_stream, keys: nil, custom_headers: nil) ⇒ Concurrent::Promise

Analyze Form

Extract key-value pairs from a given document. The input document must be of one of the supported content types - ‘application/pdf’, ‘image/jpeg’ or ‘image/png’. A success response is returned in JSON.

values for. to the HTTP request.

Parameters:

  • id

    Model Identifier to analyze the document with.

  • form_stream

    A pdf document or image (jpg,png) file to analyze.

  • keys (Array<String>) (defaults to: nil)

    An optional list of known keys to extract the

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 674

def analyze_with_custom_model_async(id, form_stream, keys:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'id is nil' if id.nil?
  fail ArgumentError, 'form_stream is nil' if form_stream.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/pdf'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Set Form Data
  form_data = {}
  form_data['form_stream'] = form_stream.to_s unless form_stream.to_s.nil?

  path_template = 'custom/models/{id}/analyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'id' => id},
      query_params: {'keys' => keys.nil? ? nil : keys.join(',')},
      headers: request_headers.merge(custom_headers || {}),
      body: URI.encode_www_form(form_data),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::AnalyzeResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#analyze_with_custom_model_with_http_info(id, form_stream, keys: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Analyze Form

Extract key-value pairs from a given document. The input document must be of one of the supported content types - ‘application/pdf’, ‘image/jpeg’ or ‘image/png’. A success response is returned in JSON.

values for. will be added to the HTTP request.

Parameters:

  • id

    Model Identifier to analyze the document with.

  • form_stream

    A pdf document or image (jpg,png) file to analyze.

  • keys (Array<String>) (defaults to: nil)

    An optional list of known keys to extract the

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



654
655
656
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 654

def analyze_with_custom_model_with_http_info(id, form_stream, keys:nil, custom_headers:nil)
  analyze_with_custom_model_async(id, form_stream, keys:keys, custom_headers:custom_headers).value!
end

#batch_read_receipt(url, custom_headers: nil) ⇒ Object

Batch Read Receipt operation. The response contains a field called ‘Operation-Location’, which contains the URL that you must use for your ‘Get Read Receipt Result’ operation.

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that



745
746
747
748
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 745

def batch_read_receipt(url, custom_headers:nil)
  response = batch_read_receipt_async(url, custom_headers:custom_headers).value!
  nil
end

#batch_read_receipt_async(url, custom_headers: nil) ⇒ Concurrent::Promise

Batch Read Receipt operation. The response contains a field called ‘Operation-Location’, which contains the URL that you must use for your ‘Get Read Receipt Result’ operation.

to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 776

def batch_read_receipt_async(url, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'url is nil' if url.nil?

  image_url = ImageUrl.new
  unless url.nil?
    image_url.url = url
  end

  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::ImageUrl.mapper()
  request_content = self.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'prebuilt/receipt/asyncBatchAnalyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 202
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#batch_read_receipt_in_stream(image, custom_headers: nil) ⇒ Object

Read Receipt operation. When you use the ‘Batch Read Receipt’ interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘Get Read Receipt Result’ operation.

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that



938
939
940
941
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 938

def batch_read_receipt_in_stream(image, custom_headers:nil)
  response = batch_read_receipt_in_stream_async(image, custom_headers:custom_headers).value!
  nil
end

#batch_read_receipt_in_stream_async(image, custom_headers: nil) ⇒ Concurrent::Promise

Read Receipt operation. When you use the ‘Batch Read Receipt’ interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘Get Read Receipt Result’ operation.

to the HTTP request.

Parameters:

  • image

    An image stream.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 971

def batch_read_receipt_in_stream_async(image, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'image is nil' if image.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/octet-stream'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'Image',
    type: {
      name: 'Stream'
    }
  }
  request_content = self.serialize(request_mapper,  image)

  path_template = 'prebuilt/receipt/asyncBatchAnalyze'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 202
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#batch_read_receipt_in_stream_with_http_info(image, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Read Receipt operation. When you use the ‘Batch Read Receipt’ interface, the response contains a field called ‘Operation-Location’. The ‘Operation-Location’ field contains the URL that you must use for your ‘Get Read Receipt Result’ operation.

will be added to the HTTP request.

Parameters:

  • image

    An image stream.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



955
956
957
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 955

def batch_read_receipt_in_stream_with_http_info(image, custom_headers:nil)
  batch_read_receipt_in_stream_async(image, custom_headers:custom_headers).value!
end

#batch_read_receipt_with_http_info(url, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Batch Read Receipt operation. The response contains a field called ‘Operation-Location’, which contains the URL that you must use for your ‘Get Read Receipt Result’ operation.

will be added to the HTTP request.

Parameters:

  • url (String)

    Publicly reachable URL of an image.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



761
762
763
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 761

def batch_read_receipt_with_http_info(url, custom_headers:nil)
  batch_read_receipt_async(url, custom_headers:custom_headers).value!
end

#delete_custom_model(id, custom_headers: nil) ⇒ Object

Delete Model

Delete model artifacts.

will be added to the HTTP request.

Parameters:

  • id

    The identifier of the model to delete.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that



543
544
545
546
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 543

def delete_custom_model(id, custom_headers:nil)
  response = delete_custom_model_async(id, custom_headers:custom_headers).value!
  nil
end

#delete_custom_model_async(id, custom_headers: nil) ⇒ Concurrent::Promise

Delete Model

Delete model artifacts.

to the HTTP request.

Parameters:

  • id

    The identifier of the model to delete.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 574

def delete_custom_model_async(id, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'id is nil' if id.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'custom/models/{id}'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'id' => id},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:delete, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 204
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?

    result
  end

  promise.execute
end

#delete_custom_model_with_http_info(id, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Delete Model

Delete model artifacts.

will be added to the HTTP request.

Parameters:

  • id

    The identifier of the model to delete.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



559
560
561
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 559

def delete_custom_model_with_http_info(id, custom_headers:nil)
  delete_custom_model_async(id, custom_headers:custom_headers).value!
end

#get_custom_model(id, custom_headers: nil) ⇒ ModelResult

Get Model

Get information about a model.

will be added to the HTTP request.

Parameters:

  • id

    Model identifier.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ModelResult)

    operation results.



449
450
451
452
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 449

def get_custom_model(id, custom_headers:nil)
  response = get_custom_model_async(id, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_custom_model_async(id, custom_headers: nil) ⇒ Concurrent::Promise

Get Model

Get information about a model.

to the HTTP request.

Parameters:

  • id

    Model identifier.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 480

def get_custom_model_async(id, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'id is nil' if id.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'custom/models/{id}'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'id' => id},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:get, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::ModelResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_custom_model_with_http_info(id, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Get Model

Get information about a model.

will be added to the HTTP request.

Parameters:

  • id

    Model identifier.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



465
466
467
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 465

def get_custom_model_with_http_info(id, custom_headers:nil)
  get_custom_model_async(id, custom_headers:custom_headers).value!
end

#get_custom_models(custom_headers: nil) ⇒ ModelsResult

Get Models

Get information about all trained custom models

will be added to the HTTP request.

Parameters:

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ModelsResult)

    operation results.



358
359
360
361
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 358

def get_custom_models(custom_headers:nil)
  response = get_custom_models_async(custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_custom_models_async(custom_headers: nil) ⇒ Concurrent::Promise

Get Models

Get information about all trained custom models

to the HTTP request.

Parameters:

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 387

def get_custom_models_async(custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'custom/models'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:get, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::ModelsResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_custom_models_with_http_info(custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Get Models

Get information about all trained custom models

will be added to the HTTP request.

Parameters:

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



373
374
375
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 373

def get_custom_models_with_http_info(custom_headers:nil)
  get_custom_models_async(custom_headers:custom_headers).value!
end

#get_extracted_keys(id, custom_headers: nil) ⇒ KeysResult

Get Keys

Retrieve the keys that were extracted during the training of the specified model.

will be added to the HTTP request.

Parameters:

  • id

    Model identifier.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (KeysResult)

    operation results.



262
263
264
265
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 262

def get_extracted_keys(id, custom_headers:nil)
  response = get_extracted_keys_async(id, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_extracted_keys_async(id, custom_headers: nil) ⇒ Concurrent::Promise

Get Keys

Retrieve the keys that were extracted during the training of the specified model.

to the HTTP request.

Parameters:

  • id

    Model identifier.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 295

def get_extracted_keys_async(id, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'id is nil' if id.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'custom/models/{id}/keys'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'id' => id},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:get, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::KeysResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_extracted_keys_with_http_info(id, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Get Keys

Retrieve the keys that were extracted during the training of the specified model.

will be added to the HTTP request.

Parameters:

  • id

    Model identifier.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



279
280
281
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 279

def get_extracted_keys_with_http_info(id, custom_headers:nil)
  get_extracted_keys_async(id, custom_headers:custom_headers).value!
end

#get_read_receipt_result(operation_id, custom_headers: nil) ⇒ ReadReceiptResult

This interface is used for getting the analysis results of a ‘Batch Read Receipt’ operation. The URL to this interface should be retrieved from the ‘Operation-Location’ field returned from the ‘Batch Read Receipt’ operation.

a ‘Batch Read Receipt’ operation. will be added to the HTTP request.

Parameters:

  • operation_id (String)

    Id of read operation returned in the response of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (ReadReceiptResult)

    operation results.



841
842
843
844
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 841

def get_read_receipt_result(operation_id, custom_headers:nil)
  response = get_read_receipt_result_async(operation_id, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#get_read_receipt_result_async(operation_id, custom_headers: nil) ⇒ Concurrent::Promise

This interface is used for getting the analysis results of a ‘Batch Read Receipt’ operation. The URL to this interface should be retrieved from the ‘Operation-Location’ field returned from the ‘Batch Read Receipt’ operation.

a ‘Batch Read Receipt’ operation. to the HTTP request.

Parameters:

  • operation_id (String)

    Id of read operation returned in the response of

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 874

def get_read_receipt_result_async(operation_id, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'operation_id is nil' if operation_id.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?
  path_template = 'prebuilt/receipt/operations/{operationId}'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      path_params: {'operationId' => operation_id},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:get, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::ReadReceiptResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#get_read_receipt_result_with_http_info(operation_id, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

This interface is used for getting the analysis results of a ‘Batch Read Receipt’ operation. The URL to this interface should be retrieved from the ‘Operation-Location’ field returned from the ‘Batch Read Receipt’ operation.

a ‘Batch Read Receipt’ operation. will be added to the HTTP request.

Parameters:

  • operation_id (String)

    Id of read operation returned in the response of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



858
859
860
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 858

def get_read_receipt_result_with_http_info(operation_id, custom_headers:nil)
  get_read_receipt_result_async(operation_id, custom_headers:custom_headers).value!
end

#make_request(method, path, options = {}) ⇒ Hash{String=>String}

Makes a request and returns the body of the response. Example:

request_content = "{'location':'westus','tags':{'tag1':'val1','tag2':'val2'}}"
path = "/path"
options = {
  body: request_content,
  query_params: {'api-version' => '2016-02-01'}
}
result = @client.make_request(:put, path, options)

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (Hash{String=>String})

    containing the body of the response.



74
75
76
77
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 74

def make_request(method, path, options = {})
  result = make_request_with_http_info(method, path, options)
  result.body unless result.nil?
end

#make_request_async(method, path, options = {}) ⇒ Concurrent::Promise

Makes a request asynchronously.

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 99

def make_request_async(method, path, options = {})
  fail ArgumentError, 'method is nil' if method.nil?
  fail ArgumentError, 'path is nil' if path.nil?

  request_url = options[:base_url] || @base_url
  if(!options[:headers].nil? && !options[:headers]['Content-Type'].nil?)
    @request_headers['Content-Type'] = options[:headers]['Content-Type']
  end

  request_headers = @request_headers
  request_headers.merge!({'accept-language' => @accept_language}) unless @accept_language.nil?
  options.merge!({headers: request_headers.merge(options[:headers] || {})})
  options.merge!({credentials: @credentials}) unless @credentials.nil?

  super(request_url, method, path, options)
end

#make_request_with_http_info(method, path, options = {}) ⇒ MsRestAzure::AzureOperationResponse

Makes a request and returns the operation response.

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (MsRestAzure::AzureOperationResponse)

    Operation response containing the request, response and status.



86
87
88
89
90
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 86

def make_request_with_http_info(method, path, options = {})
  result = make_request_async(method, path, options).value!
  result.body = result.response.body.to_s.empty? ? nil : JSON.load(result.response.body)
  result
end

#train_custom_model(train_request, custom_headers: nil) ⇒ TrainResult

Train Model

Create and train a custom model. The train request must include a source parameter that is either an externally accessible Azure Storage blob container Uri (preferably a Shared Access Signature Uri) or valid path to a data folder in a locally mounted drive. When local paths are specified, they must follow the Linux/Unix path format and be an absolute path rooted to the input mount configuration setting value e.g., if ‘Mounts:Input’ configuration setting value is ‘/input’ then a valid source path would be ‘/input/contosodataset’. All data to be trained is expected to be directly under the source folder. Subfolders are not supported. Models are trained using documents that are of the following content type - ‘application/pdf’, ‘image/jpeg’ and ‘image/png’.“ Other type of content is ignored.

will be added to the HTTP request.

Parameters:

  • train_request (TrainRequest)

    Request object for training.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (TrainResult)

    operation results.



138
139
140
141
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 138

def train_custom_model(train_request, custom_headers:nil)
  response = train_custom_model_async(train_request, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#train_custom_model_async(train_request, custom_headers: nil) ⇒ Concurrent::Promise

Train Model

Create and train a custom model. The train request must include a source parameter that is either an externally accessible Azure Storage blob container Uri (preferably a Shared Access Signature Uri) or valid path to a data folder in a locally mounted drive. When local paths are specified, they must follow the Linux/Unix path format and be an absolute path rooted to the input mount configuration setting value e.g., if ‘Mounts:Input’ configuration setting value is ‘/input’ then a valid source path would be ‘/input/contosodataset’. All data to be trained is expected to be directly under the source folder. Subfolders are not supported. Models are trained using documents that are of the following content type - ‘application/pdf’, ‘image/jpeg’ and ‘image/png’.“ Other type of content is ignored.

to the HTTP request.

Parameters:

  • train_request (TrainRequest)

    Request object for training.

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 191

def train_custom_model_async(train_request, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.nil?
  fail ArgumentError, 'train_request is nil' if train_request.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'application/json; charset=utf-8'

  # Set Headers
  request_headers['x-ms-client-request-id'] = SecureRandom.uuid
  request_headers['accept-language'] = accept_language unless accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::TrainRequest.mapper()
  request_content = self.serialize(request_mapper,  train_request)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'custom/train'

  request_url = @base_url || self.base_url
request_url = request_url.gsub('{Endpoint}', endpoint)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200
      error_model = JSON.load(response_content)
      fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
    end

    result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
    result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
    result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::FormRecognizer::V1_0_preview::Models::TrainResult.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#train_custom_model_with_http_info(train_request, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Train Model

Create and train a custom model. The train request must include a source parameter that is either an externally accessible Azure Storage blob container Uri (preferably a Shared Access Signature Uri) or valid path to a data folder in a locally mounted drive. When local paths are specified, they must follow the Linux/Unix path format and be an absolute path rooted to the input mount configuration setting value e.g., if ‘Mounts:Input’ configuration setting value is ‘/input’ then a valid source path would be ‘/input/contosodataset’. All data to be trained is expected to be directly under the source folder. Subfolders are not supported. Models are trained using documents that are of the following content type - ‘application/pdf’, ‘image/jpeg’ and ‘image/png’.“ Other type of content is ignored.

will be added to the HTTP request.

Parameters:

  • train_request (TrainRequest)

    Request object for training.

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



165
166
167
# File 'lib/1.0-preview/generated/azure_cognitiveservices_formrecognizer/form_recognizer_client.rb', line 165

def train_custom_model_with_http_info(train_request, custom_headers:nil)
  train_custom_model_async(train_request, custom_headers:custom_headers).value!
end