Class: Ham::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ham/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scan!Object

Iterates over each host, applying the re-defined scan method to it.

Returns nil



47
48
49
50
51
52
53
54
55
56
# File 'lib/ham/base.rb', line 47

def self.scan!
  scanner = new
  threads = []
  scanner.each_host do |host|
    threads << Thread.new(host) do |host|
      scanner.send(:scan, host)
    end
  end
  threads.join
end

Instance Method Details

#each_host(&blk) ⇒ Object

Returns a block that yields user defined-hosts



10
11
12
# File 'lib/ham/base.rb', line 10

def each_host(&blk)
  Ham::Hosts.parse(hosts, &blk)
end

#get(uri, options = {}) ⇒ Object

Make a HTTP GET request to your host.

Returns a HTTParty object



40
41
42
# File 'lib/ham/base.rb', line 40

def get(uri, options = {})
  HTTParty.get(uri, options.merge(headers: headers, body: params))
end

#headersObject

Returns an empty hash of default headers



15
16
17
# File 'lib/ham/base.rb', line 15

def headers
  {}
end

#hostsObject

Returns an empty array of default hosts



5
6
7
# File 'lib/ham/base.rb', line 5

def hosts
  []
end

#paramsObject

Returns an empty hash of default parameters



20
21
22
# File 'lib/ham/base.rb', line 20

def params
  {}
end

#post(uri, options = {}) ⇒ Object

Make a HTTP POST request to your host.

Returns a HTTParty object



33
34
35
# File 'lib/ham/base.rb', line 33

def post(uri, options = {})
  HTTParty.post(uri, options.merge(headers: headers, body: params))
end

#scanObject

Raises a NotImplementedError. You should inherit this class and implement your own #scan method.

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/ham/base.rb', line 26

def scan
  raise NotImplementedError, 'Please override #scan with your own method'
end