Class: Cin7API::SalesOrderResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/cin7_api/resources/sales_order_resource.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#get_request, #handle_response, #initialize, #post_request, #put_request

Constructor Details

This class inherits a constructor from Cin7API::Resource

Instance Method Details

#find(id) ⇒ Object

@client.sales_order.find(2218)



21
22
23
# File 'lib/cin7_api/resources/sales_order_resource.rb', line 21

def find(id)
  SalesOrder.new(get_request("SalesOrders/#{id}").body)
end

#find_by(**params) ⇒ Object

@client.sales_order.find_by(reference: “#1050”, email: “[email protected]”)



16
17
18
# File 'lib/cin7_api/resources/sales_order_resource.rb', line 16

def find_by(**params)
  where(**params).first
end

#update(attributes_array) ⇒ Object

attributes_array = [

{
  id: 2221,
  lineItems: [{ id: 8140, unitPrice: 100 }],
  dispatchedDate: "2022-09-16T09:00:00Z",
  invoiceDate: "2022-09-16T09:00:00Z"
}

] @client.sales_order.update(attributes_array)



34
35
36
37
# File 'lib/cin7_api/resources/sales_order_resource.rb', line 34

def update(attributes_array)
  responses = put_request("SalesOrders", body: attributes_array).body
  responses.map { |attributes| Response.new(attributes) }
end

#where(**params) ⇒ Object

@client.sales_order.where(reference: “#1050”, email: “[email protected]”)



6
7
8
9
10
11
12
13
# File 'lib/cin7_api/resources/sales_order_resource.rb', line 6

def where(**params)
  response_body = get_request("SalesOrders", params: params).body
  sales_orders = response_body.map { |attributes| SalesOrder.new(attributes) }
  # Doing a filter here because Cin7 is doing a binary OR check for the filter params
  sales_orders.filter do |sales_order|
    params.reduce(true) { |acc, (key, value)| acc && sales_order[key] == value }
  end
end