class ThreeScaleToolbox::Entities::Limit

Attributes

attrs[R]
id[R]
metric_id[R]
plan[R]
remote[R]

Public Class Methods

create(plan:, metric_id:, attrs:) click to toggle source
# File lib/3scale_toolbox/entities/limit.rb, line 7
def create(plan:, metric_id:, attrs:)
  resp_attrs = plan.remote.create_application_plan_limit plan.id, metric_id, attrs
  if (errors = resp_attrs['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('Limit has not been created', errors)
  end

  new(id: resp_attrs.fetch('id'), plan: plan, metric_id: metric_id, attrs: resp_attrs)
end
new(id:, plan:, metric_id:, attrs:) click to toggle source
# File lib/3scale_toolbox/entities/limit.rb, line 19
def initialize(id:, plan:, metric_id:, attrs:)
  @id = id.to_i
  @plan = plan
  @remote = plan.remote
  @metric_id = metric_id
  @attrs = attrs
end

Public Instance Methods

delete() click to toggle source
# File lib/3scale_toolbox/entities/limit.rb, line 55
def delete
  remote.delete_application_plan_limit plan.id, metric_id, id
end
period() click to toggle source
# File lib/3scale_toolbox/entities/limit.rb, line 27
def period
  attrs['period']
end
update(new_limit_attrs) click to toggle source
# File lib/3scale_toolbox/entities/limit.rb, line 43
def update(new_limit_attrs)
  new_attrs = remote.update_application_plan_limit(plan.id, metric_id, id, new_limit_attrs)
  if (errors = new_attrs['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('Limit has not been updated', errors)
  end

  # update current attrs
  @attrs = new_attrs

  new_attrs
end
value() click to toggle source
# File lib/3scale_toolbox/entities/limit.rb, line 31
def value
  attrs['value']
end

Private Instance Methods

backend_from_metric() click to toggle source

Used by CRD::Limit Returns the backend hosting the metric

# File lib/3scale_toolbox/entities/limit.rb, line 63
def backend_from_metric
  backend_id = Helper.backend_metric_link_parser(metric_link['href'] || '')
  return if backend_id.nil?

  Backend.new(id: backend_id.to_i, remote: remote)
end