Class: Stigg::Resources::V1::Plans

Inherits:
Object
  • Object
show all
Defined in:
lib/stigg/resources/v1/plans.rb,
lib/stigg/resources/v1/plans/entitlements.rb

Overview

Operations related to plans

Defined Under Namespace

Classes: Entitlements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Plans

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Plans.

Parameters:



232
233
234
235
# File 'lib/stigg/resources/v1/plans.rb', line 232

def initialize(client:)
  @client = client
  @entitlements = Stigg::Resources::V1::Plans::Entitlements.new(client: client)
end

Instance Attribute Details

#entitlementsStigg::Resources::V1::Plans::Entitlements (readonly)



9
10
11
# File 'lib/stigg/resources/v1/plans.rb', line 9

def entitlements
  @entitlements
end

Instance Method Details

#archive(id, request_options: {}) ⇒ Stigg::Models::V1::Plan

Archives a plan, preventing it from being used in new subscriptions.

Parameters:

  • id (String)

    The unique identifier of the entity

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



156
157
158
159
160
161
162
163
# File 'lib/stigg/resources/v1/plans.rb', line 156

def archive(id, params = {})
  @client.request(
    method: :post,
    path: ["api/v1/plans/%1$s/archive", id],
    model: Stigg::V1::Plan,
    options: params[:request_options]
  )
end

#create(id:, display_name:, product_id:, billing_id: nil, default_trial_config: nil, description: nil, metadata: nil, parent_plan_id: nil, pricing_type: nil, status: nil, request_options: {}) ⇒ Stigg::Models::V1::Plan

Creates a new plan in draft status.

Parameters:

  • id (String)

    The unique identifier for the entity

  • display_name (String)

    The display name of the package

  • product_id (String)

    The product ID to associate the plan with

  • billing_id (String, nil)

    The unique identifier for the entity in the billing provider

  • default_trial_config (Stigg::Models::V1::PlanCreateParams::DefaultTrialConfig, nil)

    Default trial configuration for the plan

  • description (String, nil)

    The description of the package

  • metadata (Hash{Symbol=>String})

    Metadata associated with the entity

  • parent_plan_id (String, nil)

    The ID of the parent plan, if applicable

  • pricing_type (Symbol, Stigg::Models::V1::PlanCreateParams::PricingType, nil)

    The pricing type of the package

  • status (Symbol, Stigg::Models::V1::PlanCreateParams::Status)

    The status of the package

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



40
41
42
43
44
45
46
47
48
49
# File 'lib/stigg/resources/v1/plans.rb', line 40

def create(params)
  parsed, options = Stigg::V1::PlanCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "api/v1/plans",
    body: parsed,
    model: Stigg::V1::Plan,
    options: options
  )
end

#create_draft(id, request_options: {}) ⇒ Stigg::Models::V1::Plan

Creates a draft version of an existing plan for modification before publishing.

Parameters:

  • id (String)

    The unique identifier of the entity

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



176
177
178
179
180
181
182
183
# File 'lib/stigg/resources/v1/plans.rb', line 176

def create_draft(id, params = {})
  @client.request(
    method: :post,
    path: ["api/v1/plans/%1$s/draft", id],
    model: Stigg::V1::Plan,
    options: params[:request_options]
  )
end

#list(after: nil, before: nil, created_at: nil, limit: nil, product_id: nil, status: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::PlanListResponse>

Retrieves a paginated list of plans in the environment.

Parameters:

  • after (String)

    Return items that come after this cursor

  • before (String)

    Return items that come before this cursor

  • created_at (Stigg::Models::V1::PlanListParams::CreatedAt)

    Filter by creation date using range operators: gt, gte, lt, lte

  • limit (Integer)

    Maximum number of items to return

  • product_id (String)

    Filter by product ID

  • status (String)

    Filter by status. Supports comma-separated values for multiple statuses

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/stigg/resources/v1/plans.rb', line 132

def list(params = {})
  parsed, options = Stigg::V1::PlanListParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "api/v1/plans",
    query: query.transform_keys(created_at: "createdAt", product_id: "productId"),
    page: Stigg::Internal::MyCursorIDPage,
    model: Stigg::Models::V1::PlanListResponse,
    options: options
  )
end

#publish(id, migration_type:, request_options: {}) ⇒ Stigg::Models::V1::PlanPublishResponse

Publishes a draft plan, making it available for use in subscriptions.

Parameters:

Returns:

See Also:



198
199
200
201
202
203
204
205
206
207
# File 'lib/stigg/resources/v1/plans.rb', line 198

def publish(id, params)
  parsed, options = Stigg::V1::PlanPublishParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/v1/plans/%1$s/publish", id],
    body: parsed,
    model: Stigg::Models::V1::PlanPublishResponse,
    options: options
  )
end

#remove_draft(id, request_options: {}) ⇒ Stigg::Models::V1::PlanRemoveDraftResponse

Removes a draft version of a plan.

Parameters:

  • id (String)

    The unique identifier of the entity

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



220
221
222
223
224
225
226
227
# File 'lib/stigg/resources/v1/plans.rb', line 220

def remove_draft(id, params = {})
  @client.request(
    method: :delete,
    path: ["api/v1/plans/%1$s/draft", id],
    model: Stigg::Models::V1::PlanRemoveDraftResponse,
    options: params[:request_options]
  )
end

#retrieve(id, request_options: {}) ⇒ Stigg::Models::V1::Plan

Retrieves a plan by its unique identifier, including entitlements and pricing details.

Parameters:

  • id (String)

    The unique identifier of the entity

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



63
64
65
66
67
68
69
70
# File 'lib/stigg/resources/v1/plans.rb', line 63

def retrieve(id, params = {})
  @client.request(
    method: :get,
    path: ["api/v1/plans/%1$s", id],
    model: Stigg::V1::Plan,
    options: params[:request_options]
  )
end

#update(id, billing_id: nil, charges: nil, compatible_addon_ids: nil, default_trial_config: nil, description: nil, display_name: nil, metadata: nil, parent_plan_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Plan

Updates an existing plan’s properties such as display name, description, and metadata.

Parameters:

  • id (String)

    The unique identifier of the entity

  • billing_id (String, nil)

    The unique identifier for the entity in the billing provider

  • charges (Stigg::Models::V1::PlanUpdateParams::Charges)

    Pricing configuration to set on the plan draft

  • compatible_addon_ids (Array<String>, nil)
  • default_trial_config (Stigg::Models::V1::PlanUpdateParams::DefaultTrialConfig, nil)

    Default trial configuration for the plan

  • description (String, nil)

    The description of the package

  • display_name (String)

    The display name of the package

  • metadata (Hash{Symbol=>String})

    Metadata associated with the entity

  • parent_plan_id (String, nil)

    The ID of the parent plan, if applicable

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



100
101
102
103
104
105
106
107
108
109
# File 'lib/stigg/resources/v1/plans.rb', line 100

def update(id, params = {})
  parsed, options = Stigg::V1::PlanUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["api/v1/plans/%1$s", id],
    body: parsed,
    model: Stigg::V1::Plan,
    options: options
  )
end