Class: Stigg::Resources::V1::Products

Inherits:
Object
  • Object
show all
Defined in:
lib/stigg/resources/v1/products.rb

Overview

Operations related to products

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Products

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 Products.

Parameters:



179
180
181
# File 'lib/stigg/resources/v1/products.rb', line 179

def initialize(client:)
  @client = client
end

Instance Method Details

#archive_product(id, request_options: {}) ⇒ Stigg::Models::V1::Product

Archives a product, preventing new subscriptions. All plans and addons are archived.

Parameters:

  • id (String)

    The unique identifier of the entity

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

Returns:

See Also:



20
21
22
23
24
25
26
27
# File 'lib/stigg/resources/v1/products.rb', line 20

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

#create_product(id:, display_name:, description: nil, metadata: nil, multiple_subscriptions: nil, request_options: {}) ⇒ Stigg::Models::V1::Product

Creates a new product.

Parameters:

  • id (String)

    The unique identifier for the entity

  • display_name (String)

    Display name of the product

  • description (String, nil)

    Description of the product

  • metadata (Hash{Symbol=>String}, nil)

    Additional metadata for the product

  • multiple_subscriptions (Boolean)

    Indicates if multiple subscriptions to this product are allowed

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

Returns:

See Also:



48
49
50
51
52
53
54
55
56
57
# File 'lib/stigg/resources/v1/products.rb', line 48

def create_product(params)
  parsed, options = Stigg::V1::ProductCreateProductParams.dump_request(params)
  @client.request(
    method: :post,
    path: "api/v1/products",
    body: parsed,
    model: Stigg::V1::Product,
    options: options
  )
end

#duplicate_product(id, target_id:, description: nil, display_name: nil, request_options: {}) ⇒ Stigg::Models::V1::Product

Duplicates an existing product, including its plans, addons, and configuration.

Parameters:

  • id (String)

    The unique identifier of the entity

  • target_id (String)

    The unique identifier for the entity

  • description (String, nil)

    Description of the product

  • display_name (String)

    Display name of the product

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

Returns:

See Also:



76
77
78
79
80
81
82
83
84
85
# File 'lib/stigg/resources/v1/products.rb', line 76

def duplicate_product(id, params)
  parsed, options = Stigg::V1::ProductDuplicateProductParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/v1/products/%1$s/duplicate", id],
    body: parsed,
    model: Stigg::V1::Product,
    options: options
  )
end

#list_products(id: nil, after: nil, before: nil, created_at: nil, limit: nil, status: nil, request_options: {}) ⇒ Stigg::Internal::MyCursorIDPage<Stigg::Models::V1::ProductListProductsResponse>

Retrieves a paginated list of products in the environment.

Parameters:

  • id (String)

    Filter by entity ID

  • after (String)

    Return items that come after this cursor

  • before (String)

    Return items that come before this cursor

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

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

  • limit (Integer)

    Maximum number of items to return

  • status (String)

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

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

Returns:

See Also:



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/stigg/resources/v1/products.rb', line 108

def list_products(params = {})
  parsed, options = Stigg::V1::ProductListProductsParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "api/v1/products",
    query: query.transform_keys(created_at: "createdAt"),
    page: Stigg::Internal::MyCursorIDPage,
    model: Stigg::Models::V1::ProductListProductsResponse,
    options: options
  )
end

#unarchive_product(id, request_options: {}) ⇒ Stigg::Models::V1::Product

Restores an archived product, allowing new subscriptions to be created.

Parameters:

  • id (String)

    The unique identifier of the entity

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

Returns:

See Also:



132
133
134
135
136
137
138
139
# File 'lib/stigg/resources/v1/products.rb', line 132

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

#update_product(id, description: nil, display_name: nil, metadata: nil, multiple_subscriptions: nil, product_settings: nil, usage_reset_cutoff_rule: nil, request_options: {}) ⇒ Stigg::Models::V1::Product

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

Parameters:

Returns:

See Also:



165
166
167
168
169
170
171
172
173
174
# File 'lib/stigg/resources/v1/products.rb', line 165

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