mintsoft 0.1.9 → 0.1.11

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: 9b07eb48344fbc2e9350b4dfb180155f25849e2e07b6918089b577436b156ea3
4
- data.tar.gz: a41f333869f6cee4e8e662aaf227fa10b4ae91221ccfb18df1140b42e7a09ff7
3
+ metadata.gz: 193f53b2dad0b19c81c5eb571928dde974fd46fe02f096b6093a33119528b074
4
+ data.tar.gz: 6968738d3114be16799ffd322fcecf8d4500cc913c5b557fd01c8694bc9271d9
5
5
  SHA512:
6
- metadata.gz: 070433bc3da2e1357514c4aa98a0b7daea60e05403077beca76f9e7910cc1548d2ca6f71e7b8ee37db34a035def363ee793f9d27dab22a74e936bb93e2a1d842
7
- data.tar.gz: 2e9a745d24b126e9bdf6a21b3bfddfe6fcc944683f323ed8c715b2a4c903cfd1be7b9dea7be2cfae954ca8d9b3a734d0efc4fbc66603f0208f0cd82772cc10ce
6
+ metadata.gz: 36a1196c64c41022aa01ff352fb4ae13e0d100937f864cd8cc2ad965439dea86c435f89e92fee2332e4725ed1f87bba64299b837fa188ec88e32e6823abafab5
7
+ data.tar.gz: bb75d0cca832ea9e1f5f9a017587dbb45d20685fdffc1656952abfca76954dba7ea55deb04b54a55c2e2dd3f256f1097df5e10f990a10e28b10f8af1f564a137
data/README.md CHANGED
@@ -33,32 +33,44 @@ 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::ValidationError => e
72
+ puts "Validation error: #{e.message}"
73
+ end
62
74
  ```
63
75
 
64
76
  ### API Reference
@@ -70,8 +82,16 @@ result = client.returns.add_item(return_obj.id, {
70
82
  auth_client = Mintsoft::AuthClient.new
71
83
 
72
84
  # Authenticate and get token
73
- token = auth_client.auth.authenticate("username", "password")
74
- puts token # Direct token string
85
+ begin
86
+ token = auth_client.auth.authenticate("username", "password")
87
+ puts token # Direct token string
88
+ rescue Mintsoft::AuthClient::AuthenticationError => e
89
+ # Invalid credentials when getting auth token
90
+ puts "Auth failed: #{e.message}"
91
+ rescue Mintsoft::ValidationError => e
92
+ # Missing username or password
93
+ puts "Validation error: #{e.message}"
94
+ end
75
95
  ```
76
96
 
77
97
  #### Client
@@ -93,6 +113,9 @@ client = Mintsoft::Client.new(
93
113
  # Search for orders by order number
94
114
  orders = client.orders.search("ORD-123")
95
115
 
116
+ # Retrieve specific order by ID
117
+ order = client.orders.retrieve(order_id)
118
+
96
119
  # Access order properties
97
120
  order = orders.first
98
121
  puts order.id # Direct access to order ID
@@ -140,16 +163,17 @@ All error classes now include response context and status codes for better debug
140
163
  begin
141
164
  orders = client.orders.search("ORD-123")
142
165
  rescue Mintsoft::AuthenticationError => e
143
- # Token expired or invalid (401)
166
+ # Token expired or invalid (401) - for API resource calls
144
167
  puts "Authentication failed: #{e.message}"
145
168
  puts "Status: #{e.status_code}"
169
+ rescue Mintsoft::AuthClient::AuthenticationError => e
170
+ # Invalid credentials when getting auth token
171
+ puts "Auth client authentication failed: #{e.message}"
172
+ puts "Status: #{e.status_code}"
146
173
  rescue Mintsoft::ValidationError => e
147
174
  # Invalid request data (400)
148
175
  puts "Validation error: #{e.message}"
149
176
  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
177
  rescue Mintsoft::APIError => e
154
178
  # General API error
155
179
  puts "API error: #{e.message}"
@@ -157,6 +181,24 @@ rescue Mintsoft::APIError => e
157
181
  end
158
182
  ```
159
183
 
184
+ ### Not Found Behavior
185
+
186
+ When resources cannot be found, the gem returns `nil` instead of raising exceptions:
187
+
188
+ ```ruby
189
+ # Search for orders - returns empty array if no orders found
190
+ orders = client.orders.search("NONEXISTENT-ORDER")
191
+ puts orders.empty? # true
192
+
193
+ # Retrieve specific order - returns nil if not found
194
+ order = client.orders.retrieve(99999)
195
+ puts order.nil? # true
196
+
197
+ # Retrieve specific return - returns nil if not found
198
+ return_obj = client.returns.retrieve(99999)
199
+ puts return_obj.nil? # true
200
+ ```
201
+
160
202
  ### Object Methods
161
203
 
162
204
  #### Order Objects
@@ -15,13 +15,9 @@ module Mintsoft
15
15
  # General API-related errors
16
16
  class APIError < Error; end
17
17
 
18
-
19
18
  # Authentication and authorization errors
20
19
  class AuthenticationError < APIError; end
21
20
 
22
- # Resource not found errors
23
- class NotFoundError < APIError; end
24
-
25
21
  # Request validation errors
26
22
  class ValidationError < APIError; end
27
23
  end
@@ -36,7 +36,6 @@ module Mintsoft
36
36
  error_class = case response.status
37
37
  when 400 then ValidationError
38
38
  when 401 then AuthenticationError
39
- when 404 then NotFoundError
40
39
  else APIError
41
40
  end
42
41
 
@@ -50,8 +49,6 @@ module Mintsoft
50
49
  "Invalid or expired token"
51
50
  when 400
52
51
  "Invalid request data: #{error_message}"
53
- when 404
54
- "Resource not found"
55
52
  else
56
53
  "API error: #{status} - #{error_message}"
57
54
  end
@@ -35,9 +35,13 @@ module Mintsoft
35
35
  validate_return_id!(return_id)
36
36
 
37
37
  response = get_request("/api/Return/#{return_id}")
38
- response_data = handle_response(response)
39
38
 
40
- Objects::Return.new(response_data)
39
+ if response.status == 404
40
+ nil # Return nil for not found returns
41
+ else
42
+ response_data = handle_response(response)
43
+ Objects::Return.new(response_data)
44
+ end
41
45
  end
42
46
 
43
47
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mintsoft
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.11"
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.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong