You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+81Lines changed: 81 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,10 @@ A simple client wrapper for the [Investec Open API](https://developer.investec.c
16
16
- Retrieve balances per account
17
17
- Transfer between accounts
18
18
19
+
## Requirements
20
+
21
+
-**Ruby 2.7.0 or higher**
22
+
19
23
## Installation
20
24
21
25
Add this line to your application's Gemfile:
@@ -123,6 +127,83 @@ client.transfer_multiple(
123
127
)
124
128
```
125
129
130
+
## Error Handling
131
+
132
+
The client raises specific exceptions for different error scenarios. Always wrap API calls in error handling:
133
+
134
+
### Custom Exception Classes
135
+
136
+
-`InvestecOpenApi::AuthenticationError` - Raised when OAuth authentication fails
137
+
-`InvestecOpenApi::ValidationError` - Raised when required parameters are missing or invalid
138
+
-`InvestecOpenApi::NotFoundError` - Raised when a requested resource is not found
139
+
-`InvestecOpenApi::APIError` - Raised for general API errors
140
+
-`InvestecOpenApi::RateLimitError` - Raised when rate limits are exceeded
141
+
142
+
### Example: Handling Errors
143
+
144
+
```ruby
145
+
client =InvestecOpenApi::Client.new
146
+
147
+
begin
148
+
client.authenticate!
149
+
rescueInvestecOpenApi::AuthenticationError => e
150
+
puts"Authentication failed: #{e.message}"
151
+
# Handle authentication error
152
+
end
153
+
154
+
begin
155
+
transactions = client.transactions(account_id)
156
+
rescueInvestecOpenApi::ValidationError => e
157
+
puts"Invalid parameters: #{e.message}"
158
+
# Handle validation error
159
+
rescueInvestecOpenApi::NotFoundError => e
160
+
puts"Account not found: #{e.message}"
161
+
# Handle not found error
162
+
rescueInvestecOpenApi::APIError => e
163
+
puts"API error occurred: #{e.message}"
164
+
# Handle general API error
165
+
end
166
+
167
+
begin
168
+
transfer =InvestecOpenApi::Models::Transfer.new(
169
+
beneficiary_id,
170
+
1000.00,
171
+
"my ref",
172
+
"their ref"
173
+
)
174
+
rescueInvestecOpenApi::ValidationError => e
175
+
puts"Invalid transfer parameters: #{e.message}"
176
+
# Handle validation error
177
+
end
178
+
```
179
+
180
+
## Thread Safety
181
+
182
+
**Important:** The client instance caches a Faraday connection object. If you're using this client in a multi-threaded environment (such as a Rails application), ensure that each thread has its own instance of `InvestecOpenApi::Client`:
183
+
184
+
```ruby
185
+
# ✅ Correct: Each thread gets its own client
186
+
threads =5.times.map do
187
+
Thread.newdo
188
+
client =InvestecOpenApi::Client.new
189
+
client.authenticate!
190
+
# Use the client...
191
+
end
192
+
end
193
+
threads.each(&:join)
194
+
195
+
# ❌ Incorrect: Sharing a single client across threads
196
+
client =InvestecOpenApi::Client.new
197
+
client.authenticate!
198
+
threads =5.times.map do
199
+
Thread.newdo
200
+
# Don't do this - connection caching is not thread-safe
201
+
client.accounts
202
+
end
203
+
end
204
+
threads.each(&:join)
205
+
```
206
+
126
207
## Running in Sandbox mode
127
208
128
209
To run in sandbox mode, use the following configuration:
0 commit comments