channeladvisor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +6 -0
  4. data/.yardopts +8 -0
  5. data/Gemfile +31 -0
  6. data/Guardfile +28 -0
  7. data/LICENSE +19 -0
  8. data/README.md +40 -0
  9. data/Rakefile +69 -0
  10. data/channeladvisor.gemspec +29 -0
  11. data/lib/channeladvisor.rb +27 -0
  12. data/lib/channeladvisor/account_authorization.rb +14 -0
  13. data/lib/channeladvisor/address.rb +39 -0
  14. data/lib/channeladvisor/admin.rb +75 -0
  15. data/lib/channeladvisor/base.rb +34 -0
  16. data/lib/channeladvisor/client.rb +3 -0
  17. data/lib/channeladvisor/configuration.rb +11 -0
  18. data/lib/channeladvisor/error.rb +30 -0
  19. data/lib/channeladvisor/line_item.rb +38 -0
  20. data/lib/channeladvisor/order.rb +179 -0
  21. data/lib/channeladvisor/order_status.rb +14 -0
  22. data/lib/channeladvisor/payment.rb +15 -0
  23. data/lib/channeladvisor/services.rb +11 -0
  24. data/lib/channeladvisor/services/admin_service.rb +47 -0
  25. data/lib/channeladvisor/services/base_service.rb +26 -0
  26. data/lib/channeladvisor/services/inventory_service.rb +90 -0
  27. data/lib/channeladvisor/services/order_service.rb +117 -0
  28. data/lib/channeladvisor/services/shipping_service.rb +164 -0
  29. data/lib/channeladvisor/shipment.rb +71 -0
  30. data/lib/channeladvisor/shopping_cart.rb +26 -0
  31. data/lib/channeladvisor/version.rb +3 -0
  32. data/spec/fixtures/requests/admin_service/get_authorization_list.xml +1 -0
  33. data/spec/fixtures/requests/admin_service/get_authorization_list_with_local_id.xml +1 -0
  34. data/spec/fixtures/requests/admin_service/ping.xml +1 -0
  35. data/spec/fixtures/requests/admin_service/request_access.xml +1 -0
  36. data/spec/fixtures/requests/inventory_service/ping.xml +1 -0
  37. data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/price_only.xml +1 -0
  38. data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_and_price.xml +1 -0
  39. data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_only.xml +1 -0
  40. data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/price_only.xml +1 -0
  41. data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_and_price.xml +1 -0
  42. data/spec/fixtures/requests/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_only.xml +1 -0
  43. data/spec/fixtures/requests/inventory_service/update_item_price.xml +1 -0
  44. data/spec/fixtures/requests/inventory_service/update_item_quantity.xml +1 -0
  45. data/spec/fixtures/requests/inventory_service/update_item_quantity_and_price.xml +1 -0
  46. data/spec/fixtures/requests/order_service/get_order_list/with_checkout_status_filter.xml +1 -0
  47. data/spec/fixtures/requests/order_service/get_order_list/with_created_from_date.xml +1 -0
  48. data/spec/fixtures/requests/order_service/get_order_list/with_created_to_date.xml +1 -0
  49. data/spec/fixtures/requests/order_service/get_order_list/with_detail_level.xml +1 -0
  50. data/spec/fixtures/requests/order_service/get_order_list/with_distribution_center_code.xml +1 -0
  51. data/spec/fixtures/requests/order_service/get_order_list/with_export_state.xml +1 -0
  52. data/spec/fixtures/requests/order_service/get_order_list/with_join_dates.xml +1 -0
  53. data/spec/fixtures/requests/order_service/get_order_list/with_one_client_order_id.xml +1 -0
  54. data/spec/fixtures/requests/order_service/get_order_list/with_one_order_id.xml +1 -0
  55. data/spec/fixtures/requests/order_service/get_order_list/with_order_state_filter.xml +1 -0
  56. data/spec/fixtures/requests/order_service/get_order_list/with_page_number_filter.xml +1 -0
  57. data/spec/fixtures/requests/order_service/get_order_list/with_page_size.xml +1 -0
  58. data/spec/fixtures/requests/order_service/get_order_list/with_payment_status_filter.xml +1 -0
  59. data/spec/fixtures/requests/order_service/get_order_list/with_refund_status_filter.xml +1 -0
  60. data/spec/fixtures/requests/order_service/get_order_list/with_shipping_status_filter.xml +1 -0
  61. data/spec/fixtures/requests/order_service/get_order_list/with_two_client_order_ids.xml +1 -0
  62. data/spec/fixtures/requests/order_service/get_order_list/with_two_order_ids.xml +1 -0
  63. data/spec/fixtures/requests/order_service/get_order_list/with_updated_from_date.xml +1 -0
  64. data/spec/fixtures/requests/order_service/get_order_list/with_updated_to_date.xml +1 -0
  65. data/spec/fixtures/requests/order_service/get_order_list/without_order_criteria.xml +1 -0
  66. data/spec/fixtures/requests/order_service/ping.xml +1 -0
  67. data/spec/fixtures/requests/order_service/set_orders_export_status/with_one_client_order_id.xml +1 -0
  68. data/spec/fixtures/requests/order_service/set_orders_export_status/with_two_client_order_ids.xml +1 -0
  69. data/spec/fixtures/requests/shipping_service/get_shipping_carrier_list.xml +1 -0
  70. data/spec/fixtures/requests/shipping_service/ping.xml +1 -0
  71. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/with_one_shipment.xml +1 -0
  72. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/with_two_shipments.xml +1 -0
  73. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_carrier_code.xml +1 -0
  74. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_class_code.xml +1 -0
  75. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_client_order_id.xml +1 -0
  76. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_seller_id.xml +1 -0
  77. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/full_shipment/without_tracking_number.xml +1 -0
  78. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/with_one_line_item.xml +1 -0
  79. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/with_two_line_items.xml +1 -0
  80. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/with_two_shipments.xml +1 -0
  81. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_carrier_code.xml +1 -0
  82. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_class_code.xml +1 -0
  83. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_seller_id.xml +1 -0
  84. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/partial_shipment/without_tracking_number.xml +1 -0
  85. data/spec/fixtures/requests/shipping_service/submit_order_shipment_list/with_partial_and_full_shipments.xml +1 -0
  86. data/spec/fixtures/responses/admin/get_authorization_list/failure.yml +50 -0
  87. data/spec/fixtures/responses/admin/get_authorization_list/no_authorizations.yml +49 -0
  88. data/spec/fixtures/responses/admin/get_authorization_list/one_authorization.yml +49 -0
  89. data/spec/fixtures/responses/admin/get_authorization_list/success.yml +49 -0
  90. data/spec/fixtures/responses/admin/get_authorization_list/two_authorizations.yml +49 -0
  91. data/spec/fixtures/responses/admin/ping/failure.yml +50 -0
  92. data/spec/fixtures/responses/admin/ping/success.yml +218 -0
  93. data/spec/fixtures/responses/admin/request_access/failure.yml +50 -0
  94. data/spec/fixtures/responses/admin/request_access/success.yml +49 -0
  95. data/spec/fixtures/responses/admin_service/get_authorization_list/with_invalid_local_id.yml +219 -0
  96. data/spec/fixtures/responses/admin_service/get_authorization_list/with_local_id/success.yml +218 -0
  97. data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/multiple_authorizations.yml +49 -0
  98. data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/no_authorizations.yml +49 -0
  99. data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/one_authorization.yml +49 -0
  100. data/spec/fixtures/responses/admin_service/get_authorization_list/with_valid_local_id/success.yml +218 -0
  101. data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/multiple_authorizations.yml +49 -0
  102. data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/no_authorizations.yml +49 -0
  103. data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/one_authorization.yml +49 -0
  104. data/spec/fixtures/responses/admin_service/get_authorization_list/without_local_id/success.yml +218 -0
  105. data/spec/fixtures/responses/admin_service/ping/failure.yml +222 -0
  106. data/spec/fixtures/responses/admin_service/ping/success.yml +218 -0
  107. data/spec/fixtures/responses/admin_service/request_access/failure.yml +219 -0
  108. data/spec/fixtures/responses/admin_service/request_access/success.yml +218 -0
  109. data/spec/fixtures/responses/http_error.yml +48 -0
  110. data/spec/fixtures/responses/inventory_service/ping.yml +1356 -0
  111. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price.yml +1356 -0
  112. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price/price_only.yml +144 -0
  113. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price/quantity_and_price.yml +191 -0
  114. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price/quantity_only.yml +1403 -0
  115. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list.yml +243 -0
  116. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/price_only.yml +97 -0
  117. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_and_price.yml +144 -0
  118. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_one_item/quantity_only.yml +51 -0
  119. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/price_only.yml +238 -0
  120. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_and_price.yml +285 -0
  121. data/spec/fixtures/responses/inventory_service/update_inventory_item_quantity_and_price_list/with_two_items/quantity_only.yml +191 -0
  122. data/spec/fixtures/responses/order/instance_set_export_status.yml +51 -0
  123. data/spec/fixtures/responses/order/instance_set_export_status/failure.yml +51 -0
  124. data/spec/fixtures/responses/order/instance_set_export_status/success/result_false.yml +51 -0
  125. data/spec/fixtures/responses/order/instance_set_export_status/success/result_true.yml +51 -0
  126. data/spec/fixtures/responses/order/list.yml +58 -0
  127. data/spec/fixtures/responses/order/list/failure.yml +56 -0
  128. data/spec/fixtures/responses/order/list/no_matching_orders.yml +56 -0
  129. data/spec/fixtures/responses/order/list/one_matching_order.yml +57 -0
  130. data/spec/fixtures/responses/order/list/two_matching_orders.yml +59 -0
  131. data/spec/fixtures/responses/order/list/with_criteria.yml +52 -0
  132. data/spec/fixtures/responses/order/list/with_no_criteria.yml +58 -0
  133. data/spec/fixtures/responses/order/ping.yml +868 -0
  134. data/spec/fixtures/responses/order/ping/failure.yml +50 -0
  135. data/spec/fixtures/responses/order/ping/success.yml +867 -0
  136. data/spec/fixtures/responses/order/set_export_status/failure.yml +51 -0
  137. data/spec/fixtures/responses/order/set_export_status/success/with_one_client_order_id.yml +51 -0
  138. data/spec/fixtures/responses/order/set_export_status/success/with_two_client_order_ids.yml +51 -0
  139. data/spec/fixtures/responses/order_service/get_order_list/.gitkeep +0 -0
  140. data/spec/fixtures/responses/order_service/get_order_list/with_checkout_status_filter.yml +875 -0
  141. data/spec/fixtures/responses/order_service/get_order_list/with_created_from_date.yml +874 -0
  142. data/spec/fixtures/responses/order_service/get_order_list/with_created_to_date.yml +874 -0
  143. data/spec/fixtures/responses/order_service/get_order_list/with_detail_level.yml +875 -0
  144. data/spec/fixtures/responses/order_service/get_order_list/with_distribution_center_code.yml +872 -0
  145. data/spec/fixtures/responses/order_service/get_order_list/with_export_state.yml +875 -0
  146. data/spec/fixtures/responses/order_service/get_order_list/with_join_dates.yml +869 -0
  147. data/spec/fixtures/responses/order_service/get_order_list/with_one_client_order_id.yml +872 -0
  148. data/spec/fixtures/responses/order_service/get_order_list/with_one_order_id.yml +873 -0
  149. data/spec/fixtures/responses/order_service/get_order_list/with_order_state_filter.yml +875 -0
  150. data/spec/fixtures/responses/order_service/get_order_list/with_page_number_filter.yml +875 -0
  151. data/spec/fixtures/responses/order_service/get_order_list/with_page_size.yml +874 -0
  152. data/spec/fixtures/responses/order_service/get_order_list/with_payment_status_filter.yml +875 -0
  153. data/spec/fixtures/responses/order_service/get_order_list/with_refund_status_filter.yml +875 -0
  154. data/spec/fixtures/responses/order_service/get_order_list/with_shipping_status_filter.yml +875 -0
  155. data/spec/fixtures/responses/order_service/get_order_list/with_two_client_order_ids.yml +872 -0
  156. data/spec/fixtures/responses/order_service/get_order_list/with_two_order_ids.yml +875 -0
  157. data/spec/fixtures/responses/order_service/get_order_list/with_updated_from_date.yml +874 -0
  158. data/spec/fixtures/responses/order_service/get_order_list/with_updated_to_date.yml +874 -0
  159. data/spec/fixtures/responses/order_service/get_order_list/without_order_criteria.yml +871 -0
  160. data/spec/fixtures/responses/order_service/get_order_refund_history/.gitkeep +0 -0
  161. data/spec/fixtures/responses/order_service/order_merge/.gitkeep +0 -0
  162. data/spec/fixtures/responses/order_service/order_split/.gitkeep +0 -0
  163. data/spec/fixtures/responses/order_service/ping/.gitkeep +0 -0
  164. data/spec/fixtures/responses/order_service/ping/failure.yml +871 -0
  165. data/spec/fixtures/responses/order_service/ping/success.yml +868 -0
  166. data/spec/fixtures/responses/order_service/set_orders_export_status/with_one_client_order_id.yml +867 -0
  167. data/spec/fixtures/responses/order_service/set_orders_export_status/with_two_client_order_id.yml +867 -0
  168. data/spec/fixtures/responses/order_service/set_seller_order_id/.gitkeep +0 -0
  169. data/spec/fixtures/responses/order_service/set_seller_order_item_id_list/.gitkeep +0 -0
  170. data/spec/fixtures/responses/order_service/submit_order/.gitkeep +0 -0
  171. data/spec/fixtures/responses/order_service/submit_order_refund/.gitkeep +0 -0
  172. data/spec/fixtures/responses/order_service/update_order_list/.gitkeep +0 -0
  173. data/spec/fixtures/responses/shipment/get_carriers.yml +53 -0
  174. data/spec/fixtures/responses/shipment/get_carriers/failure.yml +52 -0
  175. data/spec/fixtures/responses/shipment/submit.yml +464 -0
  176. data/spec/fixtures/responses/shipment/submit/failure.yml +462 -0
  177. data/spec/fixtures/responses/shipment/submit/one_shipment.yml +464 -0
  178. data/spec/fixtures/responses/shipment/submit/two_shipments.yml +56 -0
  179. data/spec/fixtures/responses/shipping_service/get_shipping_carrier_list.yml +953 -0
  180. data/spec/fixtures/responses/shipping_service/ping/failure.yml +55 -0
  181. data/spec/fixtures/responses/shipping_service/ping/success.yml +460 -0
  182. data/spec/fixtures/responses/shipping_service/submit_order_shipment_list.yml +55 -0
  183. data/spec/fixtures/responses/soap_fault.yml +53 -0
  184. data/spec/lib/channeladvisor/address_spec.rb +107 -0
  185. data/spec/lib/channeladvisor/admin_spec.rb +216 -0
  186. data/spec/lib/channeladvisor/line_item_spec.rb +147 -0
  187. data/spec/lib/channeladvisor/order_spec.rb +623 -0
  188. data/spec/lib/channeladvisor/order_status_spec.rb +36 -0
  189. data/spec/lib/channeladvisor/payment_spec.rb +38 -0
  190. data/spec/lib/channeladvisor/services/admin_service_spec.rb +65 -0
  191. data/spec/lib/channeladvisor/services/base_service_spec.rb +11 -0
  192. data/spec/lib/channeladvisor/services/inventory_service_spec.rb +214 -0
  193. data/spec/lib/channeladvisor/services/order_service_spec.rb +267 -0
  194. data/spec/lib/channeladvisor/services/shipping_service_spec.rb +288 -0
  195. data/spec/lib/channeladvisor/shipment_spec.rb +257 -0
  196. data/spec/lib/channeladvisor/shopping_cart_spec.rb +173 -0
  197. data/spec/lib/channeladvisor_spec.rb +18 -0
  198. data/spec/spec_helper.rb +29 -0
  199. data/spec/support/credentials.rb +15 -0
  200. data/spec/support/matchers/boolean.rb +17 -0
  201. data/spec/support/matchers/markup.rb +50 -0
  202. data/spec/support/rr.rb +38 -0
  203. data/spec/support/shared_examples.rb +4 -0
  204. data/spec/support/vcr.rb +38 -0
  205. metadata +501 -0
