class Pwinty::Order
Public Class Methods
find(id)
click to toggle source
# File lib/pwinty/api_models/order.rb, line 32 def self.find(id) response = Pwinty.conn.get("orders/#{id}") new(response.body['order']) end
list(page_size: DEFAULT_PAGE_SIZE, limit: 0)
click to toggle source
# File lib/pwinty/api_models/order.rb, line 37 def self.list(page_size: DEFAULT_PAGE_SIZE, limit: 0) """ Get all of the orders - this can take a while! Page size maximum is 100. Limit of 0 will get all of them. """ all_orders = list_each_page(page_size: page_size, limit: limit) Pwinty.collate_results(all_orders, self) end
list_each_page(page_size: DEFAULT_PAGE_SIZE, limit: 0)
click to toggle source
# File lib/pwinty/api_models/order.rb, line 47 def self.list_each_page(page_size: DEFAULT_PAGE_SIZE, limit: 0) all_orders = [] page_start = 0 has_more = true limit_reached = false while has_more and not limit_reached response = Pwinty.conn.get("orders?top=#{page_size}&skip=#{page_start}") all_orders = all_orders + response.body['orders'] page_start += page_size limit_reached = Pwinty::is_limit_reached(all_orders.count, limit: limit) has_more = response.body['hasMore'] end all_orders end
Public Instance Methods
add_image(image)
click to toggle source
# File lib/pwinty/api_models/order.rb, line 62 def add_image image self.items << Pwinty::OrderItem.new( sku: image[:sku], copies: image[:copies], assets: [Pwinty::OrderAsset.new( url: image[:url], )] ) end
cancel()
click to toggle source
# File lib/pwinty/api_models/order.rb, line 91 def cancel """Cancel the order. https://www.prodigi.com/print-api/docs/reference/#cancel-an-order """ response = Pwinty.conn.post("orders/#{self.id}/actions/cancel") outcome = response.body['outcome'] case outcome when 'failedToCancel'; raise Pwinty::Error, response.body when 'actionNotAvailable'; raise Pwinty::OrderActionUnavailable, response.body end new(response.body['order']) end
serializable()
click to toggle source
# File lib/pwinty/api_models/order.rb, line 72 def serializable order_attrs = Hash.new order_attrs.update(self.attributes) order_attrs[:items] = [] for item in self.items order_attrs[:items] << item.serializable end order_attrs[:recipient] = self.recipient.serializable order_attrs end
submit()
click to toggle source
# File lib/pwinty/api_models/order.rb, line 85 def submit """Send the order to Prodigi.""" response = Pwinty.conn.post("orders", self.serializable) new(response.body['order']) end