Class: Azure::CognitiveServices::ContentModerator::V1_0::ImageModeration

Inherits:
Object
  • Object
show all
Includes:
MsRestAzure
Defined in:
lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb

Overview

You use the API to scan your content as it is generated. Content Moderator then processes your content and sends the results along with relevant information either back to your systems or to the built-in review tool. You can use this information to take decisions e.g. take it down, send to human judge, etc.

When using the API, images need to have a minimum of 128 pixels and a maximum file size of 4MB. Text can be at most 1024 characters long. If the content passed to the text API or the image API exceeds the size limits, the API will return an error code that informs about the issue.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ImageModeration

Creates and initializes a new instance of the ImageModeration class.

Parameters:

  • client

    service class for accessing basic functionality.



27
28
29
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 27

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientContentModeratorClient (readonly)

Returns reference to the ContentModeratorClient.

Returns:



32
33
34
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 32

def client
  @client
end

Instance Method Details

#evaluate_file_input(image_stream, cache_image: nil, custom_headers: nil) ⇒ Evaluate

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (Evaluate)

    operation results.



925
926
927
928
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 925

def evaluate_file_input(image_stream, cache_image:nil, custom_headers:nil)
  response = evaluate_file_input_async(image_stream, cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#evaluate_file_input_async(image_stream, cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
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
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 956

def evaluate_file_input_async(image_stream, cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'image_stream is nil' if image_stream.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'image/gif'

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

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'ImageStream',
    type: {
      name: 'Stream'
    }
  }
  request_content = @client.serialize(request_mapper,  image_stream)

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/Evaluate'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'CacheImage' => cache_image},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::Evaluate.mapper()
        result.body = @client.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

#evaluate_file_input_with_http_info(image_stream, cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



941
942
943
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 941

def evaluate_file_input_with_http_info(image_stream, cache_image:nil, custom_headers:nil)
  evaluate_file_input_async(image_stream, cache_image:cache_image, custom_headers:custom_headers).value!
end

#evaluate_method(cache_image: nil, custom_headers: nil) ⇒ Evaluate

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (Evaluate)

    operation results.



247
248
249
250
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 247

def evaluate_method(cache_image:nil, custom_headers:nil)
  response = evaluate_method_async(cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#evaluate_method_async(cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 276

def evaluate_method_async(cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.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'] = @client.accept_language unless @client.accept_language.nil?
  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/Evaluate'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'CacheImage' => cache_image},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::Evaluate.mapper()
        result.body = @client.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

#evaluate_method_with_http_info(cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



262
263
264
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 262

def evaluate_method_with_http_info(cache_image:nil, custom_headers:nil)
  evaluate_method_async(cache_image:cache_image, custom_headers:custom_headers).value!
end

#evaluate_url_input(content_type, image_url, cache_image: nil, custom_headers: nil) ⇒ Evaluate

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (Evaluate)

    operation results.



1032
1033
1034
1035
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1032

def evaluate_url_input(content_type, image_url, cache_image:nil, custom_headers:nil)
  response = evaluate_url_input_async(content_type, image_url, cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#evaluate_url_input_async(content_type, image_url, cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1065

def evaluate_url_input_async(content_type, image_url, cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'content_type is nil' if content_type.nil?
  fail ArgumentError, 'image_url is nil' if image_url.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['Content-Type'] = content_type unless content_type.nil?
  request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::ImageUrl.mapper()
  request_content = @client.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/Evaluate'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'CacheImage' => cache_image},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::Evaluate.mapper()
        result.body = @client.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

#evaluate_url_input_with_http_info(content_type, image_url, cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns probabilities of the image containing racy or adult content.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1049
1050
1051
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1049

def evaluate_url_input_with_http_info(content_type, image_url, cache_image:nil, custom_headers:nil)
  evaluate_url_input_async(content_type, image_url, cache_image:cache_image, custom_headers:custom_headers).value!
end

#find_faces(cache_image: nil, custom_headers: nil) ⇒ FoundFaces

Returns the list of faces found.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (FoundFaces)

    operation results.



44
45
46
47
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 44

def find_faces(cache_image:nil, custom_headers:nil)
  response = find_faces_async(cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#find_faces_async(cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Returns the list of faces found.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 73

def find_faces_async(cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.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'] = @client.accept_language unless @client.accept_language.nil?
  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/FindFaces'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'CacheImage' => cache_image},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::FoundFaces.mapper()
        result.body = @client.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

#find_faces_file_input(image_stream, cache_image: nil, custom_headers: nil) ⇒ FoundFaces

Returns the list of faces found.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (FoundFaces)

    operation results.



453
454
455
456
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 453

def find_faces_file_input(image_stream, cache_image:nil, custom_headers:nil)
  response = find_faces_file_input_async(image_stream, cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#find_faces_file_input_async(image_stream, cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Returns the list of faces found.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 484

def find_faces_file_input_async(image_stream, cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'image_stream is nil' if image_stream.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'image/gif'

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

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'ImageStream',
    type: {
      name: 'Stream'
    }
  }
  request_content = @client.serialize(request_mapper,  image_stream)

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/FindFaces'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'CacheImage' => cache_image},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::FoundFaces.mapper()
        result.body = @client.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

#find_faces_file_input_with_http_info(image_stream, cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns the list of faces found.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



469
470
471
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 469

def find_faces_file_input_with_http_info(image_stream, cache_image:nil, custom_headers:nil)
  find_faces_file_input_async(image_stream, cache_image:cache_image, custom_headers:custom_headers).value!
end

#find_faces_url_input(content_type, image_url, cache_image: nil, custom_headers: nil) ⇒ FoundFaces

Returns the list of faces found.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (FoundFaces)

    operation results.



560
561
562
563
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 560

def find_faces_url_input(content_type, image_url, cache_image:nil, custom_headers:nil)
  response = find_faces_url_input_async(content_type, image_url, cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#find_faces_url_input_async(content_type, image_url, cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Returns the list of faces found.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 593

def find_faces_url_input_async(content_type, image_url, cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'content_type is nil' if content_type.nil?
  fail ArgumentError, 'image_url is nil' if image_url.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['Content-Type'] = content_type unless content_type.nil?
  request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::ImageUrl.mapper()
  request_content = @client.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/FindFaces'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'CacheImage' => cache_image},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::FoundFaces.mapper()
        result.body = @client.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

#find_faces_url_input_with_http_info(content_type, image_url, cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns the list of faces found.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



577
578
579
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 577

def find_faces_url_input_with_http_info(content_type, image_url, cache_image:nil, custom_headers:nil)
  find_faces_url_input_async(content_type, image_url, cache_image:cache_image, custom_headers:custom_headers).value!
end

#find_faces_with_http_info(cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns the list of faces found.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



59
60
61
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 59

def find_faces_with_http_info(cache_image:nil, custom_headers:nil)
  find_faces_async(cache_image:cache_image, custom_headers:custom_headers).value!
end

#match_file_input(image_stream, list_id: nil, cache_image: nil, custom_headers: nil) ⇒ MatchResponse

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MatchResponse)

    operation results.



1277
1278
1279
1280
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1277

def match_file_input(image_stream, list_id:nil, cache_image:nil, custom_headers:nil)
  response = match_file_input_async(image_stream, list_id:list_id, cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#match_file_input_async(image_stream, list_id: nil, cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1326

def match_file_input_async(image_stream, list_id:nil, cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'image_stream is nil' if image_stream.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'image/gif'

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

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'ImageStream',
    type: {
      name: 'Stream'
    }
  }
  request_content = @client.serialize(request_mapper,  image_stream)

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/Match'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'listId' => list_id,'CacheImage' => cache_image},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::MatchResponse.mapper()
        result.body = @client.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

#match_file_input_with_http_info(image_stream, list_id: nil, cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • image_stream

    The image file.

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1302
1303
1304
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1302

def match_file_input_with_http_info(image_stream, list_id:nil, cache_image:nil, custom_headers:nil)
  match_file_input_async(image_stream, list_id:list_id, cache_image:cache_image, custom_headers:custom_headers).value!
end

#match_method(list_id: nil, cache_image: nil, custom_headers: nil) ⇒ MatchResponse

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MatchResponse)

    operation results.



345
346
347
348
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 345

def match_method(list_id:nil, cache_image:nil, custom_headers:nil)
  response = match_method_async(list_id:list_id, cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#match_method_async(list_id: nil, cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



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
437
438
439
440
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 392

def match_method_async(list_id:nil, cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.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'] = @client.accept_language unless @client.accept_language.nil?
  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/Match'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'listId' => list_id,'CacheImage' => cache_image},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::MatchResponse.mapper()
        result.body = @client.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

#match_method_with_http_info(list_id: nil, cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



369
370
371
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 369

def match_method_with_http_info(list_id:nil, cache_image:nil, custom_headers:nil)
  match_method_async(list_id:list_id, cache_image:cache_image, custom_headers:custom_headers).value!
end

#match_url_input(content_type, image_url, list_id: nil, cache_image: nil, custom_headers: nil) ⇒ MatchResponse

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MatchResponse)

    operation results.



1146
1147
1148
1149
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1146

def match_url_input(content_type, image_url, list_id:nil, cache_image:nil, custom_headers:nil)
  response = match_url_input_async(content_type, image_url, list_id:list_id, cache_image:cache_image, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#match_url_input_async(content_type, image_url, list_id: nil, cache_image: nil, custom_headers: nil) ⇒ Concurrent::Promise

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1197

def match_url_input_async(content_type, image_url, list_id:nil, cache_image:nil, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'content_type is nil' if content_type.nil?
  fail ArgumentError, 'image_url is nil' if image_url.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['Content-Type'] = content_type unless content_type.nil?
  request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::ImageUrl.mapper()
  request_content = @client.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/Match'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'listId' => list_id,'CacheImage' => cache_image},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::MatchResponse.mapper()
        result.body = @client.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

#match_url_input_with_http_info(content_type, image_url, list_id: nil, cache_image: nil, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Fuzzily match an image against one of your custom Image Lists. You can create and manage your custom image lists using <a href=“/docs/services/578ff44d2703741568569ab9/operations/578ff7b12703741568569abe”>this</a> API.

Returns ID and tags of matching image.<br/> <br/> Note: Refresh Index must be run on the corresponding Image List before additions and removals are reflected in the response.

use; defaults to false if omitted. will be added to the HTTP request.

Parameters:

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • list_id (String) (defaults to: nil)

    The list Id.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



1172
1173
1174
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 1172

def match_url_input_with_http_info(content_type, image_url, list_id:nil, cache_image:nil, custom_headers:nil)
  match_url_input_async(content_type, image_url, list_id:list_id, cache_image:cache_image, custom_headers:custom_headers).value!
end

#ocrfile_input(language, image_stream, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ OCR

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. will be added to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

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

    A hash of custom headers that

Returns:

  • (OCR)

    operation results.



802
803
804
805
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 802

def ocrfile_input(language, image_stream, cache_image:nil, enhanced:false, custom_headers:nil)
  response = ocrfile_input_async(language, image_stream, cache_image:cache_image, enhanced:enhanced, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#ocrfile_input_async(language, image_stream, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ Concurrent::Promise

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
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
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 849

def ocrfile_input_async(language, image_stream, cache_image:nil, enhanced:false, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'language is nil' if language.nil?
  fail ArgumentError, 'image_stream is nil' if image_stream.nil?


  request_headers = {}
  request_headers['Content-Type'] = 'image/gif'

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

  # Serialize Request
  request_mapper = {
    client_side_validation: true,
    required: true,
    serialized_name: 'ImageStream',
    type: {
      name: 'Stream'
    }
  }
  request_content = @client.serialize(request_mapper,  image_stream)

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/OCR'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'language' => language,'CacheImage' => cache_image,'enhanced' => enhanced},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::OCR.mapper()
        result.body = @client.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

#ocrfile_input_with_http_info(language, image_stream, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. will be added to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • image_stream

    The image file.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



826
827
828
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 826

def ocrfile_input_with_http_info(language, image_stream, cache_image:nil, enhanced:false, custom_headers:nil)
  ocrfile_input_async(language, image_stream, cache_image:cache_image, enhanced:enhanced, custom_headers:custom_headers).value!
end

#ocrmethod(language, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ OCR

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. will be added to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

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

    A hash of custom headers that

Returns:

  • (OCR)

    operation results.



141
142
143
144
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 141

def ocrmethod(language, cache_image:nil, enhanced:false, custom_headers:nil)
  response = ocrmethod_async(language, cache_image:cache_image, enhanced:enhanced, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#ocrmethod_async(language, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ Concurrent::Promise

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



186
187
188
189
190
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
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 186

def ocrmethod_async(language, cache_image:nil, enhanced:false, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'language is nil' if language.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'] = @client.accept_language unless @client.accept_language.nil?
  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/OCR'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'language' => language,'CacheImage' => cache_image,'enhanced' => enhanced},
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::OCR.mapper()
        result.body = @client.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

#ocrmethod_with_http_info(language, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. will be added to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



164
165
166
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 164

def ocrmethod_with_http_info(language, cache_image:nil, enhanced:false, custom_headers:nil)
  ocrmethod_async(language, cache_image:cache_image, enhanced:enhanced, custom_headers:custom_headers).value!
end

#ocrurl_input(language, content_type, image_url, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ OCR

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. will be added to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

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

    A hash of custom headers that

Returns:

  • (OCR)

    operation results.



673
674
675
676
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 673

def ocrurl_input(language, content_type, image_url, cache_image:nil, enhanced:false, custom_headers:nil)
  response = ocrurl_input_async(language, content_type, image_url, cache_image:cache_image, enhanced:enhanced, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#ocrurl_input_async(language, content_type, image_url, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ Concurrent::Promise

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 722

def ocrurl_input_async(language, content_type, image_url, cache_image:nil, enhanced:false, custom_headers:nil)
  fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil?
  fail ArgumentError, 'language is nil' if language.nil?
  fail ArgumentError, 'content_type is nil' if content_type.nil?
  fail ArgumentError, 'image_url is nil' if image_url.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['Content-Type'] = content_type unless content_type.nil?
  request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?

  # Serialize Request
  request_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::ImageUrl.mapper()
  request_content = @client.serialize(request_mapper,  image_url)
  request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

  path_template = 'contentmoderator/moderate/v1.0/ProcessImage/OCR'

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

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'language' => language,'CacheImage' => cache_image,'enhanced' => enhanced},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = @client.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?
    # Deserialize Response
    if status_code == 200
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::OCR.mapper()
        result.body = @client.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

#ocrurl_input_with_http_info(language, content_type, image_url, cache_image: nil, enhanced: false, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse

Returns any text found in the image for the language specified. If no language is specified in input then the detection defaults to English.

use; defaults to false if omitted. processing to come with additional candidates.

image/tiff is not supported when enhanced is set to true

Note: This impacts the response time. will be added to the HTTP request.

Parameters:

  • language (String)

    Language of the terms.

  • content_type (String)

    The content type.

  • image_url (ImageUrl)

    The image url.

  • cache_image (Boolean) (defaults to: nil)

    Whether to retain the submitted image for future

  • enhanced (Boolean) (defaults to: false)

    When set to True, the image goes through additional

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

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



698
699
700
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb', line 698

def ocrurl_input_with_http_info(language, content_type, image_url, cache_image:nil, enhanced:false, custom_headers:nil)
  ocrurl_input_async(language, content_type, image_url, cache_image:cache_image, enhanced:enhanced, custom_headers:custom_headers).value!
end