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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ccd627b64addcd5ce4600e1df832ee931f1e98ff686ab706760cfdbc02f654f
4
- data.tar.gz: 130cc96ccd064f08341c96b6ede9f06b5f86278d6dd0f3d2cccb8cbc36fb4a57
3
+ metadata.gz: f04dc7cd3bc75a9c2b2bc1d7cc36c247003fd0428e9c9a7d03ffc54831640429
4
+ data.tar.gz: cb488c9c266ddb1b346b5e055872918e59cdee4b6661daf055b95bc463dfca09
5
5
  SHA512:
6
- metadata.gz: 3597d97e005cf9ff18df541a96d8a3dd3348847f54fbf111b3999cebd1c7d77aea4df83d7ccfd9f5942278c0960a7267eeb79dd26f9d3e4dbad6414b4fb42360
7
- data.tar.gz: bb3384d9dc29b08531761d88107695d3b8a79591e23a2d00ef5fa8d06f58597559344cf1689a4b6c4561a647c40d15e3c86524adb7bc0b0ab5beecd970b46d83
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
- # Step 1: Get authentication token
37
- auth_client = Mintsoft::AuthClient.new
38
- token = auth_client.auth.authenticate("username", "password")
39
-
40
- # Step 2: Initialize client with token
41
- client = Mintsoft::Client.new(token: token)
42
-
43
- # Step 3: Search for orders
44
- orders = client.orders.search("ORD-2024-001")
45
- order = orders.first
46
-
47
- # Step 4: Get return reasons
48
- reasons = client.returns.reasons
49
- damage_reason = reasons.find { |r| r.name.include?("Damaged") && r.active? }
50
-
51
- # Step 5: Create return
52
- return_obj = client.returns.create(order.id)
53
-
54
- # Step 6: Add item to return
55
- result = client.returns.add_item(return_obj.id, {
56
- product_id: 123,
57
- quantity: 2,
58
- reason_id: damage_reason.id,
59
- unit_value: 25.00,
60
- notes: "Damaged in shipping"
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
- token = auth_client.auth.authenticate("username", "password")
74
- puts token # Direct token string
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
- result = client.returns.add_item(return_obj.id, {
116
- product_id: 123,
117
- quantity: 2,
118
- reason_id: reason_id,
119
- unit_value: 25.00,
120
- notes: "Optional notes"
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
@@ -18,6 +18,8 @@ module Mintsoft
18
18
  # Authentication and authorization errors
19
19
  class AuthenticationError < APIError; end
20
20
 
21
+ class ForbiddenError < APIError; end
22
+
21
23
  # Request validation errors
22
24
  class ValidationError < APIError; end
23
25
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mintsoft
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.12"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mintsoft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong