-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/api rate control #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1402193
Make init method more concise
jcoetsie 9d6334f
Add API rate limiting as specified in irail docs
jcoetsie 54ba9cb
Add logging to api calls
jcoetsie 32c8ea6
Add a dev container for development
jcoetsie 10fd205
Add a unit test to test api call
jcoetsie c7428c6
bum version
jcoetsie 0d5f78f
Update pipeline to seperate tests from release
jcoetsie 604682d
updated README
jcoetsie cd2f330
Add etag caching
jcoetsie 6eb02f3
Merge branch 'tjorim:master' into feature/api-rate-control
jcoetsie 658ac8e
Delete .gitlab-ci.yml
tjorim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "Python Dev Container", | ||
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.9", | ||
"features": {}, | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-python.vscode-pylance" | ||
] | ||
} | ||
}, | ||
"postCreateCommand": "pip install -r requirements.txt" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,70 @@ | ||
# pyRail | ||
|
||
A Python wrapper for the iRail API | ||
A Python wrapper for the iRail API. | ||
|
||
## Overview | ||
|
||
pyRail is a Python library that provides a convenient interface for interacting with the iRail API. It supports various endpoints such as stations, liveboard, vehicle, connections, and disturbances. The library also includes features like caching and rate limiting to optimize API usage. | ||
|
||
## Installation | ||
|
||
To install pyRail, use pip: | ||
|
||
```sh | ||
pip install pyrail | ||
``` | ||
|
||
## Usage | ||
Here is an example of how to use pyRail: | ||
|
||
```python | ||
from pyrail.irail import iRail | ||
|
||
# Create an instance of the iRail class | ||
api = iRail(format='json', lang='en') | ||
|
||
# Make a request to the 'stations' endpoint | ||
response = api.do_request('stations') | ||
|
||
# Print the response | ||
print(response) | ||
``` | ||
|
||
## Features | ||
|
||
- Supports multiple endpoints: stations, liveboard, vehicle, connections, disturbances | ||
- Caching and conditional GET requests using ETag | ||
- Rate limiting to handle API rate limits | ||
|
||
## Configuration | ||
|
||
You can configure the format and language for the API requests: | ||
|
||
```python | ||
api = iRail(format='json', lang='en') | ||
``` | ||
|
||
Supported formats: json, xml, jsonp | ||
|
||
Supported languages: nl, fr, en, de | ||
|
||
## Logging | ||
|
||
You can set the logging level at runtime to get detailed logs: | ||
|
||
```python | ||
api.set_logging_level(logging.DEBUG) | ||
``` | ||
|
||
## Contributing | ||
Contributions are welcome! Please open an issue or submit a pull request. | ||
|
||
## Contributors | ||
- @tjorim | ||
- @jcoetsie | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the LICENSE file for details. | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from pyrail.irail import irail | ||
1E79
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,26 @@ | ||
from pyrail import iRail | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
from pyrail.irail import iRail | ||
|
||
def test_irail_station(): | ||
class TestiRailAPI(unittest.TestCase): | ||
|
||
irail_instance = iRail() | ||
response = irail_instance.get_stations() | ||
print(response) | ||
@patch('requests.Session.get') | ||
def test_successful_request(self, mock_get): | ||
# Mock the response to simulate a successful request | ||
mock_response = MagicMock() | ||
mock_response.status_code = 200 | ||
mock_response.json.return_value = {'data': 'some_data'} | ||
mock_get.return_value = mock_response | ||
|
||
irail_instance = iRail() | ||
|
||
# Call the method that triggers the API request | ||
response = irail_instance.do_request('stations') | ||
|
||
# Check that the request was successful | ||
self.assertEqual(mock_get.call_count, 1, "Expected one call to the requests.Session.get method") | ||
self.assertEqual(response, {'data': 'some_data'}, "Expected response data to match the mocked response") | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Unused import.
According to static analysis,
from pyrail.irail import irail
is unused. Remove or alias it to avoid confusion.-from pyrail.irail import irail
🧰 Tools
🪛 Ruff (0.8.2)
1-1:
pyrail.irail.irail
imported but unused; consider removing, adding to__all__
, or using a redundant alias(F401)