Class: ThreeScaleToolbox::Commands::PlansCommand::Import::CreateOrUpdateAppPlanStep

Inherits:
Object
  • Object
show all
Includes:
Step
Defined in:
lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb

Instance Attribute Summary

Attributes included from Step

#context

Instance Method Summary collapse

Methods included from Step

#artifacts_resource, #file, #find_feature_by_system_name, #initialize, #plan, #plan_system_name, #resource_backend_methods, #resource_backend_metrics, #resource_features, #resource_limits, #resource_methods, #resource_metrics, #resource_plan, #resource_pricing_rules, #resource_product_methods, #resource_product_metrics, #result, #service, #service_features, #service_system_name, #threescale_client

Instance Method Details

#callObject

Creates if it does not exist, updates otherwise



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/3scale_toolbox/commands/plans_command/import/create_or_update_app_plan_step.rb', line 9

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