Class: Tosuto::Order
Constant Summary collapse
- ENDPOINT =
"/orders/v2/orders".freeze
Instance Attribute Summary collapse
-
#external_id ⇒ Object
Returns the value of attribute external_id.
-
#guid ⇒ Object
Returns the value of attribute guid.
Class Method Summary collapse
- .all(restaurant_id:, token:, date_range: nil, business_date: nil, api: API.new) ⇒ Object
- .get(guid:, restaurant_id:, token:, api: API.new) ⇒ Object
Instance Method Summary collapse
- #get_details(token:, api: API.new) ⇒ Object
-
#initialize(hash) ⇒ Order
constructor
A new instance of Order.
Methods inherited from Resource
attr_collections, attr_objects, encode_form_data, #inspect, #parse_collection, #parse_object, #set_attribute, #set_attributes, #underscore
Constructor Details
#initialize(hash) ⇒ Order
Returns a new instance of Order.
80 81 82 |
# File 'lib/tosuto/order.rb', line 80 def initialize(hash) set_attributes(hash) end |
Instance Attribute Details
#external_id ⇒ Object
Returns the value of attribute external_id.
9 10 11 |
# File 'lib/tosuto/order.rb', line 9 def external_id @external_id end |
#guid ⇒ Object
Returns the value of attribute guid.
9 10 11 |
# File 'lib/tosuto/order.rb', line 9 def guid @guid end |
Class Method Details
.all(restaurant_id:, token:, date_range: nil, business_date: nil, api: API.new) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tosuto/order.rb', line 43 def self.all(restaurant_id:, token:, date_range: nil, business_date: nil, api: API.new) params = {} unless date_range.nil? params["startDate"] = date_range.begin.utc.strftime("%Y-%m-%dT%H:%M:%S.%L%z") params["endDate"] = date_range.end.utc.strftime("%Y-%m-%dT%H:%M:%S.%L%z") end unless business_date.nil? params["businessDate"] = business_date.strftime("%Y%m%d") end response = api.request( :get, ENDPOINT, params: params, restaurant_id: restaurant_id, token: token ) raise response.error unless response.success? response.json_body.map { |guid| Order.new(guid: guid, restaurant_id: restaurant_id) } end |
.get(guid:, restaurant_id:, token:, api: API.new) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tosuto/order.rb', line 67 def self.get(guid:, restaurant_id:, token:, api: API.new) url = "#{ENDPOINT}/#{guid}" response = api.request( :get, url, restaurant_id: restaurant_id, token: token ) raise response.error unless response.success? return new(response.json_body.merge(restaurant_id: restaurant_id)) end |