class ThreeScaleToolbox::Entities::MappingRule
Constants
- VALID_PARAMS
Attributes
id[R]
remote[R]
service[R]
Public Class Methods
create(service:, attrs:)
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 10 def create(service:, attrs:) mapping_rule = service.remote.create_mapping_rule( service.id, Helper.filter_params(VALID_PARAMS, attrs) ) if (errors = mapping_rule['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('mapping rule has not been created', errors) end new(id: mapping_rule.fetch('id'), service: service, attrs: mapping_rule) end
new(id:, service:, attrs: nil)
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 26 def initialize(id:, service:, attrs: nil) @id = id.to_i @service = service @remote = service.remote @attrs = attrs end
Public Instance Methods
attrs()
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 33 def attrs @attrs ||= mapping_rule_attrs end
delete()
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 72 def delete remote.delete_mapping_rule service.id, id end
delta()
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 45 def delta attrs['delta'] end
http_method()
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 37 def http_method attrs['http_method'] end
last()
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 49 def last attrs['last'] end
metric_id()
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 53 def metric_id attrs['metric_id'] end
pattern()
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 41 def pattern attrs['pattern'] end
update(mr_attrs)
click to toggle source
# File lib/3scale_toolbox/entities/mapping_rule.rb, line 57 def update(mr_attrs) new_attrs = remote.update_mapping_rule( service.id, id, Helper.filter_params(VALID_PARAMS, mr_attrs) ) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Service 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/mapping_rule.rb, line 78 def mapping_rule_attrs raise ThreeScaleToolbox::InvalidIdError if id.zero? mapping_rule = remote.show_mapping_rule service.id, id if (errors = mapping_rule['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Service mapping rule not read', errors) end mapping_rule end