Class: AbacatePay::Clients::ProductClient
- Defined in:
- lib/abacate_pay/clients/product_client.rb
Overview
Client for the product catalogue in the AbacatePay API.
Products are the line items referenced by billings and checkouts.
Constant Summary collapse
- URI =
"products"
Instance Method Summary collapse
- #create(data) ⇒ Resources::Products
- #delete(id) ⇒ Resources::Products
- #get(id) ⇒ Resources::Products
-
#initialize(client = nil) ⇒ ProductClient
constructor
A new instance of ProductClient.
- #list(**params) ⇒ Array<Resources::Products>
Constructor Details
#initialize(client = nil) ⇒ ProductClient
Returns a new instance of ProductClient.
11 12 13 |
# File 'lib/abacate_pay/clients/product_client.rb', line 11 def initialize(client = nil) super(URI, client) end |
Instance Method Details
#create(data) ⇒ Resources::Products
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/abacate_pay/clients/product_client.rb', line 31 def create(data) request_data = { externalId: data.external_id, name: data.name, price: data.price, currency: data.currency || "BRL", description: data.description } request_data[:imageUrl] = data.image_url if data.image_url && !data.image_url.to_s.empty? request_data[:cycle] = data.cycle if data.cycle && !data.cycle.to_s.empty? response = request("POST", "create", json: request_data) Resources::Products.new(response) end |
#delete(id) ⇒ Resources::Products
48 49 50 51 |
# File 'lib/abacate_pay/clients/product_client.rb', line 48 def delete(id) response = request("POST", "delete", json: { id: id }) Resources::Products.new(response) end |
#get(id) ⇒ Resources::Products
24 25 26 27 |
# File 'lib/abacate_pay/clients/product_client.rb', line 24 def get(id) response = request("GET", "get", params: { id: id }) Resources::Products.new(response) end |
#list(**params) ⇒ Array<Resources::Products>
17 18 19 20 |
# File 'lib/abacate_pay/clients/product_client.rb', line 17 def list(**params) response = request("GET", "list", params: params.empty? ? nil : params) Array(response).map { |data| Resources::Products.new(data) } end |