Class: BaseCRM::LineItemsService
- Inherits:
-
Object
- Object
- BaseCRM::LineItemsService
- Defined in:
- lib/basecrm/services/line_items_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:product_id, :value, :variation, :currency, :quantity]
Instance Method Summary collapse
-
#all(order_id) ⇒ Enumerable
Retrieve order’s line items.
-
#create(order_id, line_item) ⇒ LineItem
Create a line item.
-
#destroy(order_id, id) ⇒ Boolean
Delete a line item.
-
#find(order_id, id) ⇒ LineItem
Retrieve a single line item.
-
#initialize(client) ⇒ LineItemsService
constructor
A new instance of LineItemsService.
-
#where(order_id, options = {}) ⇒ Array<LineItem>
Retrieve order’s line items.
Constructor Details
#initialize(client) ⇒ LineItemsService
Returns a new instance of LineItemsService.
7 8 9 |
# File 'lib/basecrm/services/line_items_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all(order_id) ⇒ Enumerable
Retrieve order’s line items
get ‘/orders/order_id/line_items’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/line_items_service.rb', line 17 def all(order_id) PaginatedResource.new(self, order_id) end |
#create(order_id, line_item) ⇒ LineItem
Create a line item
post ‘/orders/order_id/line_items’
Adds a new line item to an existing order Line items correspond to products in the catalog, so first you must create products Because products allow defining different prices in different currencies, when creating a line item, the parameter currency is required
54 55 56 57 58 59 60 61 |
# File 'lib/basecrm/services/line_items_service.rb', line 54 def create(order_id, line_item) validate_type!(line_item) attributes = sanitize(line_item) _, _, root = @client.post("/orders/#{order_id}/line_items", attributes) LineItem.new(root[:data]) end |
#destroy(order_id, id) ⇒ Boolean
Delete a line item
delete ‘/orders/order_id/line_items/BaseCRM#id’
Remove an order’s line item This operation cannot be undone
90 91 92 93 |
# File 'lib/basecrm/services/line_items_service.rb', line 90 def destroy(order_id, id) status, _, _ = @client.delete("/orders/#{order_id}/line_items/#{id}") status == 204 end |
#find(order_id, id) ⇒ LineItem
Retrieve a single line item
get ‘/orders/order_id/line_items/BaseCRM#id’
Returns a single line item of an order, according to the unique line item ID provided
73 74 75 76 77 |
# File 'lib/basecrm/services/line_items_service.rb', line 73 def find(order_id, id) _, _, root = @client.get("/orders/#{order_id}/line_items/#{id}") LineItem.new(root[:data]) end |
#where(order_id, options = {}) ⇒ Array<LineItem>
Retrieve order’s line items
get ‘/orders/order_id/line_items’
Returns all line items associated to order
36 37 38 39 40 |
# File 'lib/basecrm/services/line_items_service.rb', line 36 def where(order_id, = {}) _, _, root = @client.get("/orders/#{order_id}/line_items", ) root[:items].map{ |item| LineItem.new(item[:data]) } end |