Class: Ham::Base
- Inherits:
-
Object
- Object
- Ham::Base
- Defined in:
- lib/ham/base.rb
Class Method Summary collapse
-
.scan! ⇒ Object
Iterates over each host, applying the re-defined
scanmethod to it.
Instance Method Summary collapse
-
#each_host(&blk) ⇒ Object
Returns a block that yields user defined-hosts.
-
#get(uri, options = {}) ⇒ Object
Make a HTTP GET request to your host.
-
#headers ⇒ Object
Returns an empty hash of default headers.
-
#hosts ⇒ Object
Returns an empty array of default hosts.
-
#params ⇒ Object
Returns an empty hash of default parameters.
-
#post(uri, options = {}) ⇒ Object
Make a HTTP POST request to your host.
-
#scan ⇒ Object
Raises a NotImplementedError.
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, = {}) HTTParty.get(uri, .merge(headers: headers, body: params)) end |
#headers ⇒ Object
Returns an empty hash of default headers
15 16 17 |
# File 'lib/ham/base.rb', line 15 def headers {} end |
#hosts ⇒ Object
Returns an empty array of default hosts
5 6 7 |
# File 'lib/ham/base.rb', line 5 def hosts [] end |
#params ⇒ Object
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, = {}) HTTParty.post(uri, .merge(headers: headers, body: params)) end |
#scan ⇒ Object
Raises a NotImplementedError. You should inherit this class and implement your own #scan method.
26 27 28 |
# File 'lib/ham/base.rb', line 26 def scan raise NotImplementedError, 'Please override #scan with your own method' end |