lib/3scale_toolbox/entities/metric.rb in 3scale_toolbox-0.19.2 vs lib/3scale_toolbox/entities/metric.rb in 3scale_toolbox-0.19.3

- old
+ new

@@ -1,10 +1,12 @@ module ThreeScaleToolbox module Entities class Metric include CRD::MetricSerializer + METRIC_BLACKLIST = %w[id links created_at updated_at].freeze + class << self def create(service:, attrs:) metric = service.remote.create_metric service.id, attrs if (errors = metric['errors']) raise ThreeScaleToolbox::ThreeScaleApiError.new('Metric has not been created', errors) @@ -88,9 +90,19 @@ new_attrs end def delete remote.delete_metric service.id, id + end + + # enriched_key returns a metric key that will be unique for all + # metrics from products and backends + def enriched_key + "product.#{service.id}.#{id}" + end + + def to_hash + attrs.reject { |key, _| METRIC_BLACKLIST.include? key } end private def metric_attrs