Skip to content

Commit

Permalink
Update to new httpx API (#91)
Browse files Browse the repository at this point in the history
 Rename `AsyncClient` to `Client`.
  • Loading branch information
dhirschfeld authored and brettcannon committed Jan 2, 2020
1 parent 94eafc2 commit 18f7b5f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

vNext
'''''

- Adapt to the new ``httpx`` api to support versions >= 0.8.0 (thanks [Dave Hirschfeld](https://github.com/dhirschfeld))

3.2.0
'''''

Expand Down
2 changes: 1 addition & 1 deletion docs/httpx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import gidgethub.httpx


async with httpx.AsyncClient() as client:
async with httpx.Client() as client:
gh = gidgethub.httpx.GitHubAPI(client, requester,
oauth_token=oauth_token)
# Make your requests, e.g. ...
Expand Down
7 changes: 5 additions & 2 deletions gidgethub/httpx.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import asyncio
from typing import Mapping, Tuple, Any

import httpx
try:
from httpx import AsyncClient as Client # type: ignore
except ImportError:
from httpx import Client

from . import abc as gh_abc


class GitHubAPI(gh_abc.GitHubAPI):
def __init__(self, client: httpx.AsyncClient, *args: Any,
def __init__(self, client: Client, *args: Any,
**kwargs: Any) -> None:
self._client = client
super().__init__(*args, **kwargs)
Expand Down
12 changes: 8 additions & 4 deletions gidgethub/test/test_httpx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import datetime

import httpx
try:
from httpx import AsyncClient as Client # type: ignore
except ImportError:
from httpx import Client

import pytest

from .. import httpx as gh_httpx
Expand All @@ -11,7 +15,7 @@
async def test_sleep():
delay = 1
start = datetime.datetime.now()
async with httpx.AsyncClient() as client:
async with Client() as client:
gh = gh_httpx.GitHubAPI(client, "gidgethub")
await gh.sleep(delay)
stop = datetime.datetime.now()
Expand All @@ -22,7 +26,7 @@ async def test_sleep():
async def test__request():
"""Make sure that that abstract method is implemented properly."""
request_headers = sansio.create_headers("gidgethub")
async with httpx.AsyncClient() as client:
async with Client() as client:
gh = gh_httpx.GitHubAPI(client, "gidgethub")
aio_call = await gh._request("GET", "https://api.github.com/rate_limit",
request_headers)
Expand All @@ -33,7 +37,7 @@ async def test__request():
@pytest.mark.asyncio
async def test_get():
"""Integration test."""
async with httpx.AsyncClient() as client:
async with Client() as client:
gh = gh_httpx.GitHubAPI(client, "gidgethub")
data = await gh.getitem("/rate_limit")
assert "rate" in data

0 comments on commit 18f7b5f

Please sign in to comment.