Class: GeneratorLabs::RBLHosts
- Inherits:
-
Object
- Object
- GeneratorLabs::RBLHosts
- Defined in:
- lib/generatorlabs/rbl.rb
Overview
RBL host management
Instance Method Summary collapse
-
#create(params) ⇒ Hash
Create a new monitored host.
-
#delete(id) ⇒ Hash
Delete a monitored host.
-
#get(*ids) ⇒ Hash
Get hosts (all, by ID, or by array of IDs).
-
#get_all(params = {}) ⇒ Array
Get all hosts with automatic pagination.
-
#initialize(handler) ⇒ RBLHosts
constructor
A new instance of RBLHosts.
-
#pause(id) ⇒ Hash
Pause monitoring for a host.
-
#resume(id) ⇒ Hash
Resume monitoring for a host.
-
#update(id, params) ⇒ Hash
Update a monitored host.
Constructor Details
#initialize(handler) ⇒ RBLHosts
Returns a new instance of RBLHosts.
74 75 76 |
# File 'lib/generatorlabs/rbl.rb', line 74 def initialize(handler) @handler = handler end |
Instance Method Details
#create(params) ⇒ Hash
Create a new monitored host
118 119 120 |
# File 'lib/generatorlabs/rbl.rb', line 118 def create(params) @handler.post('rbl/hosts', params) end |
#delete(id) ⇒ Hash
Delete a monitored host
133 134 135 |
# File 'lib/generatorlabs/rbl.rb', line 133 def delete(id) @handler.delete("rbl/hosts/#{id}") end |
#get(*ids) ⇒ Hash
Get hosts (all, by ID, or by array of IDs)
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/generatorlabs/rbl.rb', line 81 def get(*ids) return @handler.get('rbl/hosts') if ids.empty? # Check if first argument is a hash (parameters) return @handler.get('rbl/hosts', ids.first) if ids.first.is_a?(Hash) return @handler.get("rbl/hosts/#{ids.first}") if ids.length == 1 @handler.get('rbl/hosts', { ids: ids.join(',') }) end |
#get_all(params = {}) ⇒ Array
Get all hosts with automatic pagination
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/generatorlabs/rbl.rb', line 95 def get_all(params = {}) all_items = [] page = 1 params = params.dup loop do params[:page] = page response = get(params) hosts = response['hosts'] || [] all_items.concat(hosts) break unless page < (response['total_pages'] || 1) && !hosts.empty? page += 1 end all_items end |
#pause(id) ⇒ Hash
Pause monitoring for a host
140 141 142 |
# File 'lib/generatorlabs/rbl.rb', line 140 def pause(id) @handler.post("rbl/hosts/#{id}/pause") end |
#resume(id) ⇒ Hash
Resume monitoring for a host
147 148 149 |
# File 'lib/generatorlabs/rbl.rb', line 147 def resume(id) @handler.post("rbl/hosts/#{id}/resume") end |
#update(id, params) ⇒ Hash
Update a monitored host
126 127 128 |
# File 'lib/generatorlabs/rbl.rb', line 126 def update(id, params) @handler.put("rbl/hosts/#{id}", params) end |