Class: GeneratorLabs::RBLProfiles
- Inherits:
-
Object
- Object
- GeneratorLabs::RBLProfiles
- Defined in:
- lib/generatorlabs/rbl.rb
Overview
RBL profile management
Instance Method Summary collapse
-
#create(params) ⇒ Hash
Create a new monitoring profile.
-
#delete(id) ⇒ Hash
Delete a monitoring profile.
-
#get(*ids) ⇒ Hash
Get profiles (all, by ID, or by array of IDs).
-
#get_all(params = {}) ⇒ Array
Get all profiles with automatic pagination.
-
#initialize(handler) ⇒ RBLProfiles
constructor
A new instance of RBLProfiles.
-
#update(id, params) ⇒ Hash
Update a monitoring profile.
Constructor Details
#initialize(handler) ⇒ RBLProfiles
Returns a new instance of RBLProfiles.
154 155 156 |
# File 'lib/generatorlabs/rbl.rb', line 154 def initialize(handler) @handler = handler end |
Instance Method Details
#create(params) ⇒ Hash
Create a new monitoring profile
198 199 200 |
# File 'lib/generatorlabs/rbl.rb', line 198 def create(params) @handler.post('rbl/profiles', params) end |
#delete(id) ⇒ Hash
Delete a monitoring profile
213 214 215 |
# File 'lib/generatorlabs/rbl.rb', line 213 def delete(id) @handler.delete("rbl/profiles/#{id}") end |
#get(*ids) ⇒ Hash
Get profiles (all, by ID, or by array of IDs)
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/generatorlabs/rbl.rb', line 161 def get(*ids) return @handler.get('rbl/profiles') if ids.empty? # Check if first argument is a hash (parameters) return @handler.get('rbl/profiles', ids.first) if ids.first.is_a?(Hash) return @handler.get("rbl/profiles/#{ids.first}") if ids.length == 1 @handler.get('rbl/profiles', { ids: ids.join(',') }) end |
#get_all(params = {}) ⇒ Array
Get all profiles with automatic pagination
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/generatorlabs/rbl.rb', line 175 def get_all(params = {}) all_items = [] page = 1 params = params.dup loop do params[:page] = page response = get(params) profiles = response['profiles'] || [] all_items.concat(profiles) break unless page < (response['total_pages'] || 1) && !profiles.empty? page += 1 end all_items end |
#update(id, params) ⇒ Hash
Update a monitoring profile
206 207 208 |
# File 'lib/generatorlabs/rbl.rb', line 206 def update(id, params) @handler.put("rbl/profiles/#{id}", params) end |