Skip to content

Commit

Permalink
[INT-1238] Add Custom Header Parameter on Initialization Object (#47)
Browse files Browse the repository at this point in the history
* Add custom header parameter on initialization object

* Update unreleased section of changelog with changes

* Update syntax for custom_headers

* Update readme

* Prepare for v1.4.0
  • Loading branch information
kaiserawu authored May 16, 2023
1 parent 68364ad commit 6f46735
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.4.0] - 2023-05-15
### Added
- Added property for adding custom headers to all requests

## [1.3.1] - 2022-07-06
### Security
- Update dependencies (`backoff` v2.1.2, `requests` v2.28.1)
Expand Down Expand Up @@ -84,7 +88,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release on PyPI

[Unreleased]: https://github.com/onfleet/pyonfleet/compare/v1.3.1...HEAD
[Unreleased]: https://github.com/onfleet/pyonfleet/compare/v1.4.0...HEAD
[1.4.0]: https://github.com/onfleet/pyonfleet/compare/v1.3.1...v1.4.0
[1.3.1]: https://github.com/onfleet/pyonfleet/compare/v1.3.0...v1.3.1
[1.3.0]: https://github.com/onfleet/pyonfleet/compare/v1.2.1...v1.3.0
[1.2.1]: https://github.com/onfleet/pyonfleet/compare/v1.2...v1.2.1
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ onfleet_api = Onfleet() # Using the .auth.json file
onfleet_api = Onfleet(api_key="<your_api_key>") # Without the .auth.json file
```

Another optional parameter for `Onfleet` is `custom_headers` where you can pass in headers to be applied to all requests. For example:

```python
onfleet_api = Onfleet(custom_headers={"<header_name>": "<header_value>"})
```

Once the `Onfleet` object is created, you will get access to all the API endpoints as documented in the [Onfleet API documentation](https://docs.onfleet.com/).

### Unit testing using Docker
Expand Down
2 changes: 1 addition & 1 deletion onfleet/_meta.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.1'
__version__ = '1.4.0'
5 changes: 4 additions & 1 deletion onfleet/onfleet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ class Onfleet(object):

webhooks = Endpoint('webhooks', ('GET', 'POST', 'DELETE'), _session)

def __init__(self, api_key=None):
def __init__(self, api_key=None, custom_headers={}):
# Looking up local authentication JSON if no api_key was passed
if not api_key:
if os.path.isfile(".auth.json"):
with open(".auth.json") as json_secret_file:
local_secret = json.load(json_secret_file)
api_key = local_secret.get('API_KEY')
self._session.auth = (api_key, '') # Username, password
# Apply custom headers to all requests if given
if bool(custom_headers):
self._session.headers.update(custom_headers)

def auth_test(self):
response = self._session.get(f'{API_BASE_URL}/auth/test')
Expand Down

0 comments on commit 6f46735

Please sign in to comment.