module YandexImageModeration
YandexImageModeration
gem code
YandexImageModeration
module part for HTTP Client
Configuration of our class
YandexImageModeration
module part for HTTP Client
Constants
- VERSION
Public Class Methods
client()
click to toggle source
Returns an instance of the request handler.
@return [#post] an instance of a request handler
# File lib/yandex_image_moderation.rb, line 13 def client @client ||= ::YandexImageModeration::Client.new(config) end
config() { |config| ... }
click to toggle source
Configure it
@yieldparam [OpenStruct] an object on which to set configuration
options
@return [OpenStruct] options
# File lib/yandex_image_moderation/config.rb, line 10 def config @options ||= OptionSetter.new yield(@options.config) if block_given? @options.config end
moderate(file)
click to toggle source
Send a request for moderation
@return [Result] an instance of the Result
# File lib/yandex_image_moderation.rb, line 20 def moderate(file) return if file.nil? || !File.exist?(file) url = "#{config.url}?models=moderation,gender,pornography,ad" parse_response client.post(url, prepare_body(file)) end
Protected Class Methods
parse_response(response)
click to toggle source
# File lib/yandex_image_moderation.rb, line 29 def parse_response(response) return unless response.status == 200 raise(::YandexImageModeration::Error::InvalidResult, 'empty response') if response.content.nil? ::YandexImageModeration::Result.new JSON.parse(response.content) end
prepare_body(file)
click to toggle source
# File lib/yandex_image_moderation.rb, line 35 def prepare_body(file) { file: File.open(file, 'r'), token: @options.config.token } end