@@ -0,0 +1,3 @@
1
+ module ChannelAdvisor
2
+ class Client < Savon::Client; end
3
+ end
@@ -0,0 +1,11 @@
1
+ module ChannelAdvisor
2
+ class Configuration
3
+ attr_accessor :account_id, :developer_key, :password
4
+
5
+ def initialize
6
+ @account_id = nil
7
+ @developer_key = nil
8
+ @password = nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ module ChannelAdvisor
2
+ class Error < StandardError; end
3
+
4
+ class SOAPFault < Error
5
+ attr_reader :code
6
+
7
+ def initialize(fault_obj)
8
+ fault = fault_obj.to_hash[:fault]
9
+ @code = fault[:faultcode]
10
+ message = fault[:faultstring]
11
+
12
+ super(message)
13
+ end
14
+ end
15
+
16
+ class HTTPError < Error
17
+ attr_reader :code
18
+
19
+ def initialize(error_obj)
20
+ error = error_obj.to_hash
21
+ @code = error[:code]
22
+ message = "Failed with HTTP error #{@code}"
23
+
24
+ super(message)
25
+ end
26
+ end
27
+
28
+ class ServiceFailure < Error; end
29
+ end
30
+
@@ -0,0 +1,38 @@
1
+ module ChannelAdvisor
2
+ class LineItem
3
+ attr_accessor :id, :type, :sku, :title, :unit_price, :quantity, :allow_negative_quantity, :sale_source, :buyer_user_id,
4
+ :buyer_feedback_rating, :sales_source_id, :vat_rate, :tax_cost, :shipping_cost, :shipping_tax_cost, :gift_wrap_cost,
5
+ :gift_wrap_tax_cost, :gift_message, :gift_wrap_level, :recycling_fee, :unit_weight, :unit_of_measure, :warehouse_location,
6
+ :user_name, :distribution_center, :is_fba, :promo_code
7
+
8
+ def initialize(attrs={})
9
+ @id = attrs[:line_item_id]
10
+ @type = attrs[:line_item_type]
11
+ @sku = attrs[:sku]
12
+ @title = attrs[:title]
13
+ @unit_price = attrs[:unit_price].to_f
14
+ @quantity = attrs[:quantity].to_i
15
+ @allow_negative_quantity = attrs[:allow_negative_quantity]
16
+ @sale_source = attrs[:item_sale_source]
17
+ @buyer_user_id = attrs[:buyer_user_id]
18
+ @buyer_feedback_rating = attrs[:buyer_feedback_rating]
19
+ @sales_source_id = attrs[:sales_source_id]
20
+ @vat_rate = attrs[:vat_rate].to_f
21
+ @tax_cost = attrs[:tax_cost].to_f
22
+ @shipping_cost = attrs[:shipping_cost].to_f
23
+ @shipping_tax_cost = attrs[:shipping_tax_cost].to_f
24
+ @gift_wrap_cost = attrs[:gift_wrap_cost].to_f
25
+ @gift_wrap_tax_cost = attrs[:gift_wrap_tax_cost].to_f
26
+ @gift_message = attrs[:gift_message]
27
+ @gift_wrap_level = attrs[:gift_wrap_level]
28
+ @recycling_fee = attrs[:recycling_fee].to_f
29
+ @unit_weight = attrs[:unit_weight].to_f
30
+ @unit_of_measure = attrs[:unit_of_measure]
31
+ @warehouse_location = attrs[:warehouse_location]
32
+ @user_name = attrs[:user_name]
33
+ @distribution_center = attrs[:distribution_center_code]
34
+ @is_fba = attrs[:is_fba]
35
+ @promo_code = attrs[:promo_code]
36
+ end # initialize
37
+ end # LineItem
38
+ end # ChannelAdvisor
@@ -0,0 +1,179 @@
1
+ module ChannelAdvisor
2
+ class Order < Base
3
+ attr_accessor :id, :client_id, :seller_id, :state, :created_at, :updated_at, :total, :cancelled_on, :flag_description,
4
+ :reseller_id, :buyer_email, :buyer_ip_address, :email_opt_in, :shipping_instructions, :delivery_date, :estimated_ship_date,
5
+ :transaction_notes, :status, :billing_address, :shipping_address, :payment, :shipments, :shopping_cart, :custom_values
6
+
7
+ def initialize(attrs={})
8
+ @id = attrs[:order_id].to_i
9
+ @client_id = attrs[:client_order_identifier]
10
+ @seller_id = attrs[:seller_order_id]
11
+ @state = attrs[:order_state]
12
+ @created_at = attrs[:order_time_gmt]
13
+ @updated_at = attrs[:last_update_date]
14
+ @cancelled_on = attrs[:date_cancelled_gmt]
15
+ @total = attrs[:total_order_amount].to_f
16
+ @reseller_id = attrs[:reseller_id]
17
+ @flag_description = attrs[:flag_description]
18
+ @buyer_email = attrs[:buyer_email_address]
19
+ @email_opt_in = attrs[:email_opt_in]
20
+ @buyer_ip_address = attrs[:buyer_ip_address]
21
+ @transaction_notes = attrs[:transaction_notes]
22
+ @custom_values = attrs[:custom_value_list]
23
+ @status = OrderStatus.new(attrs[:order_status]) if attrs[:order_status]
24
+ @payment = Payment.new(attrs[:payment_info]) if attrs[:payment_info]
25
+ @billing_address = Address.new(attrs[:billing_info]) if attrs[:billing_info]
26
+ @shipping_address = Address.new(attrs[:shipping_info]) if attrs[:shipping_info]
27
+ @shopping_cart = ShoppingCart.new(attrs[:shopping_cart]) if attrs[:shopping_cart]
28
+
29
+ if shipping_info = attrs[:shipping_info]
30
+ @shipping_instructions = shipping_info[:shipping_instructions]
31
+ @estimated_ship_date = shipping_info[:estimated_ship_date]
32
+ @delivery_date = shipping_info[:delivery_date]
33
+
34
+ if shipment_list = shipping_info[:shipment_list]
35
+ @shipments = arrayify(shipment_list[:shipment]).map { |s| Shipment.new(s) }
36
+ end
37
+ end
38
+ end # initialize
39
+
40
+ # Set the export status for a given order instance
41
+ #
42
+ # @param [Boolean] mark_as_exported `true` (`Exported`) or `false` (`NotExported`)
43
+ #
44
+ # @raise [ServiceFailure] If the service returns a Failure status
45
+ # @raise [SOAPFault] If the service responds with a SOAP fault
46
+ # @raise [HTTPError] If the service responds with an HTTP error
47
+ #
48
+ # @return [Boolean] Returns the boolean result for changing the export status
49
+ def set_export_status(mark_as_exported)
50
+ handle_errors do
51
+ response = Services::OrderService.set_orders_export_status([@client_id], mark_as_exported)
52
+ result = response[:set_orders_export_status_response][:set_orders_export_status_result]
53
+ check_status_of result
54
+ return result[:result_data][:boolean]
55
+ end
56
+ end # set_export_status
57
+
58
+ def total_ship_cost
59
+ invoice_ship_cost || items_ship_cost
60
+ end
61
+
62
+ def invoice_ship_cost
63
+ shopping_cart.invoices.select { |i| i.type == "Shipping" }.first.unit_price.nonzero?
64
+ end
65
+
66
+ def items_ship_cost
67
+ shopping_cart.items.collect { |i| i.shipping_cost }.inject(:+)
68
+ end
69
+
70
+ class << self
71
+ # Check authorization for and availability of the order service
72
+ #
73
+ # @raise [ServiceFailure] If the service returns a Failure status
74
+ # @raise [SOAPFault] If the service responds with a SOAP fault
75
+ # @raise [HTTPError] If the service responds with an HTTP error
76
+ #
77
+ # @return [Boolean] Returns `true` if SOAP response status is `Success`
78
+ def ping
79
+ handle_errors do
80
+ response = Services::OrderService.ping
81
+ result = response[:ping_response][:ping_result]
82
+ check_status_of result
83
+ end
84
+ end # ping
85
+
86
+ # Retrieve a list of orders, restricted by the provided criteria
87
+ #
88
+ # @example List orders created between 11/11/2011 and 11/15/2011
89
+ # ChannelAdvisor::Order.list(:created_between => DateTime.new(2011,11,11)..DateTime.new(2011,11,15))
90
+ #
91
+ # @param [Hash] criteria Criteria used to filter the order list
92
+ # @option criteria [Range<DateTime>] :created_between Range of order creation date-times in UTC (instead of `created_from` and `created_to`)
93
+ # @option criteria [Range<DateTime>] :updated_between Range of order update date-times in UTC (instead of `updated_from` and `updated_to`)
94
+ # @option criteria [DateTime] :created_from Order creation begin time in UTC
95
+ # @option criteria [DateTime] :created_to Order creation end time in UTC
96
+ # @option criteria [DateTime] :updated_from Order update begin time in UTC
97
+ # @option criteria [DateTime] :updated_to Order update end time in UTC
98
+ # @option criteria [Boolean] :join_dates `true` indicates that orders can satisfy either
99
+ # the created date range or the updated date range
100
+ # @option criteria [String] :detail_level `Low`, `Medium`, `High` or `Complete`
101
+ # @option criteria [String] :export_state `Unknown`, `NotExported` or `Exported`
102
+ # @option criteria [Array<Integer>] :order_ids Array of order IDs
103
+ # @option criteria [Array<String>] :client_order_ids Array of client order IDs
104
+ # @option criteria [String] :state `Active`, `Archived`, or `Cancelled`
105
+ # @option criteria [String] :payment_status `NoChange`, `NotSubmitted`, `Cleared`, `Submitted`, `Failed`, or `Deposited`
106
+ # @option criteria [String] :checkout_status `NoChange`, `NotVisited`, `Completed`, `Visited`, `Cancelled`, `CompletedOffline`, or `OnHold`
107
+ # @option criteria [String] :shipping_status `NoChange`, `Unshipped`, `PendingShipment`, `PartiallyShipped`, or `Shipped`
108
+ # @option criteria [String] :refund_status `NoRefunds`, `OrderLevel`, `LineItemLevel`, `OrderAndLineItemLevel`, or `FailedAttemptsOnly`
109
+ # @option criteria [String] :distribution_center Only orders containing at least one item from the specified distribution center
110
+ # @option criteria [Integer] :page_number Page number of result set
111
+ # @option criteria [Integer] :page_size Size of each page in result set
112
+ #
113
+ # @raise [ServiceFailure] If the service returns a Failure status
114
+ # @raise [SOAPFault] If the service responds with a SOAP fault
115
+ # @raise [HTTPError] If the service responds with an HTTP error
116
+ #
117
+ # @return [Array<Order>] Returns an array of {Order} objects or an empty array
118
+ def list(criteria = {})
119
+ handle_errors do
120
+ if created_between = criteria.delete(:created_between)
121
+ criteria[:created_from] = created_between.first
122
+ criteria[:created_to] = created_between.last
123
+ end
124
+
125
+ if updated_between = criteria.delete(:updated_between)
126
+ criteria[:updated_from] = updated_between.first
127
+ criteria[:updated_to] = updated_between.last
128
+ end
129
+
130
+ response = Services::OrderService.get_order_list(criteria)
131
+ result = response[:get_order_list_response][:get_order_list_result]
132
+ check_status_of result
133
+ orders = []
134
+
135
+ if data = result[:result_data]
136
+ arrayify(data[:order_response_item]).each { |o| orders << new(o) }
137
+ end
138
+
139
+ return orders
140
+ end
141
+ end # list
142
+
143
+ # Set the export status for the provided client order identifiers
144
+ #
145
+ # @param client_order_ids [String, Array<String>] An client order ID or array of client order IDs
146
+ # @param mark_as_exported [boolean] `true` (`Exported`) or `false` (`NotExported`)
147
+ #
148
+ # @raise [ServiceFailure] If the service returns a Failure status
149
+ # @raise [SOAPFault] If the service responds with a SOAP fault
150
+ # @raise [HTTPError] If the service responds with an HTTP error
151
+ #
152
+ # @return [boolean, Hash] Returns a boolean result or hash of client order IDs and their corresponding boolean results
153
+ def set_export_status(client_order_ids, mark_as_exported)
154
+ handle_errors do
155
+ client_order_id_list = arrayify client_order_ids
156
+ response = Services::OrderService.set_orders_export_status(client_order_id_list, mark_as_exported)
157
+ result = response[:set_orders_export_status_response][:set_orders_export_status_result]
158
+ check_status_of result
159
+
160
+ bools = arrayify result[:result_data][:boolean]
161
+
162
+ if bools.count == 1
163
+ return bools.first
164
+ else
165
+ result_hash = {}
166
+
167
+ bools.each do |bool|
168
+ client_order_ids.each do |client_order_id|
169
+ result_hash[client_order_id] = bool
170
+ end
171
+ end
172
+
173
+ return result_hash
174
+ end
175
+ end
176
+ end # set_export_status
177
+ end # self
178
+ end # Order
179
+ end # ChannelAdvisor
@@ -0,0 +1,14 @@
1
+ module ChannelAdvisor
2
+ class OrderStatus
3
+ attr_accessor :checkout, :payment, :shipping, :refund
4
+
5
+ def initialize(attrs={})
6
+ unless attrs.nil?
7
+ @checkout = [attrs[:checkout_status], attrs[:checkout_date_gmt]]
8
+ @payment = [attrs[:payment], attrs[:payment_date_gmt]]
9
+ @shipping = [attrs[:shipping], attrs[:shipping_date_gmt]]
10
+ @refund = attrs[:order_refund_status]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module ChannelAdvisor
2
+ class Payment
3
+ attr_accessor :type, :credit_card_number, :paypal_id, :merchant_reference_number, :transaction_id
4
+
5
+ def initialize(attrs={})
6
+ unless attrs.nil?
7
+ @type = attrs[:payment_type]
8
+ @credit_card_number = attrs[:credit_card_last4]
9
+ @paypal_id = attrs[:pay_pal_id]
10
+ @merchant_reference_number = attrs[:merchant_reference_number]
11
+ @transaction_id = attrs[:payment_transaction_id]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'channeladvisor/services/base_service'
2
+ require 'channeladvisor/services/admin_service'
3
+ require 'channeladvisor/services/order_service'
4
+ require 'channeladvisor/services/shipping_service'
5
+ require 'channeladvisor/services/inventory_service'
6
+
7
+ module ChannelAdvisor
8
+ module Services
9
+
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ module ChannelAdvisor
2
+ module Services
3
+ class AdminService < BaseService
4
+ document "https://api.channeladvisor.com/ChannelAdvisorAPI/v6/AdminService.asmx?WSDL"
5
+
6
+ class << self
7
+ # Check authorization for and availability of the admin service
8
+ #
9
+ # @return [HTTPI::Response] HTTP response object containing the SOAP XML response
10
+ def ping
11
+ soap_response = client.request :ping do
12
+ soap.header = soap_header
13
+ end
14
+
15
+ @last_request = client.http
16
+ @last_response = soap_response
17
+ end # ping
18
+
19
+ # Request access to a ChannelAdvisor account
20
+ #
21
+ # @return [HTTPI::Response] HTTP response object containing the SOAP XML response
22
+ def request_access(local_id)
23
+ soap_response = client.request :request_access do
24
+ soap.header = soap_header
25
+ soap.body = {"localID" => local_id}
26
+ end
27
+
28
+ @last_request = client.http
29
+ @last_response = soap_response
30
+ end # request_access
31
+
32
+ # Retrieve a list of account authorizations for the given developer key
33
+ #
34
+ # @return [HTTPI::Response] HTTP response object containing the SOAP XML response
35
+ def get_authorization_list(local_id=nil)
36
+ soap_response = client.request :get_authorization_list do
37
+ soap.header = soap_header
38
+ soap.body = {"localID" => local_id} if local_id
39
+ end
40
+
41
+ @last_request = client.http
42
+ @last_response = soap_response
43
+ end # get_authorization_list
44
+ end # self
45
+ end # AdminService
46
+ end # Services
47
+ end # ChannelAdvisor
@@ -0,0 +1,26 @@
1
+ module ChannelAdvisor
2
+ module Services
3
+ class BaseService
4
+ extend Savon::Model
5
+
6
+ class << self
7
+ attr_reader :last_request, :last_response
8
+
9
+ private
10
+
11
+ def soap_header
12
+ {
13
+ "ins0:APICredentials" => {
14
+ "ins0:DeveloperKey" => creds(:developer_key),
15
+ "ins0:Password" => creds(:password)
16
+ }
17
+ }
18
+ end
19
+
20
+ def creds(attribute)
21
+ ChannelAdvisor.configuration.send(attribute.to_sym)
22
+ end
23
+ end # self
24
+ end # BaseService
25
+ end # Services
26
+ end # ChannelAdvisor
@@ -0,0 +1,90 @@
1
+ module ChannelAdvisor
2
+ module Services
3
+ class InventoryService < BaseService
4
+ document "https://api.channeladvisor.com/ChannelAdvisorAPI/v6/InventoryService.asmx?WSDL"
5
+
6
+ class << self
7
+ def ping
8
+ client.request :ping do
9
+ soap.header = soap_header
10
+ end
11
+ end # ping
12
+
13
+ def update_inventory_item_quantity_and_price(sku, quantity_and_price_info)
14
+ soap_body = {
15
+ "ins0:accountID" => creds(:account_id),
16
+ "ins0:itemQuantityAndPrice" => {
17
+ "ins0:Sku" => sku
18
+ }
19
+ }
20
+
21
+ item_quantity_and_price = soap_body["ins0:itemQuantityAndPrice"]
22
+
23
+ if quantity_info = quantity_and_price_info[:quantity_info]
24
+ item_quantity_and_price["ins0:QuantityInfo"] = {
25
+ "ins0:UpdateType" => quantity_info[:update_type],
26
+ "ins0:Total" => quantity_info[:total]
27
+ }
28
+ end
29
+
30
+ if price_info = quantity_and_price_info[:price_info]
31
+ item_quantity_and_price["ins0:PriceInfo"] = {
32
+ "ins0:Cost" => price_info[:cost],
33
+ "ins0:RetailPrice" => price_info[:retail_price],
34
+ "ins0:StartingPrice" => price_info[:starting_price],
35
+ "ins0:ReservePrice" => price_info[:reserve_price],
36
+ "ins0:TakeItPrice" => price_info[:take_it_price],
37
+ "ins0:SecondChanceOfferPrice" => price_info[:second_chance_offer_price],
38
+ "ins0:StorePrice" => price_info[:store_price]
39
+ }
40
+ end
41
+
42
+ client.request :update_inventory_item_quantity_and_price do
43
+ soap.header = soap_header
44
+ soap.body = soap_body
45
+ end
46
+ end # update_inventory_item_quantity_and_price
47
+
48
+ def update_inventory_item_quantity_and_price_list(quantity_and_price_list)
49
+ soap_body = {
50
+ "ins0:accountID" => creds(:account_id),
51
+ "ins0:itemQuantityAndPriceList" => {
52
+ "ins0:InventoryItemQuantityAndPrice" => []
53
+ }
54
+ }
55
+
56
+ quantity_and_price_list.each do |item|
57
+ item_quantity_and_price = {"ins0:Sku" => item[:sku]}
58
+
59
+ if quantity_info = item[:quantity_info]
60
+ item_quantity_and_price["ins0:QuantityInfo"] = {
61
+ "ins0:UpdateType" => item[:quantity_info][:update_type],
62
+ "ins0:Total" => item[:quantity_info][:total]
63
+ }
64
+ end
65
+
66
+ if price_info = item[:price_info]
67
+ item_quantity_and_price["ins0:PriceInfo"] = {
68
+ "ins0:Cost" => price_info[:cost],
69
+ "ins0:RetailPrice" => price_info[:retail_price],
70
+ "ins0:StartingPrice" => price_info[:starting_price],
71
+ "ins0:ReservePrice" => price_info[:reserve_price],
72
+ "ins0:TakeItPrice" => price_info[:take_it_price],
73
+ "ins0:SecondChanceOfferPrice" => price_info[:second_chance_offer_price],
74
+ "ins0:StorePrice" => price_info[:store_price]
75
+ }
76
+ end
77
+
78
+ soap_body["ins0:itemQuantityAndPriceList"]["ins0:InventoryItemQuantityAndPrice"] << item_quantity_and_price
79
+ end
80
+
81
+
82
+ client.request :update_inventory_item_quantity_and_price_list do
83
+ soap.header = soap_header
84
+ soap.body = soap_body
85
+ end
86
+ end # update_inventory_item_quantity_and_price_list
87
+ end # self
88
+ end # InventoryService
89
+ end # Services
90
+ end # ChannelAdvisor