class SightEngineE

The sightengine class.

Constants

BASE_URL

The sightengine endpoint.

VALID_CATEGORIES

The valid categories that sightengine api takes.

Public Class Methods

new(api_user, api_secret, workflow=nil) click to toggle source

@param [String] api_user the api_user credential provided by sightengine. @param api_secret [String] the api_secret credential provided by sightengine. @param worklfow [String] the workflow you have created in the sightengine interface, this is optional.

# File lib/rubysightengine/client.rb, line 30
def initialize(api_user, api_secret, workflow=nil)

    @api_user = api_user
    @api_secret = api_secret
    @workflow = nil 
    @min = 0.9     

end

Public Instance Methods

check(target_url, *type) click to toggle source

Checks a image for any content by making an HTTP request to the sightengine servers. @param target_url [String] the url of the target image. @param type [String] the type of content to be scanned for.

# File lib/rubysightengine/client.rb, line 50
def check(target_url, *type)

 
    if type.any? {|t| VALID_CATEGORIES.include?(t) === false}

        raise "while checking, one or more of your sightengine types were not found"

    end

    uri = URI("https://api.sightengine.com/1.0/check.json")

    form_h = {api_user: @api_user, api_secret: @api_secret, url: target_url} 
    form_h[:workflow] = @workflow if @workflow != nil
    form_h[:models] = type.join(",")
    uri.query = URI.encode_www_form(form_h)

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = (uri.scheme == 'https')

    request = Net::HTTP::Get.new(uri)
    request.body = ""
    request.add_field 'Accept', 'application/json'
    response = http.request(request)

    if response.is_a?(Net::HTTPSuccess) === false 
        raise "sightengine server gave a #{response.code} error: #{response.msg}"
    end 

    # @return [Checked] if request is 200
    return Checked.new(response.body)

end
set_workflow(workflow) click to toggle source

Sets the workflow for the class. @param workflow [String] the target workflow to set as the class workflow.

# File lib/rubysightengine/client.rb, line 41
def set_workflow(workflow)

    @workflow = workflow

end