Class: Billingrails::Resources::Products

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

Overview

Products resource

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Products

Returns a new instance of Products.

Parameters:

  • client (Client)

    The API client



10
11
12
# File 'lib/billingrails/resources/products.rb', line 10

def initialize(client)
  @client = client
end

Instance Method Details

#archive(id) ⇒ Hash

Archive a product

Archives a product.

Parameters:

  • id (String)

    Resource ID

Returns:

  • (Hash)

    Response data



66
67
68
69
# File 'lib/billingrails/resources/products.rb', line 66

def archive(id)
  path = "/products/#{id}/archive"
  @client.request(:post, path)
end

#create(data) ⇒ Hash

Create a product

Creates a product.

Parameters:

  • data (Hash)

    Request body

Returns:

  • (Hash)

    Response data



31
32
33
34
# File 'lib/billingrails/resources/products.rb', line 31

def create(data)
  path = "/products"
  @client.request(:post, path, body: data)
end

#list(params: nil) ⇒ Hash

List products

Retrieves a list of products.

Parameters:

  • params (Hash, nil) (defaults to: nil)

    Query parameters

Returns:

  • (Hash)

    Response data



20
21
22
23
# File 'lib/billingrails/resources/products.rb', line 20

def list(params: nil)
  path = "/products"
  @client.request(:get, path, params: params)
end

#retrieve(id, params: nil) ⇒ Hash

Retrieve a product

Retrieves product by ID.

Parameters:

  • id (String)

    Resource ID

  • params (Hash, nil) (defaults to: nil)

    Query parameters

Returns:

  • (Hash)

    Response data



43
44
45
46
# File 'lib/billingrails/resources/products.rb', line 43

def retrieve(id, params: nil)
  path = "/products/#{id}"
  @client.request(:get, path, params: params)
end

#unarchive(id) ⇒ Hash

Unarchive a product

Restores an archived product.

Parameters:

  • id (String)

    Resource ID

Returns:

  • (Hash)

    Response data



77
78
79
80
# File 'lib/billingrails/resources/products.rb', line 77

def unarchive(id)
  path = "/products/#{id}/unarchive"
  @client.request(:post, path)
end

#update(id, data) ⇒ Hash

Update a product

Updates a product.

Parameters:

  • id (String)

    Resource ID

  • data (Hash)

    Request body

Returns:

  • (Hash)

    Response data



55
56
57
58
# File 'lib/billingrails/resources/products.rb', line 55

def update(id, data)
  path = "/products/#{id}"
  @client.request(:put, path, body: data)
end