Skip to content

Commit

Permalink
Merge pull request #9 from uKaigo/master
Browse files Browse the repository at this point in the history
Add missing methods.
  • Loading branch information
AndyTempel authored Oct 17, 2020
2 parents e018126 + 827edd3 commit a9c5620
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ksoftapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__author__ = 'AndyTempel'
__license__ = 'GNU'
__copyright__ = 'Copyright 2018-2020 AndyTempel'
__version__ = '0.2.4a'
__version__ = '0.3.0a'

import logging
from collections import namedtuple
Expand All @@ -19,7 +19,7 @@

VersionInfo = namedtuple('VersionInfo', 'major minor micro releaselevel serial')

version_info = VersionInfo(major=0, minor=2, micro=4, releaselevel='alpha', serial=0)
version_info = VersionInfo(major=0, minor=3, micro=0, releaselevel='alpha', serial=0)

try:
from logging import NullHandler
Expand Down
59 changes: 55 additions & 4 deletions ksoftapi/apis/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,58 @@ async def tags(self) -> TagCollection:
r = await self._client.http.get('/images/tags')
return TagCollection(r)

# MISSING:
# - /image/{snowflake}
# - /tags/{search}
# - /random-nsfw
async def get_image(self, snowflake: str) -> Image:
"""|coro|
This function gets an image based on it's snowflake.
Parameters
----------
snowflake: :class:`str`
The image snowflake (unique ID)
Returns
-------
:class:`Image`
"""
r = await self._client.http.get(f'/images/image/{snowflake}')

if r.get('code', 200) == 404:
raise NoResults

return Image(r)

async def search_tags(self, search: str) -> TagCollection:
"""
This function searchs for tags.
Parameters
----------
search: :class:`str`
The search query.
Returns
-------
:class:`TagCollection`
"""
r = await self._client.http.get('/images/tags/{}'.format(search))

if r.get('code', 200) == 404:
raise NoResults

return TagCollection(r)

async def random_nsfw(self, gifs: bool = False) -> RedditImage:
"""|coro|
This function gets an random nsfw image.
Parameters
----------
gifs: :class:`bool`
If gifs should be retrivied instead of images.
Returns
-------
:class:`RedditImage`
"""
r = await self._client.http.get('/images/random-nsfw', params={'gifs': gifs})
return RedditImage(r)

0 comments on commit a9c5620

Please sign in to comment.