Skip to content

Commit

Permalink
Added new unit tests for the raindrop api
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaOliphant committed Aug 26, 2023
1 parent f2bff2f commit e77edbe
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 78 deletions.
33 changes: 10 additions & 23 deletions avocet/raindrop_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,23 @@ class RaindropAPI:
def __init__(self) -> None:
token = os.environ["RAINDROP"]
self._headers = {"Authorization": f"Bearer {token}"}
self._client = httpx.AsyncClient()

async def get_collections(self) -> Dict:
async with httpx.AsyncClient() as client:
r = await client.get("https://api.raindrop.io/rest/v1/collections", headers=self._headers)
r = await self._client.get("https://api.raindrop.io/rest/v1/collections", headers=self._headers)
return r.json()['items']

async def get_raindrops_by_collection_id(self, collection_id: str, search: str = None) -> Dict:
async with httpx.AsyncClient() as client:
if search:
params = {"search": search}
r = await client.get(f"https://api.raindrop.io/rest/v1/raindrops/{collection_id}", headers=self._headers, params=params)
else:
r = await client.get(f"https://api.raindrop.io/rest/v1/raindrops/{collection_id}", headers=self._headers)
if search:
params = {"search": search}
r = await self._client.get(f"https://api.raindrop.io/rest/v1/raindrops/{collection_id}", headers=self._headers, params=params)
else:
r = await self._client.get(f"https://api.raindrop.io/rest/v1/raindrops/{collection_id}", headers=self._headers)
return r.json()['items']

async def get_raindrop_by_raindrop_id(self, raindrop_id: str) -> Dict:
async with httpx.AsyncClient() as client:
r = await client.get(f"https://api.raindrop.io/rest/v1/raindrop/{raindrop_id}", headers=self._headers)
item = r.json()['item']
raindrop = dict()
raindrop[item['_id']] = {
'excerpt': item['excerpt'],
'tags': item['tags'],
'title': item['title'],
'link': item['link'],
'type': 'raindrop'
}
r.close()
return raindrop
r = await self._client.get(f"https://api.raindrop.io/rest/v1/raindrop/{raindrop_id}", headers=self._headers)
return r.json()['item']

async def post_raindrop(self, url: str, collection: str, tags: list) -> None:
raindrop = {
Expand All @@ -45,7 +33,6 @@ async def post_raindrop(self, url: str, collection: str, tags: list) -> None:
"tags": tags
}
log(f"Posting raindrop: {raindrop}")
async with httpx.AsyncClient() as client:
r = await client.post("https://api.raindrop.io/rest/v1/raindrop", headers=self._headers, json=raindrop)
r = await self._client.post("https://api.raindrop.io/rest/v1/raindrop", headers=self._headers, json=raindrop)
log(f"Raindrop posted: {r.json()}")
r.close()
139 changes: 85 additions & 54 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e77edbe

Please sign in to comment.