Class: WebPurify::Client

Inherits:
Object
  • Object
show all
Includes:
Blacklist, ImageFilters, TextFilters, Whitelist
Defined in:
lib/web_purify/client.rb

Overview

WebPurify::Client

The WebPurify::Client class maintains state of the request parameters like api_key, endpoint, etc., and provides easy methods for accessing WebPurify

Instance Method Summary collapse

Methods included from ImageFilters

#imgaccount, #imgcheck, #imgstatus

Methods included from Whitelist

#add_to_whitelist, #get_whitelist, #remove_from_whitelist

Methods included from Blacklist

#add_to_blacklist, #get_blacklist, #remove_from_blacklist

Methods included from TextFilters

#check, #check_count, #replace, #return

Constructor Details

#initialize(options) ⇒ Client

Initialize the class

Parameters:

  • options (String, Hash)

    Either an API key string, or a hash of options



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/web_purify/client.rb', line 19

def initialize(options)
  if options.is_a? String
    @api_key    = options
    @endpoint   = :us
    @enterprise = false
  elsif options.is_a? Hash
    @api_key    = options[:api_key]
    @endpoint   = options[:endpoint]   || :us
    @enterprise = options[:enterprise] || false
  end

  @request_base = {
    :host   => WebPurify::Constants.text_endpoints.fetch(@endpoint),
    :path   => WebPurify::Constants.rest_path,
    :scheme => WebPurify::Constants.scheme(@enterprise)
  }

  @query_base = {
    :api_key => @api_key,
    :format  => WebPurify::Constants.format
  }
end

Instance Method Details

#image_request_baseObject



46
47
48
# File 'lib/web_purify/client.rb', line 46

def image_request_base
  @request_base.merge(:host => WebPurify::Constants.image_endpoint)
end

#text_request_baseObject



42
43
44
# File 'lib/web_purify/client.rb', line 42

def text_request_base
  @request_base
end