plenty_client 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +9 -36
- data/Rakefile +3 -3
- data/lib/plenty_client.rb +8 -5
- data/lib/plenty_client/accounting.rb +2 -2
- data/lib/plenty_client/authentication.rb +2 -2
- data/lib/plenty_client/authorization.rb +2 -2
- data/lib/plenty_client/basket.rb +2 -2
- data/lib/plenty_client/basket/item.rb +2 -2
- data/lib/plenty_client/category.rb +6 -7
- data/lib/plenty_client/category/branch.rb +2 -2
- data/lib/plenty_client/category/template.rb +3 -3
- data/lib/plenty_client/comment.rb +3 -3
- data/lib/plenty_client/config.rb +3 -1
- data/lib/plenty_client/endpoint.rb +74 -68
- data/lib/plenty_client/item.rb +7 -2
- data/lib/plenty_client/item/attribute.rb +3 -3
- data/lib/plenty_client/item/attribute/name.rb +12 -20
- data/lib/plenty_client/item/attribute/value.rb +13 -18
- data/lib/plenty_client/item/attribute/value_name.rb +12 -12
- data/lib/plenty_client/item/barcode.rb +3 -3
- data/lib/plenty_client/item/cross_selling.rb +3 -3
- data/lib/plenty_client/item/image.rb +6 -6
- data/lib/plenty_client/item/image/availability.rb +10 -10
- data/lib/plenty_client/item/image/name.rb +14 -24
- data/lib/plenty_client/item/manufacturer.rb +4 -4
- data/lib/plenty_client/item/manufacturer/commission.rb +3 -3
- data/lib/plenty_client/item/property.rb +3 -3
- data/lib/plenty_client/item/property/market_reference.rb +11 -11
- data/lib/plenty_client/item/property/name.rb +12 -17
- data/lib/plenty_client/item/property_group.rb +3 -3
- data/lib/plenty_client/item/property_group_name.rb +8 -10
- data/lib/plenty_client/item/sales_price.rb +3 -4
- data/lib/plenty_client/item/shipping_profile.rb +6 -6
- data/lib/plenty_client/item/unit.rb +3 -4
- data/lib/plenty_client/item/unit_name.rb +12 -11
- data/lib/plenty_client/item/variation.rb +10 -4
- data/lib/plenty_client/item/variation/barcode.rb +3 -3
- data/lib/plenty_client/item/variation/bundle.rb +14 -16
- data/lib/plenty_client/item/variation/category.rb +8 -10
- data/lib/plenty_client/item/variation/client.rb +3 -3
- data/lib/plenty_client/item/variation/default_category.rb +3 -3
- data/lib/plenty_client/item/variation/description.rb +3 -3
- data/lib/plenty_client/item/variation/image.rb +5 -4
- data/lib/plenty_client/item/variation/market.rb +3 -3
- data/lib/plenty_client/item/variation/market_ident_number.rb +3 -3
- data/lib/plenty_client/item/variation/sales_price.rb +13 -17
- data/lib/plenty_client/item/variation/sku.rb +12 -15
- data/lib/plenty_client/item/variation/stock.rb +3 -3
- data/lib/plenty_client/item/variation/supplier.rb +12 -15
- data/lib/plenty_client/item/variation/warehouse.rb +6 -5
- data/lib/plenty_client/item/variation_property.rb +3 -3
- data/lib/plenty_client/item/variation_property_value.rb +10 -14
- data/lib/plenty_client/item_set.rb +4 -4
- data/lib/plenty_client/item_set/component.rb +15 -22
- data/lib/plenty_client/item_set/config.rb +3 -2
- data/lib/plenty_client/order.rb +5 -4
- data/lib/plenty_client/order/contact_wish.rb +2 -3
- data/lib/plenty_client/order/coupon_code.rb +5 -7
- data/lib/plenty_client/order/coupon_code/contact.rb +4 -6
- data/lib/plenty_client/order/coupon_code/validation.rb +4 -6
- data/lib/plenty_client/order/currency.rb +2 -3
- data/lib/plenty_client/order/date.rb +3 -4
- data/lib/plenty_client/order/item.rb +3 -3
- data/lib/plenty_client/order/item/date.rb +2 -2
- data/lib/plenty_client/order/item/property.rb +2 -2
- data/lib/plenty_client/order/item/serial_number.rb +3 -3
- data/lib/plenty_client/order/property.rb +2 -3
- data/lib/plenty_client/order/referrer.rb +2 -3
- data/lib/plenty_client/order/shipping.rb +2 -3
- data/lib/plenty_client/order/shipping/country.rb +2 -2
- data/lib/plenty_client/order/shipping/information.rb +3 -3
- data/lib/plenty_client/order/shipping/package.rb +4 -4
- data/lib/plenty_client/order/shipping/profile.rb +2 -2
- data/lib/plenty_client/order/shipping/service_provider.rb +2 -2
- data/lib/plenty_client/request.rb +121 -98
- data/lib/plenty_client/sales_price/account.rb +2 -3
- data/lib/plenty_client/sales_price/country.rb +2 -2
- data/lib/plenty_client/sales_price/currency.rb +2 -2
- data/lib/plenty_client/sales_price/customer_class.rb +2 -2
- data/lib/plenty_client/sales_price/name.rb +4 -4
- data/lib/plenty_client/sales_price/online_store.rb +2 -3
- data/lib/plenty_client/sales_price/referrer.rb +3 -2
- data/lib/plenty_client/version.rb +1 -1
- metadata +2 -2
@@ -1,8 +1,9 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module ItemSet
|
3
3
|
class Config
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
|
+
|
6
7
|
FIND_ITEM_SET_CONFIGS = '/item_sets/{itemSetId}/config'.freeze
|
7
8
|
UPDATE_ITEM_SET_CONFIGS = '/item_sets/{itemSetId}/config'.freeze
|
8
9
|
|
data/lib/plenty_client/order.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
|
-
|
4
|
-
|
3
|
+
include PlentyClient::Endpoint
|
4
|
+
include PlentyClient::Request
|
5
5
|
|
6
6
|
CREATE_ORDER = '/orders'.freeze
|
7
7
|
LIST_ORDERS = '/orders'.freeze
|
@@ -23,7 +23,8 @@ module PlentyClient
|
|
23
23
|
def list_contacts_orders(contact_id, headers = {}, &block)
|
24
24
|
get(build_endpoint(LIST_CONTACTS_ORDERS, contact: contact_id), headers, &block)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
def list_package_numbers(order_id, headers = {}, &block)
|
27
28
|
get(build_endpoint(LIST_ORDERS_PACKAGE_NUMBERS, order: order_id), headers, &block)
|
28
29
|
end
|
29
30
|
|
@@ -35,7 +36,7 @@ module PlentyClient
|
|
35
36
|
put(build_endpoint(UPDATE_ORDER, order: order_id), body)
|
36
37
|
end
|
37
38
|
|
38
|
-
def
|
39
|
+
def destroy(order_id, body = {})
|
39
40
|
delete(build_endpoint(DELETE_ORDER, order: order_id), body)
|
40
41
|
end
|
41
42
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
3
|
module ContactWish
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
6
|
|
7
7
|
FIND_ORDER_COTACT_WISH = '/orders/{orderId}/contactWish'.freeze
|
8
8
|
|
@@ -14,4 +14,3 @@ module PlentyClient
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
@@ -1,19 +1,17 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
3
|
module CouponCode
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
6
|
|
7
|
-
UPDATE_COUPON_CODE
|
7
|
+
UPDATE_COUPON_CODE = '/orders/{orderId}/coupons/{coupon}'.freeze
|
8
8
|
|
9
9
|
class << self
|
10
10
|
def update(order_id, coupon_string, headers = {}, &block)
|
11
|
-
post(build_endpoint(UPDATE_COUPON_CODE,
|
12
|
-
|
13
|
-
coupon_string: coupon_string), headers, &block)
|
11
|
+
post(build_endpoint(UPDATE_COUPON_CODE, order: order_id, coupon_string: coupon_string),
|
12
|
+
headers, &block)
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
19
|
-
|
@@ -2,19 +2,17 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module CouponCode
|
4
4
|
class Contact
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
|
-
LIST_COUPON_CONTACTS
|
8
|
+
LIST_COUPON_CONTACTS = '/orders/coupons/codes/contacts/{contactId}'.freeze
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def update(contact_id, headers = {}, &block)
|
12
|
-
post(build_endpoint(LIST_COUPON_CONTACTS,
|
13
|
-
contact: contact_id), headers, &block)
|
12
|
+
post(build_endpoint(LIST_COUPON_CONTACTS, contact: contact_id), headers, &block)
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
@@ -2,19 +2,17 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module CouponCode
|
4
4
|
class Validation
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
|
-
VALIDATE_COUPON
|
8
|
+
VALIDATE_COUPON = '/orders/coupons/codes/{coupon}'.freeze
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def update(coupon_string, headers = {}, &block)
|
12
|
-
post(build_endpoint(VALIDATE_COUPON,
|
13
|
-
coupon_string: coupon_string), headers, &block)
|
12
|
+
post(build_endpoint(VALIDATE_COUPON, coupon_string: coupon_string), headers, &block)
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
3
|
class Currency
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
6
|
|
7
7
|
LIST_CURRENCIES = '/orders/currencies'.freeze
|
8
8
|
FIND_CURRENCY_ISO = '/orders/currencies/{currencyIso}'.freeze
|
@@ -29,4 +29,3 @@ module PlentyClient
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
3
|
class Date
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
6
|
|
7
7
|
LIST_ORDER_DATE_TYPE_NAMES = '/orders/dates/types/{typeId}/names'.freeze
|
8
8
|
FIND_ORDER_DATE_TYPE_NAME = '/orders/dates/types/{typeId}/names/{lang}'.freeze
|
@@ -18,7 +18,7 @@ module PlentyClient
|
|
18
18
|
get(build_endpoint(FIND_ORDER_DATE_TYPE_NAME, type: type_id, lang: lang), headers, &block)
|
19
19
|
end
|
20
20
|
|
21
|
-
def list(
|
21
|
+
def list(order_id, headers = {}, &block)
|
22
22
|
get(build_endpoint(LIST_ORDER_DATES, order: order_id), headers, &block)
|
23
23
|
end
|
24
24
|
|
@@ -29,4 +29,3 @@ module PlentyClient
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
3
|
module Item
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
6
|
|
7
7
|
DELETE_ORDERS_ORDER_ITEM = '/orders/{orderId}/items/{orderItemId}'.freeze
|
8
8
|
|
9
9
|
class << self
|
10
|
-
def
|
10
|
+
def destroy(order_id, order_item_id)
|
11
11
|
delete(build_endpoint(DELETE_ORDERS_ORDER_ITEM,
|
12
12
|
order: order_id,
|
13
13
|
order_item: order_item_id))
|
@@ -2,8 +2,8 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Item
|
4
4
|
class Date
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
# get /orders/items/{orderItemId}/dates
|
9
9
|
# get /orders/items/{orderItemId}/dates/{typeId}
|
@@ -2,8 +2,8 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Item
|
4
4
|
class Property
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
# get /orders/items/{orderItemId}/properties
|
9
9
|
# get /orders/items/{orderItemId}/properties/{typeId}
|
@@ -2,12 +2,12 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Item
|
4
4
|
class SerialNumber
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
LIST_SERIAL_NUMBERS = '/orders/{orderId}/items/serialNumbers'.freeze
|
9
9
|
LIST_ORDER_ITEM_SERIAL_NUMBERS = '/orders/{orderId}/items/{orderItemId}/serialNumbers'.freeze
|
10
|
-
|
10
|
+
|
11
11
|
class << self
|
12
12
|
def list(order_id, headers = {}, &block)
|
13
13
|
get(build_endpoint(LIST_SERIAL_NUMBERS, order: order_id), headers, &block)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
3
|
class Property
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
6
|
|
7
7
|
# get /rest/orders/{orderId}/properties/{typeId?}
|
8
8
|
# post /rest/orders/{orderId}/properties
|
@@ -18,4 +18,3 @@ module PlentyClient
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module PlentyClient
|
2
2
|
module Order
|
3
3
|
class Referrer
|
4
|
-
|
5
|
-
|
4
|
+
include PlentyClient::Endpoint
|
5
|
+
include PlentyClient::Request
|
6
6
|
|
7
7
|
LIST_REFERRERS = '/orders/referrers'.freeze
|
8
8
|
CREATE_ORDER_REFERRER = '/orders/referrers/{parentReferrerId}'.freeze
|
@@ -19,4 +19,3 @@ module PlentyClient
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
@@ -2,8 +2,8 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Shipping
|
4
4
|
class Country
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
LIST_SHIPPING_COUNTRIES = '/orders/shipping/countries'.freeze
|
9
9
|
|
@@ -2,8 +2,8 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Shipping
|
4
4
|
class Information
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
BASE_ORDERS_SHIPPING_INFORMATION_PATH = '/orders/{orderId}/shipping'.freeze
|
9
9
|
|
@@ -34,7 +34,7 @@ module PlentyClient
|
|
34
34
|
order: order_id), body)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def destroy(order_id, body = {})
|
38
38
|
delete(build_endpoint("#{BASE_ORDERS_SHIPPING_INFORMATION_PATH}#{DELETE_ORDER_SHIPPING_INFORMATION}",
|
39
39
|
order: order_id), body)
|
40
40
|
end
|
@@ -2,8 +2,8 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Shipping
|
4
4
|
class Package
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
BASE_ORDERS_SHIPPING_PATH = '/orders/{orderId}/shipping'.freeze
|
9
9
|
|
@@ -37,13 +37,13 @@ module PlentyClient
|
|
37
37
|
shipping_package: package_id), body)
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
40
|
+
def destroy(order_id, package_id, body = {})
|
41
41
|
delete(build_endpoint("#{BASE_ORDERS_SHIPPING_PATH}#{DELETE_ORDER_SHIPPING_PACKAGE}",
|
42
42
|
order: order_id,
|
43
43
|
shipping_package: package_id), body)
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def destroy_all(order_id, body = {})
|
47
47
|
delete(build_endpoint("#{BASE_ORDERS_SHIPPING_PATH}#{DELETE_ORDER_SHIPPING_PACKAGES}",
|
48
48
|
order: order_id), body)
|
49
49
|
end
|
@@ -2,8 +2,8 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Shipping
|
4
4
|
class Profile
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
LIST_SHIPPING_PRESET = '/orders/shipping/presets'.freeze
|
9
9
|
FIND_SHIPPING_PRESETS = '/orders/shipping/presets/{presetId}'.freeze
|
@@ -2,8 +2,8 @@ module PlentyClient
|
|
2
2
|
module Order
|
3
3
|
module Shipping
|
4
4
|
class ServiceProvider
|
5
|
-
|
6
|
-
|
5
|
+
include PlentyClient::Endpoint
|
6
|
+
include PlentyClient::Request
|
7
7
|
|
8
8
|
BASE_ORDERS_SHIPPING_SERVICE_PROVIDER_PATH = '/orders/shipping'.freeze
|
9
9
|
|
@@ -1,125 +1,148 @@
|
|
1
1
|
require 'curl'
|
2
2
|
module PlentyClient
|
3
3
|
module Request
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
login if PlentyClient::Config.access_token.nil?
|
9
|
-
start_time = Time.now
|
10
|
-
response = perform(http_method, path, params)
|
11
|
-
body = parse_body(response, http_method, path, params)
|
12
|
-
log_output(http_method, base_url(path), params, time_diff_ms(start_time, Time.now)) if PlentyClient::Config.log
|
13
|
-
body
|
14
|
-
end
|
4
|
+
module ClassMethods
|
5
|
+
def request(http_method, path, params = {})
|
6
|
+
return false if http_method.nil? || path.nil?
|
7
|
+
return false unless %w[post put patch delete get].include?(http_method.to_s)
|
15
8
|
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
if PlentyClient::Config.access_token.nil? || time_diff_ms(Time.now, PlentyClient::Config.expiry_date).negative?
|
10
|
+
login_check
|
11
|
+
end
|
12
|
+
start_time = Time.now
|
13
|
+
response = perform(http_method, path, params)
|
14
|
+
body = parse_body(response, http_method, path, params)
|
15
|
+
log_output(http_method, base_url(path), params, time_diff_ms(start_time, Time.now)) if PlentyClient::Config.log
|
16
|
+
body
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def post(path, body = {})
|
20
|
+
request(:post, path, body)
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def put(path, body = {})
|
24
|
+
request(:put, path, body)
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def patch(path, body = {})
|
28
|
+
request(:patch, path, body)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
31
|
+
def delete(path, body = {})
|
32
|
+
request(:delete, path, body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get(path, params = {}, &block)
|
36
|
+
page = 1
|
37
|
+
rval_array = []
|
38
|
+
if block_given?
|
39
|
+
loop do
|
40
|
+
response = request(:get, path, params.merge(page: page))
|
41
|
+
yield response['entries'] if block_given?
|
42
|
+
page += 1
|
43
|
+
break if response['isLastPage'] == true
|
44
|
+
end
|
45
|
+
else
|
46
|
+
rval_array = request(:get, path, params.merge(page: page))
|
41
47
|
end
|
42
|
-
|
43
|
-
rval_array
|
48
|
+
return rval_array.flatten if rval_array.is_a?(Array)
|
49
|
+
rval_array
|
44
50
|
end
|
45
|
-
rval_array.flatten
|
46
|
-
end
|
47
51
|
|
48
|
-
|
52
|
+
private
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def login_check
|
55
|
+
url = "/login?username=#{PlentyClient::Config.api_user}&password=#{PlentyClient::Config.api_password}"
|
56
|
+
response = perform(:post, url)
|
57
|
+
result = parse_body(response, :post, 'login')
|
58
|
+
PlentyClient::Config.access_token = result['accessToken']
|
59
|
+
PlentyClient::Config.refresh_token = result['refreshToken']
|
60
|
+
PlentyClient::Config.expiry_date = Time.now + result['expiresIn']
|
61
|
+
end
|
57
62
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
def perform(http_method, path, params = {})
|
64
|
+
case http_method.to_s.downcase
|
65
|
+
when 'get'
|
66
|
+
Curl.get(base_url(path), params) do |curl|
|
67
|
+
curl_options(curl)
|
68
|
+
end
|
69
|
+
when 'post'
|
70
|
+
Curl.post(base_url(path), params.to_json) do |curl|
|
71
|
+
curl_options(curl)
|
72
|
+
end
|
73
|
+
when 'put'
|
74
|
+
Curl.put(base_url(path), params.to_json) do |curl|
|
75
|
+
curl_options(curl)
|
76
|
+
end
|
77
|
+
when 'delete'
|
78
|
+
Curl.delete(base_url(path), params) do |curl|
|
79
|
+
curl_options(curl)
|
80
|
+
end
|
81
|
+
when 'patch'
|
82
|
+
Curl.patch(base_url(path), params.to_json) do |curl|
|
83
|
+
curl_options(curl)
|
84
|
+
end
|
63
85
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
curl_options(curl)
|
71
|
-
end
|
72
|
-
when 'delete'
|
73
|
-
Curl.delete(base_url(path), params) do |curl|
|
74
|
-
curl_options(curl)
|
75
|
-
end
|
76
|
-
when 'patch'
|
77
|
-
Curl.patch(base_url(path), params) do |curl|
|
78
|
-
curl_options(curl)
|
86
|
+
end
|
87
|
+
|
88
|
+
def curl_options(curl)
|
89
|
+
curl.headers['Content-type'] = 'application/json'
|
90
|
+
unless PlentyClient::Config.access_token.nil?
|
91
|
+
curl.headers['Authorization'] = "Bearer #{PlentyClient::Config.access_token}"
|
79
92
|
end
|
93
|
+
curl.headers['Accept'] = 'application/x.plentymarkets.v1+json'
|
94
|
+
curl
|
80
95
|
end
|
81
|
-
end
|
82
96
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
97
|
+
def base_url(path)
|
98
|
+
uri = URI(PlentyClient::Config.site_url)
|
99
|
+
url = "#{uri.scheme}://#{uri.host}/rest"
|
100
|
+
url += path.start_with?('/') ? path : "/#{path}"
|
101
|
+
url
|
87
102
|
end
|
88
|
-
curl.headers['Accept'] = 'application/x.plentymarkets.v1+json'
|
89
|
-
curl
|
90
|
-
end
|
91
103
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
104
|
+
def parse_body(response, http_method, rest_path, params = {})
|
105
|
+
result = JSON.parse(response.body)
|
106
|
+
errors = error_check(result)
|
107
|
+
unless errors.blank?
|
108
|
+
raise PlentyClient::ResponseError, [*errors].join(', ')
|
109
|
+
log_output(http_method, path, params, '')
|
110
|
+
end
|
111
|
+
result
|
112
|
+
end
|
98
113
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
false
|
103
|
-
end
|
114
|
+
def log_output(http_method, path, params, duration)
|
115
|
+
puts [Time.now, "#{duration} ms", http_method.upcase, path, params].join(' # ')
|
116
|
+
end
|
104
117
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
result
|
109
|
-
end
|
118
|
+
def time_diff_ms(start, finish)
|
119
|
+
((finish - start) * 1000.0).round(2)
|
120
|
+
end
|
110
121
|
|
111
|
-
|
112
|
-
|
113
|
-
|
122
|
+
def error_check(response)
|
123
|
+
rval = []
|
124
|
+
return rval if response.blank?
|
125
|
+
if response.is_a?(Array) && response.first.key?('error')
|
126
|
+
response.each do |res|
|
127
|
+
rval << extract_message(res)
|
128
|
+
end
|
129
|
+
elsif response.is_a?(Hash) && response.key?('error')
|
130
|
+
rval << extract_message(response)
|
131
|
+
end
|
132
|
+
rval
|
133
|
+
end
|
114
134
|
|
115
|
-
|
116
|
-
|
135
|
+
def extract_message(response)
|
136
|
+
if response.key?('validation_errors') && !response['validation_errors'].blank?
|
137
|
+
response['validation_errors'].values.flatten.join(', ')
|
138
|
+
else
|
139
|
+
response['error']['message']
|
140
|
+
end
|
141
|
+
end
|
117
142
|
end
|
118
|
-
end
|
119
|
-
end
|
120
143
|
|
121
|
-
|
122
|
-
|
123
|
-
|
144
|
+
def self.included(base)
|
145
|
+
base.extend(ClassMethods)
|
146
|
+
end
|
124
147
|
end
|
125
148
|
end
|