Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Topic #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions imgurpython/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import requests
from .imgur.models.tag import Tag
from .imgur.models.topic import Topic
from .imgur.models.album import Album
from .imgur.models.image import Image
from .imgur.models.account import Account
Expand Down Expand Up @@ -679,3 +680,20 @@ def mark_notifications_as_read(self, notification_ids):
def default_memes(self):
response = self.make_request('GET', 'memegen/defaults')
return [Image(meme) for meme in response]

# Topic-related endpoints
def default_topics(self):
topics = self.make_request('GET', 'topics/defaults')
return [Topic(topic) for topic in topics]

def gallery_topic(self, topic_id, sort='viral', page=0, windown='week'):
if sort == 'top':
response = self.make_request('GET', 'topics/%s/%s/%s/%d' % (topic_id, sort, window, page))
else:
response = self.make_request('GET', 'topics/%s/%s/%d' % (topic_id, sort, page))

return build_gallery_images_and_albums(response)

def gallery_topic_item(self, topic_id, item_id):
response = self.make_request('GET', 'topics/%s/%s' % (topic_id, item_id))
return build_gallery_images_and_albums(response)
8 changes: 8 additions & 0 deletions imgurpython/imgur/models/topic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Topic(object):

def __init__(self, *initial_data, **kwargs):
for dictionary in initial_data:
for key, value in dictionary.iteritems():
setattr(self, key, value)
for key, value in kwargs.iteritems():
setattr(self, key, value)