sheepla 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sheepla/version.rb +1 -1
- data/lib/sheepla.rb +37 -31
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 380c4cc89e9d22be4a5d055503045169a04175f7
|
4
|
+
data.tar.gz: ec1d4790e0657c7160928dd03a260a22377d9b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 669000e3b01bd50812e1e95397fe8d2192a71185425607a5e71ed0ca6d88764e66e69f5fcd3bcf1309bf0d894847366fc18c6982d719e56980cf2cc2c0537054
|
7
|
+
data.tar.gz: 8666a7f481ed27e7a2a09f7c03c839e029a556e5fc0f5ed03966dbae10a757018b73c38ead5008a0f93a8338079994e568c5762c7e77cbfb51a6a666428b1805
|
data/lib/sheepla/version.rb
CHANGED
data/lib/sheepla.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'uri'
|
4
4
|
require 'nokogiri'
|
5
|
-
require 'ostruct'
|
6
5
|
|
7
6
|
module Sheepla
|
8
7
|
class ApiError < StandardError; end
|
@@ -17,7 +16,8 @@ module Sheepla
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def create_order(params)
|
20
|
-
order = params.
|
19
|
+
order = params.deep_transform_keys{ |key| key.to_s.camelize(:lower) }
|
20
|
+
|
21
21
|
raise ApiError.new("Order parameters don't contain all obligatory keys") unless validate_order(order)
|
22
22
|
|
23
23
|
connection('createOrder')
|
@@ -85,40 +85,40 @@ module Sheepla
|
|
85
85
|
body_wrapper('createOrderRequest') do |xml|
|
86
86
|
xml.orders do
|
87
87
|
xml.order do
|
88
|
-
xml
|
89
|
-
xml.
|
90
|
-
xml.
|
91
|
-
xml
|
92
|
-
xml.
|
93
|
-
xml.
|
94
|
-
xml.
|
95
|
-
xml.
|
96
|
-
xml.
|
97
|
-
xml.
|
98
|
-
xml.
|
99
|
-
xml.
|
100
|
-
xml.
|
101
|
-
xml.
|
102
|
-
xml.
|
103
|
-
xml.
|
104
|
-
xml.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
xml.firstName order['delivery_address']['first_name']
|
110
|
-
xml.lastName order['delivery_address']['last_name']
|
111
|
-
xml.companyName order['delivery_address']['company_name']
|
112
|
-
xml.phone order['delivery_address']['phone']
|
113
|
-
xml.email order['delivery_address']['email']
|
114
|
-
end
|
115
|
-
add_order_items(xml, order['order_items'])
|
116
|
-
add_delivery_options(xml, order['delivery_options']) if order['delivery_options']
|
88
|
+
add_delivery_address(xml, order.delete('deliveryAddress'))
|
89
|
+
add_order_items(xml, order.delete('orderItems')) if order['orderItems']
|
90
|
+
add_delivery_options(xml, order.delete('deliveryOptions')) if order['deliveryOptions']
|
91
|
+
add_other_order_data(xml, order)
|
92
|
+
# xml.orderValue order['order_value']
|
93
|
+
# xml.orderValueCurrency order['order_currency']
|
94
|
+
# xml.externalDeliveryTypeId order['external_delivery_type_id']
|
95
|
+
# xml.externalDeliveryTypeName order['external_delivery_type_name']
|
96
|
+
# xml.externalPaymentTypeId order['external_payment_type_id']
|
97
|
+
# xml.externalPaymentTypeName order['external_payment_type_name']
|
98
|
+
# xml.externalCarrierName order['external_carrier_name']
|
99
|
+
# xml.externalCarrierId order['external_carrier_id']
|
100
|
+
# xml.externalCountryId order['external_country_id']
|
101
|
+
# xml.externalBuyerId order['external_buyer_id']
|
102
|
+
# xml.externalOrderId order['external_order_id']
|
103
|
+
# xml.shipmentTemplate order['shipment_template']
|
104
|
+
# xml.comments order['comments']
|
105
|
+
# xml.createdOn order['created_on'].to_s
|
106
|
+
# xml.deliveryPrice order['delivery_price']
|
107
|
+
# xml.deliveryPriceCurrency order['delivery_price_currency']
|
108
|
+
|
117
109
|
end
|
118
110
|
end
|
119
111
|
end
|
120
112
|
end
|
121
113
|
|
114
|
+
def add_delivery_address(xml, delivery_address)
|
115
|
+
xml.deliveryAddress do
|
116
|
+
delivery_address.each do |delivery_key, delivery_value|
|
117
|
+
xml.send(delivery_key, delivery_value)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
122
|
def add_order_items(xml, order_items)
|
123
123
|
xml.orderItems do
|
124
124
|
order_items.each do |order_item|
|
@@ -145,6 +145,12 @@ module Sheepla
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
def add_other_order_data(xml, order_data)
|
149
|
+
order_data.each do |k,v|
|
150
|
+
xml.send(k, v)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
148
154
|
def validate_order(params)
|
149
155
|
params['order_value'] &&
|
150
156
|
params['order_currency'] &&
|