-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make init method more concise * Add API rate limiting as specified in irail docs * Add logging to api calls * Add a dev container for development * Add a unit test to test api call * bum version * Update pipeline to seperate tests from release * updated README * Add etag caching * Delete .gitlab-ci.yml --------- Co-authored-by: Jorim Tielemans <tielemans.jorim@gmail.com>
- Loading branch information
Showing
6 changed files
with
181 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
This file contains 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() |