class PrevotySmartFilter

Attributes

base[RW]
key[RW]

Public Class Methods

new(key) click to toggle source
# File lib/stoolie/clients/prevoty/smartfilter.rb, line 18
def initialize(key)
  @key = key
  @base = 'https://api.prevoty.com/1'
end

Public Instance Methods

filter(input, rule_key) click to toggle source

Endpoint: /xss/filter

# File lib/stoolie/clients/prevoty/smartfilter.rb, line 81
def filter(input, rule_key)
  begin
    return filter!(input, rule_key)
  rescue => e
    return nil
  end
end
filter!(input, rule_key) click to toggle source
# File lib/stoolie/clients/prevoty/smartfilter.rb, line 89
def filter!(input, rule_key)
  options = {:api_key => @key, :input => input, :rule_key => rule_key}
  response = HTTParty.post("#{@base}/xss/filter", :query => options)
  return JSON.parse(response.body) if response.code == 200
  raise SmartFilterBadInputParameter.new if response.code == 400
  raise SmartFilterBadAPIKey.new if response.code == 403
  raise SmartFilterRequestTooLarge.new if response.code == 413
  raise SmartFilterInternalError.new if response.code == 500
  raise SmartFilterAccountQuotaExceeded.new if response.code == 507
  Array.new
end
info() click to toggle source

Endpoint: /key/info

# File lib/stoolie/clients/prevoty/smartfilter.rb, line 43
def info
  begin
    return info!
  rescue => e
    return nil
  end
end
info!() click to toggle source
# File lib/stoolie/clients/prevoty/smartfilter.rb, line 51
def info!
  options = {:api_key => @key}
  response = HTTParty.get("#{@base}/key/info", :query => options)
  return JSON.parse(response.body) if response.code == 200
  raise SmartFilterBadInputParameter.new if response.code == 400
  raise SmartFilterBadAPIKey.new if response.code == 403
  raise SmartFilterInternalError.new if response.code == 500
  Array.new
end
verify() click to toggle source

Endpoint: /key/verify

# File lib/stoolie/clients/prevoty/smartfilter.rb, line 24
def verify
  begin
    return verify!
  rescue => e
    return nil
  end
end
verify!() click to toggle source
# File lib/stoolie/clients/prevoty/smartfilter.rb, line 32
def verify!
  options = {:api_key => @key}
  response = HTTParty.get("#{@base}/key/verify", :query => options)
  return true if response.code == 200
  raise SmartFilterBadInputParameter.new if response.code == 400
  raise SmartFilterBadAPIKey.new if response.code == 403
  raise SmartFilterInternalError.new if response.code == 500
  false
end
verify_rule(rule_key) click to toggle source

Endpoint: /rule/verify

# File lib/stoolie/clients/prevoty/smartfilter.rb, line 62
def verify_rule(rule_key)
  begin
    return verify_rule!(rule_key)
  rescue => e
    return nil
  end
end
verify_rule!(rule_key) click to toggle source
# File lib/stoolie/clients/prevoty/smartfilter.rb, line 70
def verify_rule!(rule_key)
  options = {:api_key => @key, :rule_key => rule_key}
  response = HTTParty.get("#{@base}/rule/verify", :query => options)
  return true if response.code == 200
  raise SmartFilterBadInputParameter.new if response.code == 400
  raise SmartFilterBadAPIKey.new if response.code == 403
  raise SmartFilterInternalError.new if response.code == 500
  false
end