Class: EasyPost::Order
- Inherits:
-
Resource
- Object
- EasyPostObject
- Resource
- EasyPost::Order
- Defined in:
- lib/easypost/order.rb
Overview
The Order object represents a collection of packages and can be used for Multi-Piece Shipments.
Instance Attribute Summary
Attributes inherited from EasyPostObject
#api_key, #name, #parent, #unsaved_values
Class Method Summary collapse
-
.all(_filters = {}, _api_key = nil) ⇒ Object
Retrieve a list of Order objects.
Instance Method Summary collapse
-
#buy(params = {}) ⇒ Object
Buy an Order.
-
#get_rates(params = {}) ⇒ Object
Get the rates of an Order.
-
#lowest_rate(carriers = [], services = []) ⇒ Object
Get the lowest rate of an Order (can exclude by having `'!'` as the first element of your optional filter lists).
Methods inherited from Resource
class_name, create, #delete, each, #refresh, retrieve, #save, url, #url
Methods inherited from EasyPostObject
#[], #[]=, #as_json, construct_from, #deconstruct_keys, #each, #id, #id=, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values
Constructor Details
This class inherits a constructor from EasyPost::EasyPostObject
Class Method Details
.all(_filters = {}, _api_key = nil) ⇒ Object
Retrieve a list of Order objects.
29 30 31 |
# File 'lib/easypost/order.rb', line 29 def self.all(_filters = {}, _api_key = nil) raise NotImplementedError.new('Order.all not implemented.') end |
Instance Method Details
#buy(params = {}) ⇒ Object
Buy an Order.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/easypost/order.rb', line 14 def buy(params = {}) if params.instance_of?(EasyPost::Rate) temp = params.clone params = {} params[:carrier] = temp.carrier params[:service] = temp.service end response = EasyPost.make_request(:post, "#{url}/buy", @api_key, params) refresh_from(response, @api_key) self end |
#get_rates(params = {}) ⇒ Object
Get the rates of an Order.
6 7 8 9 10 11 |
# File 'lib/easypost/order.rb', line 6 def get_rates(params = {}) response = EasyPost.make_request(:get, "#{url}/rates", @api_key, params) refresh_from(response, @api_key) self end |
#lowest_rate(carriers = [], services = []) ⇒ Object
Get the lowest rate of an Order (can exclude by having `'!'` as the first element of your optional filter lists).
34 35 36 |
# File 'lib/easypost/order.rb', line 34 def lowest_rate(carriers = [], services = []) EasyPost::Util.get_lowest_object_rate(self, carriers, services) end |