Sha256: 308327a4e1421c4d0ba1034b821d99a19dbf05a61e0fc96bc7de65666a65d7aa

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ImportCommand
      module OpenAPI
        class CreateMethodsStep
          include Step

          def call
            hits_metric_id = service.hits['id']
            operations.each do |op|
              res = service.create_method(hits_metric_id, op.method)
              metric_id = res['id']
              # if method system_name exists, ignore error and get metric_id
              # Make operation indempotent
              if (errors = res['errors'])
                raise ThreeScaleToolbox::Error, "Metohd has not been saved. #{errors}" \
                  unless ThreeScaleToolbox::Helper.system_name_already_taken_error? errors

                metric_id = method_id_by_system_name[op.method['system_name']]
              end

              op.set(:metric_id, metric_id)
            end
          end

          private

          def method_id_by_system_name
            @method_id_by_system_name ||= service.methods.each_with_object({}) do |method, acc|
              acc[method['system_name']] = method['id']
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
3scale_toolbox-0.9.0 lib/3scale_toolbox/commands/import_command/openapi/create_method_step.rb