fulfil_api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fulfil_api/customer_shipment.rb +15 -26
- data/lib/fulfil_api/resource/persistable.rb +1 -8
- data/lib/fulfil_api/resource.rb +13 -0
- data/lib/fulfil_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68821bbca5de486309740ca1fec47352555b874dc0a2428dd9dc3663df7db063
|
4
|
+
data.tar.gz: 3b44214cf2330b643fbe50cb2d060e8e0cdfc3f0a7720bef47d2152955199407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 881c1beb39b7ccefcc45b41755f858345eaf28433d06f91249d4d221f7f82f09ff5b99cff6aef56d834a5a0bec18a2ac77aea4935ea0f4978cf4e3d0405a348d
|
7
|
+
data.tar.gz: 3a9645874ddc1394fbbc864c3da07432542a370e47a1a25e7117b9f0e6167d41609e61285933497c1640549b6ba0a8dd1efdf01fb1085d6d4174573444d16db2
|
@@ -10,20 +10,17 @@ module FulfilApi
|
|
10
10
|
# Sets the fulfillment status of the customer shipment on hold
|
11
11
|
#
|
12
12
|
# @param id_or_ids [String, Integer, Array[String], Array[Integer]] The ID(s) of the customer shipment(s) to hold.
|
13
|
-
# @param note [String] A note to define the reason for holding.
|
14
|
-
# @param hold_reason [String] An hold reason ID. (Optional)
|
13
|
+
# @param note [String] A note to define the reason for holding.
|
15
14
|
# @return [Boolean] Returns true if hold successfully.
|
16
15
|
# @raise [FulfilApi::Error] If an error occurs during holding the customer shipment.
|
17
16
|
#
|
18
17
|
# @example Hold a customer shipment
|
19
|
-
# FulfilApi::CustomerShipment.hold(123, note: "Double booking"
|
18
|
+
# FulfilApi::CustomerShipment.hold(123, note: "Double booking")
|
20
19
|
#
|
21
20
|
# @example Hold multipe customer shipments
|
22
|
-
# FulfilApi::CustomerShipment.hold([123, 456], note: "Double booking"
|
23
|
-
def hold!(id_or_ids, note:
|
24
|
-
FulfilApi.client.put("/model/#{MODEL_NAME}/hold",
|
25
|
-
body: [[*id_or_ids].flatten, { note: note, hold_reason: hold_reason }.compact_blank])
|
26
|
-
|
21
|
+
# FulfilApi::CustomerShipment.hold([123, 456], note: "Double booking")
|
22
|
+
def hold!(id_or_ids, note:)
|
23
|
+
FulfilApi.client.put("/model/#{MODEL_NAME}/hold", body: [[*id_or_ids].flatten, note])
|
27
24
|
true
|
28
25
|
end
|
29
26
|
|
@@ -40,25 +37,23 @@ module FulfilApi
|
|
40
37
|
#
|
41
38
|
# @example Unhold a customer shipment
|
42
39
|
# FulfilApi::CustomerShipment.unhold([123, 456], note: "All clear")
|
43
|
-
def unhold!(id_or_ids, note:
|
44
|
-
FulfilApi.client.put("/model/#{MODEL_NAME}/unhold", body: [[*id_or_ids].flatten,
|
45
|
-
|
40
|
+
def unhold!(id_or_ids, note:)
|
41
|
+
FulfilApi.client.put("/model/#{MODEL_NAME}/unhold", body: [[*id_or_ids].flatten, note])
|
46
42
|
true
|
47
43
|
end
|
48
44
|
end
|
49
45
|
|
50
46
|
# Sets the current customer shipment on hold, rescuing any errors that occur and handling them based on error type.
|
51
47
|
#
|
52
|
-
# @param note [String] A note to define the reason for holding.
|
53
|
-
# @param hold_reason [String] An hold reason ID. (Optional)
|
48
|
+
# @param note [String] A note to define the reason for holding.
|
54
49
|
# @return [Boolean] Returns true if hold successfully, otherwise false.
|
55
50
|
#
|
56
51
|
# @example Holds a customer_shipment
|
57
|
-
# customer_shipment.hold(
|
58
|
-
def hold(note
|
59
|
-
self.class.hold!(id, note: note
|
52
|
+
# customer_shipment.hold("Holding the shipment for 30 minutes to allow edits to the order")
|
53
|
+
def hold(note)
|
54
|
+
self.class.hold!(id, note: note)
|
60
55
|
rescue FulfilApi::Error => e
|
61
|
-
|
56
|
+
handle_exception(e)
|
62
57
|
false
|
63
58
|
end
|
64
59
|
|
@@ -68,18 +63,12 @@ module FulfilApi
|
|
68
63
|
# @return [Boolean] Returns true if unhold successfully, otherwise false.
|
69
64
|
#
|
70
65
|
# @example Unholds a customer_shipment
|
71
|
-
# customer_shipment.unhold(
|
72
|
-
def unhold(note
|
66
|
+
# customer_shipment.unhold("Ship out these items to the customer")
|
67
|
+
def unhold(note)
|
73
68
|
self.class.unhold!(id, note: note)
|
74
69
|
rescue FulfilApi::Error => e
|
75
|
-
|
70
|
+
handle_exception(e)
|
76
71
|
false
|
77
72
|
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def handle_error(err)
|
82
|
-
errors.add(code: err.details[:response_status], type: :system, message: err.details[:response_body])
|
83
|
-
end
|
84
73
|
end
|
85
74
|
end
|
@@ -52,14 +52,7 @@ module FulfilApi
|
|
52
52
|
def save
|
53
53
|
save!
|
54
54
|
rescue FulfilApi::Error => e
|
55
|
-
|
56
|
-
in { type: "UserError" }
|
57
|
-
errors.add(code: error[:code], type: :user, message: error[:message])
|
58
|
-
in { code: Integer, name: String, description: String }
|
59
|
-
errors.add(code: error[:code], type: :authorization, message: error[:description])
|
60
|
-
end
|
61
|
-
|
62
|
-
self
|
55
|
+
handle_exception(e)
|
63
56
|
end
|
64
57
|
|
65
58
|
# Saves the current resource, raising an error if it cannot be saved.
|
data/lib/fulfil_api/resource.rb
CHANGED
@@ -72,5 +72,18 @@ module FulfilApi
|
|
72
72
|
private
|
73
73
|
|
74
74
|
attr_reader :model_name
|
75
|
+
|
76
|
+
def handle_exception(exception) # rubocop:disable Metrics/AbcSize
|
77
|
+
case (error = JSON.parse(exception.details[:response_body]).deep_symbolize_keys!)
|
78
|
+
in { type: "UserError" }
|
79
|
+
errors.add(code: error[:code], type: :user, message: error[:message])
|
80
|
+
in { code: Integer, name: String, description: String }
|
81
|
+
errors.add(code: error[:code], type: :authorization, message: error[:description])
|
82
|
+
else
|
83
|
+
errors.add(code: exception.details[:response_status], type: :system, message: exception.details[:response_body])
|
84
|
+
end
|
85
|
+
|
86
|
+
self
|
87
|
+
end
|
75
88
|
end
|
76
89
|
end
|
data/lib/fulfil_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fulfil_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|