Class: ThreeScaleToolbox::Entities::BackendMappingRule
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Entities::BackendMappingRule
- Defined in:
- lib/3scale_toolbox/entities/backend_mapping_rule.rb
Constant Summary collapse
- VALID_PARAMS =
%w[metric_id pattern http_method delta position last].freeze
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
Instance Method Summary collapse
- #attrs ⇒ Object
- #delete ⇒ Object
-
#initialize(id:, backend:, attrs: nil) ⇒ BackendMappingRule
constructor
A new instance of BackendMappingRule.
- #metric_id ⇒ Object
- #metric_id=(metric_id) ⇒ Object
- #update(mr_attrs) ⇒ Object
Constructor Details
#initialize(id:, backend:, attrs: nil) ⇒ BackendMappingRule
Returns a new instance of BackendMappingRule.
24 25 26 27 28 29 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 24 def initialize(id:, backend:, attrs: nil) @id = id.to_i @backend = backend @remote = backend.remote @attrs = attrs end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
22 23 24 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 22 def backend @backend end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 22 def id @id end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
22 23 24 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 22 def remote @remote end |
Class Method Details
.create(backend:, attrs:) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 8 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 |
Instance Method Details
#attrs ⇒ Object
31 32 33 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 31 def attrs @attrs ||= mapping_rule_attrs end |
#delete ⇒ Object
58 59 60 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 58 def delete remote.delete_backend_mapping_rule backend.id, id end |
#metric_id ⇒ Object
35 36 37 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 35 def metric_id @attrs['metric_id'] end |
#metric_id=(metric_id) ⇒ Object
39 40 41 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 39 def metric_id=(metric_id) @attrs['metric_id'] = metric_id end |
#update(mr_attrs) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/3scale_toolbox/entities/backend_mapping_rule.rb', line 43 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 |