class Azure::CognitiveServices::ContentModerator::V1_0::ImageModeration

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.

Attributes

client[R]

@return [ContentModeratorClient] reference to the ContentModeratorClient

Private Class Methods

new(client) click to toggle source

Creates and initializes a new instance of the ImageModeration class. @param client service class for accessing basic functionality.

# File lib/1.0/generated/azure_cognitiveservices_contentmoderator/image_moderation.rb, line 27
def initialize(client)
  @client = client
end

Private Instance Methods

evaluate_file_input(image_stream, cache_image:nil, custom_headers:nil) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Evaluate] operation results.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Evaluate] operation results.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Evaluate] operation results.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

Returns probabilities of the image containing racy or adult content.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

Returns the list of faces found.

@param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [FoundFaces] operation results.

# 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) click to toggle source

Returns the list of faces found.

@param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

Returns the list of faces found.

@param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [FoundFaces] operation results.

# 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) click to toggle source

Returns the list of faces found.

@param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

Returns the list of faces found.

@param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

Returns the list of faces found.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [FoundFaces] operation results.

# 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) click to toggle source

Returns the list of faces found.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

Returns the list of faces found.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

Returns the list of faces found.

@param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

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.

@param image_stream The image file. @param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MatchResponse] operation results.

# 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) click to toggle source

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.

@param image_stream The image file. @param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

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.

@param image_stream The image file. @param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

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.

@param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MatchResponse] operation results.

# 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) click to toggle source

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.

@param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

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.

@param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

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.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MatchResponse] operation results.

# 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) click to toggle source

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.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

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.

@param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param list_id [String] The list Id. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [OCR] operation results.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param image_stream The image file. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [OCR] operation results.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [OCR] operation results.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [Concurrent::Promise] Promise object which holds the HTTP response.

# 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) click to toggle source

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

@param language [String] Language of the terms. @param content_type [String] The content type. @param image_url [ImageUrl] The image url. @param cache_image [Boolean] Whether to retain the submitted image for future use; defaults to false if omitted. @param enhanced [Boolean] When set to True, the image goes through additional processing to come with additional candidates.

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

Note: This impacts the response time. @param custom_headers [Hash{String => String}] A hash of custom headers that will be added to the HTTP request.

@return [MsRestAzure::AzureOperationResponse] HTTP response information.

# 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