Class: GeneratorLabs::RBLProfiles

Inherits:
Object
  • Object
show all
Defined in:
lib/generatorlabs/rbl.rb

Overview

RBL profile management

Instance Method Summary collapse

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

Parameters:

  • params (Hash)

    Profile parameters

Returns:

  • (Hash)

    Created profile data



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

Parameters:

  • id (String, Integer)

    Profile ID

Returns:

  • (Hash)

    Deletion confirmation



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)

Parameters:

  • ids (nil, String, Integer, Hash, Array)

    Optional ID(s) or parameters

Returns:

  • (Hash)

    Profile data



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

Parameters:

  • params (Hash) (defaults to: {})

    Optional parameters (e.g., page_size)

Returns:

  • (Array)

    All profiles across all pages



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

Parameters:

  • id (String, Integer)

    Profile ID

  • params (Hash)

    Updated parameters

Returns:

  • (Hash)

    Updated profile data



206
207
208
# File 'lib/generatorlabs/rbl.rb', line 206

def update(id, params)
  @handler.put("rbl/profiles/#{id}", params)
end