Class: PowaApi::OrderService
- Inherits:
-
PowaService
- Object
- PowaService
- PowaApi::OrderService
- Defined in:
- lib/powa_api/order_service.rb
Class Method Summary collapse
- .find_updated_orders(updated_from, updated_to = nil) ⇒ Object
- .get_order_details(order_number) ⇒ Object
-
.get_orders(start_date, end_date = nil) ⇒ Object
This method invokes find_updated_orders and then calls get_order_details for each order and returns an array of the results.
Methods inherited from PowaService
Class Method Details
.find_updated_orders(updated_from, updated_to = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/powa_api/order_service.rb', line 4 def self.find_updated_orders(updated_from, updated_to = nil) client = Savon.client wsdl response = client.request :get_updated_orders do soap.xml do |xml| xml.soapenv(:Envelope, namespaces) do |xml| header_block(xml) xml.soapenv(:Body) do |xml| xml.urn(:FindUpdatedOrdersRequest) do |xml| xml.updatedFrom updated_from.strftime('%FT%T.000') xml.updatedTo updated_to.strftime('%FT%T.000') if updated_to end end end end end [response.to_array(:find_updated_orders_response).first[:orders]].flatten.compact end |
.get_order_details(order_number) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/powa_api/order_service.rb', line 28 def self.get_order_details(order_number) client = Savon.client wsdl begin response = client.request :get_order_details do soap.xml do |xml| xml.soapenv(:Envelope, namespaces) do |xml| header_block(xml) xml.soapenv(:Body) do |xml| xml.urn(:GetOrderDetailsRequest) do |xml| xml.orderNumber order_number end end end end end rescue Savon::SOAP::Fault => e return nil if e..include?("Order not found") raise e. end response.to_array(:get_order_details_response).first end |
.get_orders(start_date, end_date = nil) ⇒ Object
This method invokes find_updated_orders and then calls get_order_details for each order and returns an array of the results
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/powa_api/order_service.rb', line 58 def self.get_orders(start_date, end_date=nil) orders = [] # Grab the list of orders and extract the order numbers order_ids = OrderService.find_updated_orders(start_date, end_date).map { |order| order[:order_number] } order_ids.each do |order_id| orders << OrderService.get_order_details(order_id) end return orders.flatten.compact end |