Skip to content

Commit

Permalink
Added timeout argument to Client. Fix for secure flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Aug 29, 2019
1 parent f8ebd5f commit 6aaf85c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ client = h51.Client('your_api_key...')

# Create an asset
with open('image.bmp') as f:
asset = h51.Asset.create(client, f)
asset = h51.resources.Asset.create(client, f)

# Analyze the image asset to find its dominant colours and focal point
asset.analyze([
Expand Down
19 changes: 15 additions & 4 deletions h51/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ class Client:
A client for the H51 (Hangar51) API.
"""

def __init__(self, api_key, api_base_url='https://api.h51.io'):
def __init__(
self,
api_key,
api_base_url='https://api.h51.io',
timeout=None
):

# A key used to authenticate API calls to an account
self._api_key = api_key

# The base URL to use when calling the API
self._api_base_url = api_base_url

# The period of time before requests to the API should timeout
self._timeout = timeout

# NOTE: Rate limiting information is only available after a request
# has been made.

Expand Down Expand Up @@ -72,14 +80,19 @@ def __call__(self,
# Filter out parameters set to `None`
params = {k: v for k, v in params.items() if v is not None}

if data:
# Filter out data set to `None`
data = {k: v for k, v in data.items() if v is not None}

# Make the request
r = getattr(requests, method.lower())(
f'{self._api_base_url}/{path}',
headers=headers,
params=params,
data=data,
json=json_type_body,
files=files
files=files,
timeout=self._timeout
)

# Update the rate limit
Expand Down Expand Up @@ -123,5 +136,3 @@ def __call__(self,
error.get('hint'),
error.get('arg_errors')
)


4 changes: 2 additions & 2 deletions h51/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ def create(cls, client, file, name=None, expire=None, secure=False):
'put',
f'assets',
files={'file': file},
params={
data={
'name': name,
'expire': expire,
'secure': secure
'secure': True if secure else None
}
)
)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
setup(
name='H51',

# Versions should comply with PEP440. For a discussion on single-sourcing
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.0.2',
version='0.0.3',
description=\
'The H51 Python library provides a pythonic interface to the H51 API.',
long_description=long_description,
Expand Down

0 comments on commit 6aaf85c

Please sign in to comment.