Sha256: a9793ea7a6a4dccfb69ea99a1f0d5b2a0a143a75ad60f1a2e154efc576c31979

Contents?: true

Size: 1.38 KB

Versions: 22

Compression:

Stored size: 1.38 KB

Contents

module ThreeScaleToolbox
  module Commands
    module PlansCommand
      module Import
        class ImportPlanFeaturesStep
          include Step
          ##
          # Writes Plan features
          def call
            missing_features.each do |feature|
              create_plan_feature(feature)
              puts "Created plan feature: #{feature}"
            end
          end

          private

          def missing_features
            ThreeScaleToolbox::Helper.array_difference(resource_features, plan.features) do |a, b|
              ThreeScaleToolbox::Helper.compare_hashes(a, b, ['system_name'])
            end
          end

          def create_plan_feature(feature_attrs)
            feature = find_feature_by_system_name(feature_attrs['system_name']) || create_service_feature(feature_attrs)

            plan.create_feature(feature['id']).tap do |resp|
              if (errors = resp['errors'])
                raise ThreeScaleToolbox::Error, "Plan feature has not been created. #{errors}"
              end
            end
          end

          def create_service_feature(feature_attrs)
            service.create_feature(feature_attrs).tap do |resp|
              if (errors = resp['errors'])
                raise ThreeScaleToolbox::Error, "Service feature has not been created. #{errors}"
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

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