class Metascan::Client

The Client object, which stores an API key and has a (currently not used) Typhoeus::Hydra for when you have a lot of requests to make at once.

Public Class Methods

new(api_key) click to toggle source

An API key is required. Free at www.metascan-online.com

# File lib/metascan/client.rb, line 9
def initialize(api_key)
  @api_key = api_key
  @hydra   = Typhoeus::Hydra.hydra
end

Public Instance Methods

api_key() click to toggle source
# File lib/metascan/client.rb, line 14
def api_key
  @api_key
end
hydra() click to toggle source

A Typhoeus Hydra manages parallel HTTP requests.

# File lib/metascan/client.rb, line 19
def hydra
  if !@hydra
    @hydra = Typhoeus::Hydra.hydra
  end
  @hydra
end
scan_batch(filenames, archivepwds: nil) click to toggle source

Scan a batch of files by processing the requests in parallel with Typhoeus::Hydra. Returns a Metascan::Batch object, which can iterate over the set of finished scans. Sample usage:

scanner = Metascan::Client.new(MY_API_KEY)
filenames = ["/etc/passwd", "/dev/sda0", "/dev/random.tgz"] # don't try this
scanner.scan_batch(filenames, archivepwds: { "/dev/random.tgz" => "hunter2" })
=> <Metascan::Batch ...>
# File lib/metascan/client.rb, line 50
def scan_batch(filenames, archivepwds: nil)
  scans = Metascan::Batch.new(self.hydra)
  filenames.each do |f|
    scan = Metascan::Scan.new(f, self)
    scans.add(scan)
  end
  scans.run
  scans
end
scan_file(filename, archivepwd: nil) click to toggle source

Returns a Scan object Sample usage:

scanner = Metascan::Client.new(MY_API_KEY) 
filename = "/etc/unwise-backups/passwd.rar" # FULLY QUALIFIED
scanner.scan_file(filename, archivepwd: "the eagle has left the nest")
=> <Metascan::Scan ... >

www.metascan-online.com/en/public-api

# File lib/metascan/client.rb, line 35
def scan_file(filename, archivepwd: nil)
  scan = Metascan::Scan.new(filename, self)
  scan.run
  scan
end