class ThreeScaleToolbox::Entities::BackendMethod
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_method.rb, line 10 def create(backend:, attrs:) method = backend.remote.create_backend_method(backend.id, backend.hits.id, Helper.filter_params(VALID_PARAMS, attrs)) if (errors = method['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend Method has not been created', errors) end new(id: method.fetch('id'), backend: backend, attrs: method) end
find(backend:, ref:)
click to toggle source
ref can be system_name
or method_id
# File lib/3scale_toolbox/entities/backend_method.rb, line 22 def find(backend:, ref:) new(id: ref, backend: backend).tap(&:attrs) rescue ThreeScaleToolbox::InvalidIdError, ThreeScale::API::HttpClient::NotFoundError find_by_system_name(backend: backend, system_name: ref) end
find_by_system_name(backend:, system_name:)
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 28 def find_by_system_name(backend:, system_name:) backend.methods.find { |m| m.system_name == system_name } end
new(id:, backend:, attrs: nil)
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 35 def initialize(id:, backend:, attrs: nil) @id = id.to_i @backend = backend @remote = backend.remote @attrs = process_attrs(attrs) end
Public Instance Methods
attrs()
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 42 def attrs @attrs ||= process_attrs(method_attrs) end
delete()
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 70 def delete remote.delete_backend_method backend.id, hits_id, id end
description()
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 54 def description attrs['description'] end
friendly_name()
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 50 def friendly_name attrs['friendly_name'] end
system_name()
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 46 def system_name attrs['system_name'] end
update(m_attrs)
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 58 def update(m_attrs) new_attrs = remote.update_backend_method(backend.id, hits_id, id, Helper.filter_params(VALID_PARAMS, m_attrs)) if (errors = new_attrs['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend Method has not been updated', errors) end # update current attrs @attrs = process_attrs(new_attrs) end
Private Instance Methods
hits_id()
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 76 def hits_id backend.hits.id end
method_attrs()
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 87 def method_attrs raise ThreeScaleToolbox::InvalidIdError if id.zero? method = remote.backend_method backend.id, hits_id, id if (errors = method['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Backend method not read', errors) end method end
process_attrs(metric_attrs)
click to toggle source
# File lib/3scale_toolbox/entities/backend_method.rb, line 80 def process_attrs(metric_attrs) return if metric_attrs.nil? # system_name: my_metric_02.45498 -> system_name: my_metric_02 metric_attrs.merge('system_name' => metric_attrs.fetch('system_name', '').partition('.').first) end