class ThreeScaleToolbox::Entities::BackendMappingRule

Constants

VALID_PARAMS

Attributes

backend[R]
id[R]
remote[R]

Public Class Methods

create(backend:, attrs:) click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 10
def create(backend:, attrs:)
  mapping_rule = backend.remote.create_backend_mapping_rule(
    backend.id,
    Helper.filter_params(VALID_PARAMS, attrs)
  )
  if (errors = mapping_rule['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend mapping rule has not been created',
                                                    errors)
  end

  new(id: mapping_rule.fetch('id'), backend: backend, attrs: mapping_rule)
end
new(id:, backend:, attrs: nil) click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 26
def initialize(id:, backend:, attrs: nil)
  @id = id.to_i
  @backend = backend
  @remote = backend.remote
  @attrs = attrs
end

Public Instance Methods

attrs() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 33
def attrs
  @attrs ||= mapping_rule_attrs
end
delete() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 84
def delete
  remote.delete_backend_mapping_rule backend.id, id
end
delta() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 45
def delta
  attrs['delta']
end
http_method() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 37
def http_method
  attrs['http_method']
end
last() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 49
def last
  attrs['last']
end
metric_id() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 53
def metric_id
  attrs['metric_id']
end
pattern() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 41
def pattern
  attrs['pattern']
end
update(mr_attrs) click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 69
def update(mr_attrs)
  new_attrs = remote.update_backend_mapping_rule(
    backend.id, id,
    Helper.filter_params(VALID_PARAMS, mr_attrs)
  )
  if (errors = new_attrs['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend mapping rule has not been updated', errors)
  end

  # update current attrs
  @attrs = new_attrs

  new_attrs
end

Private Instance Methods

mapping_rule_attrs() click to toggle source
# File lib/3scale_toolbox/entities/backend_mapping_rule.rb, line 90
def mapping_rule_attrs
  raise ThreeScaleToolbox::InvalidIdError if id.zero?

  mapping_rule = remote.backend_mapping_rule backend.id, id
  if (errors = mapping_rule['errors'])
    raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend mapping rule not read', errors)
  end

  mapping_rule
end