From d6ac1c97765be75e4b6547decdbe7970f4a95a5e Mon Sep 17 00:00:00 2001 From: ueg1990 Date: Mon, 19 Oct 2015 18:04:03 -0400 Subject: [PATCH 1/4] Define Topic model --- imgurpython/imgur/models/topic.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 imgurpython/imgur/models/topic.py diff --git a/imgurpython/imgur/models/topic.py b/imgurpython/imgur/models/topic.py new file mode 100644 index 0000000..b9d2774 --- /dev/null +++ b/imgurpython/imgur/models/topic.py @@ -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) From bfec45806a03be2cc67007081e1e939aa5c26477 Mon Sep 17 00:00:00 2001 From: ueg1990 Date: Mon, 19 Oct 2015 18:37:01 -0400 Subject: [PATCH 2/4] Define method for default topics endpoint --- imgurpython/client.py | 6 ++++++ imgurpython/imgur/models/topic.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/imgurpython/client.py b/imgurpython/client.py index 544330b..c67f15d 100644 --- a/imgurpython/client.py +++ b/imgurpython/client.py @@ -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 @@ -679,3 +680,8 @@ 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] diff --git a/imgurpython/imgur/models/topic.py b/imgurpython/imgur/models/topic.py index b9d2774..2d0f336 100644 --- a/imgurpython/imgur/models/topic.py +++ b/imgurpython/imgur/models/topic.py @@ -1,6 +1,6 @@ class Topic(object): - def __init__(self, *initial_data, **kwargs) + def __init__(self, *initial_data, **kwargs): for dictionary in initial_data: for key, value in dictionary.iteritems(): setattr(self, key, value) From ea2fbcf24e69436ed5c4162cc6032a3da741ae8b Mon Sep 17 00:00:00 2001 From: ueg1990 Date: Mon, 19 Oct 2015 19:20:44 -0400 Subject: [PATCH 3/4] Define method for Gallery Topic Items --- imgurpython/client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/imgurpython/client.py b/imgurpython/client.py index c67f15d..cddeec9 100644 --- a/imgurpython/client.py +++ b/imgurpython/client.py @@ -685,3 +685,7 @@ def default_memes(self): def default_topics(self): topics = self.make_request('GET', 'topics/defaults') return [Topic(topic) for topic in topics] + + 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) From 7fece4d215dcda4147c3a03794b6a6149ad64585 Mon Sep 17 00:00:00 2001 From: ueg1990 Date: Mon, 19 Oct 2015 19:24:21 -0400 Subject: [PATCH 4/4] Deinfe method for Gallery Topic --- imgurpython/client.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/imgurpython/client.py b/imgurpython/client.py index cddeec9..54bd00e 100644 --- a/imgurpython/client.py +++ b/imgurpython/client.py @@ -686,6 +686,14 @@ 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)