Class: TerminalShop::Resources::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal_shop/resources/subscription.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Subscription

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

Parameters:



136
137
138
# File 'lib/terminal_shop/resources/subscription.rb', line 136

def initialize(client:)
  @client = client
end

Instance Method Details

#create(id: , address_id: , card_id: , created: , price: , product_variant_id: , quantity: , next_: nil, schedule: nil, request_options: {}) ⇒ TerminalShop::Models::SubscriptionCreateResponse

Some parameter documentations has been truncated, see Models::SubscriptionCreateParams for more details.

Create a subscription for the current user.

Parameters:

  • id (String)

    Unique object identifier.

  • address_id (String)

    ID of the shipping address used for the subscription.

  • card_id (String)

    ID of the card used for the subscription.

  • created (String)

    Date the subscription was created.

  • price (Integer)

    Price of the subscription in cents (USD).

  • product_variant_id (String)

    ID of the product variant being subscribed to.

  • quantity (Integer)

    Quantity of the subscription.

  • next_ (String)

    Next shipment and billing date for the subscription.

  • schedule (TerminalShop::Models::SubscriptionAPI::Schedule::Fixed, TerminalShop::Models::SubscriptionAPI::Schedule::Weekly)

    Schedule of the subscription.

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

Returns:

See Also:



36
37
38
39
40
41
42
43
44
45
# File 'lib/terminal_shop/resources/subscription.rb', line 36

def create(params)
  parsed, options = TerminalShop::SubscriptionCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "subscription",
    body: parsed,
    model: TerminalShop::Models::SubscriptionCreateResponse,
    options: options
  )
end

#delete(id, request_options: {}) ⇒ TerminalShop::Models::SubscriptionDeleteResponse

Cancel a subscription for the current user.

Parameters:

Returns:

See Also:



104
105
106
107
108
109
110
111
# File 'lib/terminal_shop/resources/subscription.rb', line 104

def delete(id, params = {})
  @client.request(
    method: :delete,
    path: ["subscription/%1$s", id],
    model: TerminalShop::Models::SubscriptionDeleteResponse,
    options: params[:request_options]
  )
end

#get(id, request_options: {}) ⇒ TerminalShop::Models::SubscriptionGetResponse

Get the subscription with the given ID.

Parameters:

Returns:

See Also:



124
125
126
127
128
129
130
131
# File 'lib/terminal_shop/resources/subscription.rb', line 124

def get(id, params = {})
  @client.request(
    method: :get,
    path: ["subscription/%1$s", id],
    model: TerminalShop::Models::SubscriptionGetResponse,
    options: params[:request_options]
  )
end

#list(request_options: {}) ⇒ TerminalShop::Models::SubscriptionListResponse

List the subscriptions associated with the current user.

Parameters:

Returns:

See Also:



84
85
86
87
88
89
90
91
# File 'lib/terminal_shop/resources/subscription.rb', line 84

def list(params = {})
  @client.request(
    method: :get,
    path: "subscription",
    model: TerminalShop::Models::SubscriptionListResponse,
    options: params[:request_options]
  )
end

#update(id, address_id: nil, card_id: nil, schedule: nil, request_options: {}) ⇒ TerminalShop::Models::SubscriptionUpdateResponse

Update card, address, or interval for an existing subscription.

Parameters:

Returns:

See Also:



64
65
66
67
68
69
70
71
72
73
# File 'lib/terminal_shop/resources/subscription.rb', line 64

def update(id, params = {})
  parsed, options = TerminalShop::SubscriptionUpdateParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["subscription/%1$s", id],
    body: parsed,
    model: TerminalShop::Models::SubscriptionUpdateResponse,
    options: options
  )
end