Class: Printful::ProductsResource

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

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Printful::Resource

Instance Method Details

#create(product:, variants:) ⇒ Object



10
11
12
13
14
# File 'lib/printful/resources/products.rb', line 10

def create(product:, variants:)
  attributes = {sync_product: product, sync_variants: variants}
  response = post_request("store/products", body: attributes)
  Product.new(response.body["result"])
end

#delete(id:) ⇒ Object



27
28
29
30
# File 'lib/printful/resources/products.rb', line 27

def delete(id:)
  response = delete_request("store/products/#{id}")
  return true if response.success?
end

#listObject



4
5
6
7
8
# File 'lib/printful/resources/products.rb', line 4

def list
  response = get_request("store/products")
  body = response.body["result"]
  Collection.from_response(body: body, type: Product)
end

#retrieve(id:) ⇒ Object



16
17
18
19
# File 'lib/printful/resources/products.rb', line 16

def retrieve(id:)
  response = get_request("store/products/#{id}")
  Product.new(response.body["result"])
end

#update(id:, product:, variants: nil) ⇒ Object



21
22
23
24
25
# File 'lib/printful/resources/products.rb', line 21

def update(id:, product:, variants: nil)
  attributes = {sync_product: product, sync_variants: variants}
  response = put_request("store/products/#{id}", body: attributes)
  return true if response.success?
end