Class: BaseCRM::OrdersService
- Inherits:
-
Object
- Object
- BaseCRM::OrdersService
- Defined in:
- lib/basecrm/services/orders_service.rb
Constant Summary collapse
- OPTS_KEYS_TO_PERSIST =
Set[:deal_id, :discount]
Instance Method Summary collapse
-
#all ⇒ Enumerable
Retrieve all orders.
-
#create(order) ⇒ Order
Create an order.
-
#destroy(id) ⇒ Boolean
Delete an order.
-
#find(id) ⇒ Order
Retrieve a single order.
-
#initialize(client) ⇒ OrdersService
constructor
A new instance of OrdersService.
-
#update(order) ⇒ Order
Update an order.
-
#where(options = {}) ⇒ Array<Order>
Retrieve all orders.
Constructor Details
#initialize(client) ⇒ OrdersService
Returns a new instance of OrdersService.
7 8 9 |
# File 'lib/basecrm/services/orders_service.rb', line 7 def initialize(client) @client = client end |
Instance Method Details
#all ⇒ Enumerable
Retrieve all orders
get ‘/orders’
If you want to use filtering or sorting (see #where).
17 18 19 |
# File 'lib/basecrm/services/orders_service.rb', line 17 def all PaginatedResource.new(self) end |
#create(order) ⇒ Order
Create an order
post ‘/orders’
Create a new order for a deal User needs to have access to the deal to create an order Each deal can have at most one order and error is returned when attempting to create more
51 52 53 54 55 56 57 58 |
# File 'lib/basecrm/services/orders_service.rb', line 51 def create(order) validate_type!(order) attributes = sanitize(order) _, _, root = @client.post("/orders", attributes) Order.new(root[:data]) end |
#destroy(id) ⇒ Boolean
Delete an order
delete ‘/orders/BaseCRM#id’
Delete an existing order and remove all of the associated line items in a single call If the specified order does not exist, the request will return an error This operation cannot be undone
108 109 110 111 |
# File 'lib/basecrm/services/orders_service.rb', line 108 def destroy(id) status, _, _ = @client.delete("/orders/#{id}") status == 204 end |
#find(id) ⇒ Order
Retrieve a single order
get ‘/orders/BaseCRM#id’
Returns a single order available to the user, according to the unique order ID provided If the specified order does not exist, the request will return an error
70 71 72 73 74 |
# File 'lib/basecrm/services/orders_service.rb', line 70 def find(id) _, _, root = @client.get("/orders/#{id}") Order.new(root[:data]) end |
#update(order) ⇒ Order
Update an order
put ‘/orders/BaseCRM#id’
Updates order information If the specified order does not exist, the request will return an error
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/basecrm/services/orders_service.rb', line 86 def update(order) validate_type!(order) params = extract_params!(order, :id) id = params[:id] attributes = sanitize(order) _, _, root = @client.put("/orders/#{id}", attributes) Order.new(root[:data]) end |
#where(options = {}) ⇒ Array<Order>
Retrieve all orders
get ‘/orders’
Returns all orders available to the user according to the parameters provided
34 35 36 37 38 |
# File 'lib/basecrm/services/orders_service.rb', line 34 def where( = {}) _, _, root = @client.get("/orders", ) root[:items].map{ |item| Order.new(item[:data]) } end |