sheepla 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sheepla/version.rb +1 -1
  3. data/lib/sheepla.rb +37 -31
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba095070e93b0af664dfa673f64520719dab1ed3
4
- data.tar.gz: bf86e08c0f16f0149bcfd539eb2e98b7d731fa54
3
+ metadata.gz: 380c4cc89e9d22be4a5d055503045169a04175f7
4
+ data.tar.gz: ec1d4790e0657c7160928dd03a260a22377d9b65
5
5
  SHA512:
6
- metadata.gz: b4ab3f7588bb889ffaa3263f5887bcb69f662ccf26ed35fcb4db3007fa2ccd1be3ab3e03b52eeff0abda6a66dc2e9384822089c63f27588da60c0802214d3521
7
- data.tar.gz: a318f5ca6af2b7efba9af43f67c3e63145b91c7016c7fd2ddc0b9ccddfa839dd6d63e27d272dbfc435c11a825aad04e10ee087cf5accfc17aba5c9e4d3157b81
6
+ metadata.gz: 669000e3b01bd50812e1e95397fe8d2192a71185425607a5e71ed0ca6d88764e66e69f5fcd3bcf1309bf0d894847366fc18c6982d719e56980cf2cc2c0537054
7
+ data.tar.gz: 8666a7f481ed27e7a2a09f7c03c839e029a556e5fc0f5ed03966dbae10a757018b73c38ead5008a0f93a8338079994e568c5762c7e77cbfb51a6a666428b1805
@@ -1,3 +1,3 @@
1
1
  module Sheepla
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.clone.deep_stringify_keys
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.orderValue order['order_value']
89
- xml.orderValueCurrency order['order_currency']
90
- xml.externalDeliveryTypeId order['external_delivery_type_id']
91
- xml.externalDeliveryTypeName order['external_delivery_type_name']
92
- xml.externalPaymentTypeId order['external_payment_type_id']
93
- xml.externalPaymentTypeName order['external_payment_type_name']
94
- xml.externalCarrierName order['external_carrier_name']
95
- xml.externalCarrierId order['external_carrier_id']
96
- xml.externalCountryId order['external_country_id']
97
- xml.externalBuyerId order['external_buyer_id']
98
- xml.externalOrderId order['external_order_id']
99
- xml.shipmentTemplate order['shipment_template']
100
- xml.comments order['comments']
101
- xml.createdOn order['created_on'].to_s
102
- xml.deliveryPrice order['delivery_price']
103
- xml.deliveryPriceCurrency order['delivery_price_currency']
104
- xml.deliveryAddress do
105
- xml.street order['delivery_address']['street']
106
- xml.zipCode order['delivery_address']['zip_code']
107
- xml.city order['delivery_address']['city']
108
- xml.countryAlpha2Code order['delivery_address']['country_alpha2_code']
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'] &&
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sheepla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Jan Adamczyk