ninja_van_api 0.3.4 → 0.3.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 +4 -4
- data/README.md +97 -1
- data/lib/ninja_van_api/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: 481484b7c6723678a26c7bbc898baf4e3a300a81881640d1eddeaa1b936a6fd0
|
4
|
+
data.tar.gz: d3e660f1ba15957e07441519d73d56239c7a7221515072e3ff0d4ee1cfc15902
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100f124aac939de091834aa5a0ad8d37d8210e050ef0b714503c1c291765979d5c3325aa265c6a0be8df305c3aad002ef11f741ecfa0675123170692ebd8fa15
|
7
|
+
data.tar.gz: bf7c08e8f3d9de76a5d1875365761f9826ee9297d0aecf376507c0ce2cacb9ba0d0973a712fbe42f61dcf7d4b157451d0fc06d617969875863d2ee361cb50b53
|
data/README.md
CHANGED
@@ -183,13 +183,109 @@ The webhook endpoints will be available at your specified paths (e.g., `/ninja_v
|
|
183
183
|
|
184
184
|
## Development
|
185
185
|
|
186
|
+
### Setup
|
187
|
+
|
186
188
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
187
189
|
|
190
|
+
### Environment Variables
|
191
|
+
|
192
|
+
For development purposes only, create a `.env` file in the root directory with a NinjaVan API access token:
|
193
|
+
|
194
|
+
```
|
195
|
+
NINJAVAN_API_ACCESS_TOKEN=00000000000
|
196
|
+
```
|
197
|
+
|
198
|
+
This token is used exclusively in development to prevent hitting NinjaVan's API request limits. When the token expires:
|
199
|
+
|
200
|
+
1. Open the console:
|
201
|
+
|
202
|
+
```
|
203
|
+
bin/console
|
204
|
+
```
|
205
|
+
|
206
|
+
2. Refresh the token:
|
207
|
+
|
208
|
+
```ruby
|
209
|
+
# Intialize the client
|
210
|
+
client = NinjaVanApi::Client.new(
|
211
|
+
client_id: ENV["CLIENT_ID"],
|
212
|
+
client_secret: ENV["CLIENT_SECRET"],
|
213
|
+
country_code: "SG",
|
214
|
+
test_mode: true,
|
215
|
+
)
|
216
|
+
|
217
|
+
# Refresh the token
|
218
|
+
client.refresh_access_token # => "new_access_token"
|
219
|
+
```
|
220
|
+
|
221
|
+
3. Update your `.env` file with the new token
|
222
|
+
|
223
|
+
4. Restart your application
|
224
|
+
|
225
|
+
Note: These environment variables are automatically loaded when you run `bin/console`. For production, ensure your client credentials (CLIENT_ID and CLIENT_SECRET) are securely set in your deployment environment.
|
226
|
+
|
227
|
+
### Authorization Issues
|
228
|
+
|
229
|
+
The gem handles token management automatically, including:
|
230
|
+
|
231
|
+
- Initial token acquisition
|
232
|
+
- Automatic token refresh when expired
|
233
|
+
- Retry mechanisms for failed requests
|
234
|
+
|
235
|
+
If you encounter authorization issues:
|
236
|
+
|
237
|
+
1. Verify your credentials:
|
238
|
+
|
239
|
+
- Check if CLIENT_ID and CLIENT_SECRET are correct
|
240
|
+
- Ensure credentials haven't been revoked by NinjaVan
|
241
|
+
|
242
|
+
2. Debug token issues:
|
243
|
+
|
244
|
+
- The gem automatically refreshes expired tokens
|
245
|
+
- Check your application logs for token-related errors
|
246
|
+
- Verify your system clock is synchronized (important for token validation)
|
247
|
+
|
248
|
+
3. Environment-specific troubleshooting:
|
249
|
+
- Development: Update your .env file with new credentials if needed
|
250
|
+
- Production: Safely update credentials in your environment
|
251
|
+
- Always restart your application after credential updates
|
252
|
+
|
253
|
+
### Testing
|
254
|
+
|
255
|
+
When testing your integration, it's recommended to stub the API requests. Here's an example using RSpec and WebMock:
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
require 'webmock/rspec'
|
259
|
+
|
260
|
+
RSpec.describe YourService do
|
261
|
+
let(:client) { NinjaVanApi::Client.new(client_id: 'test', client_secret: 'test', country_code: 'SG', test_mode: true) }
|
262
|
+
|
263
|
+
before do
|
264
|
+
# Stub authentication request
|
265
|
+
stub_request(:post, "https://api.ninjavan.co/SG/2.0/oauth/access_token")
|
266
|
+
.to_return(status: 200, body: { access_token: 'test_token' }.to_json)
|
267
|
+
|
268
|
+
# Stub API request
|
269
|
+
stub_request(:post, "https://api-sandbox.ninjavan.co/SG/4.2/orders")
|
270
|
+
.with(headers: { 'Authorization' => 'Bearer test_token', 'Content-Type' => 'application/json' })
|
271
|
+
.to_return(status: 200, body: { tracking_number: 'TEST123' }.to_json, headers: { 'Content-Type' => 'application/json' })
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'retrieves order information' do
|
275
|
+
order_params = {}
|
276
|
+
response = client.orders.create(order_params)
|
277
|
+
expect(response.tracking_number).to eq('TEST123')
|
278
|
+
end
|
279
|
+
end
|
280
|
+
```
|
281
|
+
|
282
|
+
### Installation
|
283
|
+
|
188
284
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
189
285
|
|
190
286
|
## Contributing
|
191
287
|
|
192
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
288
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/PostCo/ninja_van_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ninja_van_api/blob/main/CODE_OF_CONDUCT.md).
|
193
289
|
|
194
290
|
## License
|
195
291
|
|