Class: GeneratorLabs::RBLSources
- Inherits:
-
Object
- Object
- GeneratorLabs::RBLSources
- Defined in:
- lib/generatorlabs/rbl.rb
Overview
RBL source management
Instance Method Summary collapse
-
#create(params) ⇒ Hash
Create a new RBL source.
-
#delete(id) ⇒ Hash
Delete an RBL source.
-
#get(*ids) ⇒ Hash
Get sources (all, by ID, or by array of IDs).
-
#get_all(params = {}) ⇒ Array
Get all sources with automatic pagination.
-
#initialize(handler) ⇒ RBLSources
constructor
A new instance of RBLSources.
-
#pause(id) ⇒ Hash
Pause an RBL source.
-
#resume(id) ⇒ Hash
Resume an RBL source.
-
#update(id, params) ⇒ Hash
Update an RBL source.
Constructor Details
#initialize(handler) ⇒ RBLSources
Returns a new instance of RBLSources.
220 221 222 |
# File 'lib/generatorlabs/rbl.rb', line 220 def initialize(handler) @handler = handler end |
Instance Method Details
#create(params) ⇒ Hash
Create a new RBL source
264 265 266 |
# File 'lib/generatorlabs/rbl.rb', line 264 def create(params) @handler.post('rbl/sources', params) end |
#delete(id) ⇒ Hash
Delete an RBL source
279 280 281 |
# File 'lib/generatorlabs/rbl.rb', line 279 def delete(id) @handler.delete("rbl/sources/#{id}") end |
#get(*ids) ⇒ Hash
Get sources (all, by ID, or by array of IDs)
227 228 229 230 231 232 233 234 235 236 |
# File 'lib/generatorlabs/rbl.rb', line 227 def get(*ids) return @handler.get('rbl/sources') if ids.empty? # Check if first argument is a hash (parameters) return @handler.get('rbl/sources', ids.first) if ids.first.is_a?(Hash) return @handler.get("rbl/sources/#{ids.first}") if ids.length == 1 @handler.get('rbl/sources', { ids: ids.join(',') }) end |
#get_all(params = {}) ⇒ Array
Get all sources with automatic pagination
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/generatorlabs/rbl.rb', line 241 def get_all(params = {}) all_items = [] page = 1 params = params.dup loop do params[:page] = page response = get(params) sources = response['sources'] || [] all_items.concat(sources) break unless page < (response['total_pages'] || 1) && !sources.empty? page += 1 end all_items end |
#pause(id) ⇒ Hash
Pause an RBL source
286 287 288 |
# File 'lib/generatorlabs/rbl.rb', line 286 def pause(id) @handler.post("rbl/sources/#{id}/pause") end |
#resume(id) ⇒ Hash
Resume an RBL source
293 294 295 |
# File 'lib/generatorlabs/rbl.rb', line 293 def resume(id) @handler.post("rbl/sources/#{id}/resume") end |
#update(id, params) ⇒ Hash
Update an RBL source
272 273 274 |
# File 'lib/generatorlabs/rbl.rb', line 272 def update(id, params) @handler.put("rbl/sources/#{id}", params) end |