Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions CHANGELOG.md

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sites = ecologi.impact('owenvoke')

## Change log

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Please see [GitHub Releases][link-github-releases] for more information on what has changed recently.

## Testing

Expand Down Expand Up @@ -70,6 +70,7 @@ Read more about Treeware at [treeware.earth][link-treeware].

[link-pypi]: https://pypi.org/project/ecologi-sdk
[link-github-actions]: https://github.com/owenvoke/ecologi-python-sdk/actions
[link-github-releases]: https://github.com/owenvoke/ecologi-python-sdk/releases
[link-treeware]: https://treeware.earth
[link-treeware-gifting]: https://ecologi.com/owenvoke?gift-trees
[link-author]: https://github.com/owenvoke
Expand Down
11 changes: 8 additions & 3 deletions ecologi/ecologi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from .types import Impact

TIMEOUT = 3
# Seconds to wait for a connection, and between bytes of the response
TIMEOUT = 10
API_BASE_URI = "https://public.ecologi.com"


Expand All @@ -17,8 +18,9 @@ class NotFoundException(EcologiException):


class Ecologi:
def __init__(self, base_uri: str = API_BASE_URI) -> None:
def __init__(self, base_uri: str = API_BASE_URI, timeout: float = TIMEOUT) -> None:
self.base_uri: str = base_uri
self.timeout: float = timeout
self.headers: dict = {}

def user_exists(self, username: str) -> bool:
Expand All @@ -39,7 +41,10 @@ def __request(self, method: str, url: str, params: Optional[dict] = None):

if method == "GET":
response = requests.get(
self.base_uri + url, params=params, headers=self.headers
self.base_uri + url,
params=params,
headers=self.headers,
timeout=self.timeout,
)
else:
raise RuntimeError("Invalid request method provided")
Expand Down
14 changes: 14 additions & 0 deletions tests/test_ecologi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ def test_not_authenticated():

assert type(me) == bool
assert me is False


def test_requests_time_out():
with requests_mock.Mocker() as m:
m.get(
url="https://public.ecologi.com/users/owenvoke/impact",
json={"trees": 1733, "carbonOffset": 41.05},
)

ecologi.impact("owenvoke")
assert m.last_request.timeout == 10

Ecologi(timeout=2.5).impact("owenvoke")
assert m.last_request.timeout == 2.5
Loading