mintsoft 0.1.10 → 0.1.12
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/README.md +92 -39
- data/lib/mintsoft/errors.rb +2 -0
- data/lib/mintsoft/resources/base_resource.rb +5 -2
- data/lib/mintsoft/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f04dc7cd3bc75a9c2b2bc1d7cc36c247003fd0428e9c9a7d03ffc54831640429
|
4
|
+
data.tar.gz: cb488c9c266ddb1b346b5e055872918e59cdee4b6661daf055b95bc463dfca09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a329bf4a4a08129b09d3cf15f22e8e199b56218a747b0ef2007c8fa601913189df67a9b58fbb51d7d93ccad62609aa3cdf30ac043223b648d45983313e275060
|
7
|
+
data.tar.gz: ddd83252d8a4a3140cfce31220c687413b197100fcad8b864bf90dcd20b6e801780000a0f2b24246ed2f64183ef38ad5facd11d3dff330cd8afbdb563e79f2bf
|
data/README.md
CHANGED
@@ -33,32 +33,46 @@ Or install it yourself as:
|
|
33
33
|
```ruby
|
34
34
|
require 'mintsoft'
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
36
|
+
begin
|
37
|
+
# Step 1: Get authentication token
|
38
|
+
auth_client = Mintsoft::AuthClient.new
|
39
|
+
token = auth_client.auth.authenticate("username", "password")
|
40
|
+
|
41
|
+
# Step 2: Initialize client with token
|
42
|
+
client = Mintsoft::Client.new(token: token)
|
43
|
+
|
44
|
+
# Step 3: Search for orders
|
45
|
+
orders = client.orders.search("ORD-2024-001")
|
46
|
+
if orders.empty?
|
47
|
+
puts "No orders found"
|
48
|
+
return
|
49
|
+
end
|
50
|
+
order = orders.first
|
51
|
+
|
52
|
+
# Step 4: Get return reasons
|
53
|
+
reasons = client.returns.reasons
|
54
|
+
damage_reason = reasons.find { |r| r.name.include?("Damaged") && r.active? }
|
55
|
+
|
56
|
+
# Step 5: Create return
|
57
|
+
return_obj = client.returns.create(order.id)
|
58
|
+
|
59
|
+
# Step 6: Add item to return
|
60
|
+
result = client.returns.add_item(return_obj.id, {
|
61
|
+
product_id: 123,
|
62
|
+
quantity: 2,
|
63
|
+
reason_id: damage_reason.id,
|
64
|
+
unit_value: 25.00,
|
65
|
+
notes: "Damaged in shipping"
|
66
|
+
})
|
67
|
+
rescue Mintsoft::AuthClient::AuthenticationError => e
|
68
|
+
puts "Authentication failed: #{e.message}"
|
69
|
+
rescue Mintsoft::AuthenticationError => e
|
70
|
+
puts "Token expired: #{e.message}"
|
71
|
+
rescue Mintsoft::ForbiddenError => e
|
72
|
+
puts "Insufficient permissions: #{e.message}"
|
73
|
+
rescue Mintsoft::ValidationError => e
|
74
|
+
puts "Validation error: #{e.message}"
|
75
|
+
end
|
62
76
|
```
|
63
77
|
|
64
78
|
### API Reference
|
@@ -70,8 +84,16 @@ result = client.returns.add_item(return_obj.id, {
|
|
70
84
|
auth_client = Mintsoft::AuthClient.new
|
71
85
|
|
72
86
|
# Authenticate and get token
|
73
|
-
|
74
|
-
|
87
|
+
begin
|
88
|
+
token = auth_client.auth.authenticate("username", "password")
|
89
|
+
puts token # Direct token string
|
90
|
+
rescue Mintsoft::AuthClient::AuthenticationError => e
|
91
|
+
# Invalid credentials when getting auth token
|
92
|
+
puts "Auth failed: #{e.message}"
|
93
|
+
rescue Mintsoft::ValidationError => e
|
94
|
+
# Missing username or password
|
95
|
+
puts "Validation error: #{e.message}"
|
96
|
+
end
|
75
97
|
```
|
76
98
|
|
77
99
|
#### Client
|
@@ -93,6 +115,9 @@ client = Mintsoft::Client.new(
|
|
93
115
|
# Search for orders by order number
|
94
116
|
orders = client.orders.search("ORD-123")
|
95
117
|
|
118
|
+
# Retrieve specific order by ID
|
119
|
+
order = client.orders.retrieve(order_id)
|
120
|
+
|
96
121
|
# Access order properties
|
97
122
|
order = orders.first
|
98
123
|
puts order.id # Direct access to order ID
|
@@ -112,13 +137,18 @@ active_reasons = reasons.select(&:active?)
|
|
112
137
|
return_obj = client.returns.create(order_id)
|
113
138
|
|
114
139
|
# Add item to return
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
140
|
+
begin
|
141
|
+
result = client.returns.add_item(return_obj.id, {
|
142
|
+
product_id: 123,
|
143
|
+
quantity: 2,
|
144
|
+
reason_id: reason_id,
|
145
|
+
unit_value: 25.00,
|
146
|
+
notes: "Optional notes"
|
147
|
+
})
|
148
|
+
rescue Mintsoft::ForbiddenError => e
|
149
|
+
# This typically occurs when credentials don't have permission to add items to returns
|
150
|
+
puts "Permission denied: #{e.message}"
|
151
|
+
end
|
122
152
|
|
123
153
|
# Retrieve a specific return by ID
|
124
154
|
return_obj = client.returns.retrieve(return_id)
|
@@ -140,16 +170,21 @@ All error classes now include response context and status codes for better debug
|
|
140
170
|
begin
|
141
171
|
orders = client.orders.search("ORD-123")
|
142
172
|
rescue Mintsoft::AuthenticationError => e
|
143
|
-
# Token expired or invalid (401)
|
173
|
+
# Token expired or invalid (401) - for API resource calls
|
144
174
|
puts "Authentication failed: #{e.message}"
|
145
175
|
puts "Status: #{e.status_code}"
|
176
|
+
rescue Mintsoft::AuthClient::AuthenticationError => e
|
177
|
+
# Invalid credentials when getting auth token
|
178
|
+
puts "Auth client authentication failed: #{e.message}"
|
179
|
+
puts "Status: #{e.status_code}"
|
180
|
+
rescue Mintsoft::ForbiddenError => e
|
181
|
+
# Insufficient permissions (403) - typically when adding items to returns
|
182
|
+
puts "Insufficient permissions: #{e.message}"
|
183
|
+
puts "Status: #{e.status_code}"
|
146
184
|
rescue Mintsoft::ValidationError => e
|
147
185
|
# Invalid request data (400)
|
148
186
|
puts "Validation error: #{e.message}"
|
149
187
|
puts "Response: #{e.response.body if e.response}"
|
150
|
-
rescue Mintsoft::NotFoundError => e
|
151
|
-
# Resource not found (404)
|
152
|
-
puts "Not found: #{e.message}"
|
153
188
|
rescue Mintsoft::APIError => e
|
154
189
|
# General API error
|
155
190
|
puts "API error: #{e.message}"
|
@@ -157,6 +192,24 @@ rescue Mintsoft::APIError => e
|
|
157
192
|
end
|
158
193
|
```
|
159
194
|
|
195
|
+
### Not Found Behavior
|
196
|
+
|
197
|
+
When resources cannot be found, the gem returns `nil` instead of raising exceptions:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
# Search for orders - returns empty array if no orders found
|
201
|
+
orders = client.orders.search("NONEXISTENT-ORDER")
|
202
|
+
puts orders.empty? # true
|
203
|
+
|
204
|
+
# Retrieve specific order - returns nil if not found
|
205
|
+
order = client.orders.retrieve(99999)
|
206
|
+
puts order.nil? # true
|
207
|
+
|
208
|
+
# Retrieve specific return - returns nil if not found
|
209
|
+
return_obj = client.returns.retrieve(99999)
|
210
|
+
puts return_obj.nil? # true
|
211
|
+
```
|
212
|
+
|
160
213
|
### Object Methods
|
161
214
|
|
162
215
|
#### Order Objects
|
data/lib/mintsoft/errors.rb
CHANGED
@@ -36,6 +36,7 @@ module Mintsoft
|
|
36
36
|
error_class = case response.status
|
37
37
|
when 400 then ValidationError
|
38
38
|
when 401 then AuthenticationError
|
39
|
+
when 403 then ForbiddenError
|
39
40
|
else APIError
|
40
41
|
end
|
41
42
|
|
@@ -45,10 +46,12 @@ module Mintsoft
|
|
45
46
|
|
46
47
|
def build_error_message(status, error_message)
|
47
48
|
case status
|
48
|
-
when 401
|
49
|
-
"Invalid or expired token"
|
50
49
|
when 400
|
51
50
|
"Invalid request data: #{error_message}"
|
51
|
+
when 401
|
52
|
+
"Invalid or expired token"
|
53
|
+
when 403
|
54
|
+
"Insufficient permissions"
|
52
55
|
else
|
53
56
|
"API error: #{status} - #{error_message}"
|
54
57
|
end
|
data/lib/mintsoft/version.rb
CHANGED