Module: LoyverseApi::Endpoints::Items
- Included in:
- Client
- Defined in:
- lib/loyverse_api/endpoints/items.rb
Instance Method Summary collapse
-
#create_item(item_name:, category_id: nil, variants: [], track_stock: false, sold_by_weight: false, is_composite: false) ⇒ Hash
Create a new item.
-
#delete_item(item_id) ⇒ Hash
Delete an item.
-
#get_item(item_id) ⇒ Hash
Get a specific item by ID.
-
#list_items(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil) ⇒ Hash
List items.
-
#update_item(item_id, item_name: nil, category_id: nil, variants: nil, track_stock: nil) ⇒ Hash
Update an existing item.
Instance Method Details
#create_item(item_name:, category_id: nil, variants: [], track_stock: false, sold_by_weight: false, is_composite: false) ⇒ Hash
Create a new item
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/loyverse_api/endpoints/items.rb', line 36 def create_item(item_name:, category_id: nil, variants: [], track_stock: false, sold_by_weight: false, is_composite: false) body = { item_name: item_name, track_stock: track_stock, sold_by_weight: sold_by_weight, is_composite: is_composite } body[:category_id] = category_id if category_id body[:variants] = variants unless variants.empty? post("items", body: body) end |
#delete_item(item_id) ⇒ Hash
Delete an item
70 71 72 |
# File 'lib/loyverse_api/endpoints/items.rb', line 70 def delete_item(item_id) delete("items/#{item_id}") end |
#get_item(item_id) ⇒ Hash
Get a specific item by ID
7 8 9 |
# File 'lib/loyverse_api/endpoints/items.rb', line 7 def get_item(item_id) get("items/#{item_id}") end |
#list_items(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil) ⇒ Hash
List items
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/loyverse_api/endpoints/items.rb', line 17 def list_items(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil) params = { limit: limit, cursor: cursor, updated_at_min: format_time(updated_at_min), updated_at_max: format_time(updated_at_max) }.compact get("items", params: params) end |
#update_item(item_id, item_name: nil, category_id: nil, variants: nil, track_stock: nil) ⇒ Hash
Update an existing item
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/loyverse_api/endpoints/items.rb', line 56 def update_item(item_id, item_name: nil, category_id: nil, variants: nil, track_stock: nil) body = { item_name: item_name, category_id: category_id, variants: variants, track_stock: track_stock }.compact put("items/#{item_id}", body: body) end |