Sha256: bc926fecd55b78f8a5123a51d908e18c65ecabda2bcb18743271c5df07b7623c

Contents?: true

Size: 1.21 KB

Versions: 19

Compression:

Stored size: 1.21 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Import
        class CreateOrUpdateAppPlanStep
          include Step
          ##
          # Creates if it does not exist, updates otherwise
          def call
            plan_obj = Entities::ApplicationPlan.find(service: service, ref: plan_system_name)
            if plan_obj.nil?
              plan_obj = Entities::ApplicationPlan.create(service: service,
                                                          plan_attrs: create_plan_attrs)
              puts "Application plan created: #{plan_obj.id}"
            else
              res = plan_obj.update(update_plan_attrs)
              if (errors = res['errors'])
                raise ThreeScaleToolbox::Error, "Could not update application plan #{plan_system_name}. Errors: #{errors}"
              end

              puts "Application plan updated: #{plan_obj.id}"
            end
          end

          private

          def create_plan_attrs
            resource_plan.merge('system_name' => plan_system_name)
          end

          def update_plan_attrs
            resource_plan.reject { |key, _| %w[system_name].include? key }
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb