mintsoft 0.1.3 → 0.1.5

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: f77c74116b807d8a07ce73ccf258237db3665585ede056cc00d08044fe811497
4
- data.tar.gz: 06e3a80cc0b9e2f38424116875c5e96fd0a78d78dfb7fb8c3330824e3fdf2600
3
+ metadata.gz: f317c96d49df00a91bb679b079da14192f53ee373bedd233b68a373694f82528
4
+ data.tar.gz: 181fbdf0b85db468c9537dc1fb2c4d8cb41c8651487056cc9e71a8b3007f41ac
5
5
  SHA512:
6
- metadata.gz: 4a443a1a412560f0dd8f97fd00a2aacbc2dc1ce3186bf5e59cf67e4dfb968661db32dda6fa2dc0591e8032fb696da461348b68c7c474471c53c5a1e2c90d8cab
7
- data.tar.gz: 01a64e1ec0b9415434f6dcc3ba9f36f98d0e97121e1ef9b2cf301862053f5e2a086ba8b4d3d2c9ba75c855c78d2400435a57b8342070a26810461d3353b894e0
6
+ metadata.gz: 122feb85df1c698d875f4494f5b3a31a9401378ff0629bcf5328ccaa26d06057bc0f7f0b6b5213762c663a2220d48569c3b9fd5f226f0969fd72c44fec0b37e5
7
+ data.tar.gz: 4e5db4e19ff76da89ae50dd1d05d3303d1e4dc34a0c32896875fad648795acf1f86a0760914faf5f244012308451294d083a5a9aec35f82ddd4456baf8d260b1
data/CLAUDE.md ADDED
@@ -0,0 +1,92 @@
1
+ # Mintsoft Ruby Gem - Claude Instructions
2
+
3
+ ## Project Overview
4
+
5
+ This is a Ruby gem that provides a wrapper for the Mintsoft API with token-based authentication and access to warehouse management functions.
6
+
7
+ ## Core Principles
8
+
9
+ ### API Response Handling - CRITICAL RULE
10
+ **DO NOT ENHANCE OR INJECT DATA TO THE RESPONSE WHEN WRAPPING THE API RESPONSE IN OBJECT**
11
+
12
+ - The `Base` class (lib/mintsoft/base.rb) wraps API responses in OpenStruct objects
13
+ - Objects should only contain data that comes directly from the API response
14
+ - DO NOT add computed properties, injected fields, or derived data
15
+ - Preserve the original response structure exactly as returned by the API
16
+ - Use `@original_response` to store the frozen, unmodified API response
17
+
18
+ ### Object Design
19
+ - All API objects inherit from `Mintsoft::Objects::Base`
20
+ - Base class provides OpenStruct functionality with underscore key transformation
21
+ - Objects provide `.raw` method to access original API response
22
+ - Objects provide `.to_hash` method to convert back to hash representation
23
+ - Keep object classes simple - they are data containers, not business logic
24
+
25
+ ## Project Structure
26
+
27
+ ```
28
+ lib/
29
+ ├── mintsoft/
30
+ │ ├── base.rb # Base class for all API objects
31
+ │ ├── client.rb # Main API client
32
+ │ ├── auth_client.rb # Authentication client
33
+ │ ├── resources/ # API resource handlers
34
+ │ └── objects/ # API response objects
35
+ │ ├── order.rb # Order object (inherits from Base)
36
+ │ └── return.rb # Return object (inherits from Base)
37
+ ```
38
+
39
+ ## Development Guidelines
40
+
41
+ ### When Adding New Object Classes
42
+ 1. Inherit from `Mintsoft::Objects::Base`
43
+ 2. Keep the class minimal - let Base handle the data transformation
44
+ 3. DO NOT add computed properties or inject additional data
45
+ 4. Test with actual API responses to ensure correct transformation
46
+
47
+ ### When Modifying Base Class
48
+ 1. Maintain backward compatibility
49
+ 2. Preserve original response data integrity
50
+ 3. Ensure `to_hash` and `raw` methods continue to work
51
+ 4. Test key transformation (camelCase to underscore)
52
+
53
+ ### Error Handling
54
+ - All error classes should include response context and status codes
55
+ - Provide clear error messages for common scenarios
56
+ - Use appropriate HTTP status-based error classes
57
+
58
+ ### Authentication
59
+ - Token management is manual - no automatic refresh
60
+ - Auth client returns token directly as string
61
+ - Client initialization requires explicit token parameter
62
+
63
+ ## Testing
64
+
65
+ - Run tests with `rake spec`
66
+ - Test with real API responses when possible
67
+ - Ensure object transformation preserves data integrity
68
+ - Test error scenarios with appropriate status codes
69
+
70
+ ## Key Files to Understand
71
+
72
+ 1. `lib/mintsoft/base.rb` - Core object transformation logic
73
+ 2. `lib/mintsoft/client.rb` - Main API client interface
74
+ 3. `lib/mintsoft/auth_client.rb` - Authentication handling
75
+ 4. `spec/` - Test files showing expected behavior
76
+
77
+ ## When Making Changes
78
+
79
+ 1. Read the existing code patterns first
80
+ 2. Follow Ruby conventions and the existing style
81
+ 3. **NEVER inject or enhance API response data**
82
+ 4. Keep object classes simple and focused on data representation
83
+ 5. Maintain the original response preservation pattern
84
+ 6. Test thoroughly with real API responses
85
+
86
+ ## Common Pitfalls to Avoid
87
+
88
+ - Adding computed properties to object classes
89
+ - Modifying API response data during object creation
90
+ - Breaking the `@original_response` storage pattern
91
+ - Adding business logic to data objects
92
+ - Changing key transformation behavior without testing
data/README.md CHANGED
@@ -122,7 +122,6 @@ result = client.returns.add_item(return_obj.id, {
122
122
 
123
123
  # Access return properties
124
124
  puts return_obj.id # Direct access to return ID
125
- puts return_obj.order_id # Access to associated order ID (injected by resource)
126
125
  # Note: Items data structure depends on API response format
127
126
  ```
128
127
 
@@ -173,7 +172,6 @@ return_obj = client.returns.create(order_id)
173
172
 
174
173
  # Direct property access
175
174
  return_obj.id # Return ID from API response
176
- return_obj.order_id # Associated order ID (injected by resource)
177
175
  # Note: Other properties depend on API response structure
178
176
  ```
179
177
 
@@ -189,7 +187,7 @@ puts token # Direct token string
189
187
  client = Mintsoft::Client.new(token: token)
190
188
 
191
189
  # For re-authentication when token expires:
192
- token = auth_client.auth.authenticate("username", "password")
190
+ token = auth_client.auth.authenticate("username", "password")
193
191
  client = Mintsoft::Client.new(token: token)
194
192
  ```
195
193
 
@@ -5,6 +5,9 @@ require "faraday/net_http"
5
5
 
6
6
  module Mintsoft
7
7
  class AuthClient
8
+ # Authentication errors specific to auth client
9
+ class AuthenticationError < APIError; end
10
+
8
11
  BASE_URL = "https://api.mintsoft.co.uk"
9
12
 
10
13
  attr_reader :base_url, :conn_opts
@@ -67,7 +70,7 @@ module Mintsoft
67
70
  def handle_error_response(response)
68
71
  case response.status
69
72
  when 401
70
- raise AuthenticationError, "Invalid credentials"
73
+ raise AuthClient::AuthenticationError, "Invalid credentials"
71
74
  when 400
72
75
  raise ValidationError, "Invalid request: #{extract_error_message(response.body)}"
73
76
  else
@@ -15,6 +15,7 @@ module Mintsoft
15
15
  # General API-related errors
16
16
  class APIError < Error; end
17
17
 
18
+
18
19
  # Authentication and authorization errors
19
20
  class AuthenticationError < APIError; end
20
21
 
@@ -16,7 +16,6 @@ module Mintsoft
16
16
 
17
17
  response = post_request("/api/Return/CreateReturn/#{order_id}")
18
18
  response_data = handle_response(response)
19
- response_data["order_id"] = order_id
20
19
 
21
20
  Objects::Return.new(response_data)
22
21
  end
@@ -28,7 +27,6 @@ module Mintsoft
28
27
  payload = format_item_payload(item_attributes)
29
28
  response = post_request("/api/Return/#{return_id}/AddItem", body: payload)
30
29
  response_data = handle_response(response)
31
- response_data["return_id"] = return_id
32
30
 
33
31
  Objects::Return.new(response_data)
34
32
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mintsoft
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
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.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
@@ -111,11 +111,11 @@ files:
111
111
  - ".serena/project.yml"
112
112
  - ".standard.yml"
113
113
  - CHANGELOG.md
114
+ - CLAUDE.md
114
115
  - CODE_OF_CONDUCT.md
115
116
  - LICENSE.txt
116
117
  - README.md
117
118
  - Rakefile
118
- - examples/complete_workflow.rb
119
119
  - lib/mintsoft.rb
120
120
  - lib/mintsoft/auth_client.rb
121
121
  - lib/mintsoft/base.rb
@@ -1,140 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # Complete workflow example for the Mintsoft gem
5
- # This demonstrates all 5 endpoints working together
6
-
7
- require "mintsoft"
8
-
9
- # Step 1: Authentication using AuthClient
10
- puts "=== Step 1: Authentication ==="
11
- auth_client = Mintsoft::AuthClient.new
12
- begin
13
- token = auth_client.auth.authenticate(
14
- ENV.fetch("MINTSOFT_USERNAME"),
15
- ENV.fetch("MINTSOFT_PASSWORD")
16
- )
17
-
18
- puts "✅ Authentication successful!"
19
- puts "Token: #{token[0...10]}..."
20
- rescue Mintsoft::AuthenticationError => e
21
- puts "❌ Authentication failed: #{e.message}"
22
- exit 1
23
- rescue KeyError => e
24
- puts "❌ Environment variable not set: #{e.message}"
25
- puts "Please set MINTSOFT_USERNAME and MINTSOFT_PASSWORD environment variables"
26
- exit 1
27
- end
28
-
29
- # Step 2: Initialize client with token
30
- puts "\n=== Step 2: Initialize Client ==="
31
- client = Mintsoft::Client.new(token: token)
32
- puts "✅ Client initialized with token"
33
-
34
- # Step 3: Search for orders
35
- puts "\n=== Step 3: Search Orders ==="
36
- order_number = "ORD-2024-001" # Change this to a real order number in your system
37
- begin
38
- orders = client.orders.search(order_number)
39
-
40
- if orders.empty?
41
- puts "⚠️ No orders found with number: #{order_number}"
42
- puts "Please try with a different order number"
43
- exit 1
44
- end
45
-
46
- order = orders.first
47
- puts "✅ Found #{orders.size} order(s)"
48
- puts "Order ID: #{order.id}"
49
- puts "Order Number: #{order.order_number}"
50
- puts "Customer ID: #{order.customer_id}" if order.respond_to?(:customer_id)
51
- puts "Status: #{order.status}" if order.respond_to?(:status)
52
- rescue Mintsoft::ValidationError => e
53
- puts "❌ Validation error: #{e.message}"
54
- exit 1
55
- rescue Mintsoft::AuthenticationError => e
56
- puts "❌ Authentication error: #{e.message}"
57
- puts "Token may have expired. Please re-authenticate."
58
- exit 1
59
- rescue Mintsoft::APIError => e
60
- puts "❌ API error: #{e.message}"
61
- exit 1
62
- end
63
-
64
- # Step 4: Get return reasons
65
- puts "\n=== Step 4: Get Return Reasons ==="
66
- begin
67
- reasons = client.returns.reasons
68
- puts "✅ Found #{reasons.size} return reason(s)"
69
-
70
- reasons.each do |reason|
71
- status = reason.active? ? "✅" : "❌"
72
- puts " #{status} #{reason.name} (ID: #{reason.id}): #{reason.description}"
73
- end
74
-
75
- # Select the first active reason for demo
76
- selected_reason = reasons.find(&:active?)
77
- if selected_reason.nil?
78
- puts "❌ No active return reasons found"
79
- exit 1
80
- end
81
-
82
- puts "\n🎯 Selected reason: #{selected_reason.name}"
83
- rescue Mintsoft::APIError => e
84
- puts "❌ API error: #{e.message}"
85
- exit 1
86
- end
87
-
88
- # Step 5: Create return
89
- puts "\n=== Step 5: Create Return ==="
90
- begin
91
- return_obj = client.returns.create(order.id)
92
- puts "✅ Return created successfully!"
93
- puts "Return ID: #{return_obj.id}"
94
- puts "Order ID: #{return_obj.order_id}"
95
- puts "Status: #{return_obj.status}"
96
- rescue Mintsoft::ValidationError => e
97
- puts "❌ Validation error: #{e.message}"
98
- exit 1
99
- rescue Mintsoft::APIError => e
100
- puts "❌ API error: #{e.message}"
101
- exit 1
102
- end
103
-
104
- # Step 6: Add item to return
105
- puts "\n=== Step 6: Add Item to Return ==="
106
- item_attributes = {
107
- product_id: 123, # Replace with actual product ID
108
- quantity: 2, # Quantity to return
109
- reason_id: selected_reason.id, # Selected return reason
110
- unit_value: 25.00, # Unit value
111
- notes: "Damaged during shipping" # Optional notes
112
- }
113
-
114
- begin
115
- success = client.returns.add_item(return_obj.id, item_attributes)
116
-
117
- if success
118
- puts "✅ Item added to return successfully!"
119
- puts "Product ID: #{item_attributes[:product_id]}"
120
- puts "Quantity: #{item_attributes[:quantity]}"
121
- puts "Reason: #{selected_reason.name}"
122
- puts "Unit Value: $#{item_attributes[:unit_value]}"
123
- puts "Notes: #{item_attributes[:notes]}"
124
- else
125
- puts "❌ Failed to add item to return"
126
- end
127
- rescue Mintsoft::ValidationError => e
128
- puts "❌ Validation error: #{e.message}"
129
- rescue Mintsoft::APIError => e
130
- puts "❌ API error: #{e.message}"
131
- end
132
-
133
- puts "\n=== Workflow Complete ==="
134
- puts "🎉 Successfully completed the full Mintsoft API workflow!"
135
- puts " 1. ✅ Authenticated and got token"
136
- puts " 2. ✅ Initialized client"
137
- puts " 3. ✅ Searched for orders"
138
- puts " 4. ✅ Retrieved return reasons"
139
- puts " 5. ✅ Created return"
140
- puts " 6. ✅ Added item to return"