From 22d10a73296fcdb6c91d6255029364661ff178ae Mon Sep 17 00:00:00 2001 From: Aaron Swartz Date: Fri, 4 Feb 2011 23:32:25 -0600 Subject: [PATCH] Add support for related_result --- tweepy/api.py | 8 ++++++++ tweepy/models.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tweepy/api.py b/tweepy/api.py index b2304b6..2668787 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -77,6 +77,14 @@ class API(object): allowed_param = ['id', 'count', 'page'], require_auth = True ) + + """/related_results/show/:id.format""" + related_results = bind_api( + path = '/related_results/show/{id}.json', + payload_type = 'relation', payload_list = True, + allowed_param = ['id'], + require_auth = False + ) """/statuses/:id/retweeted_by/ids.format""" retweeted_by_ids = bind_api( diff --git a/tweepy/models.py b/tweepy/models.py index b584fbc..d4d5c4e 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -276,6 +276,19 @@ class List(Model): def is_subscribed(self, id): return self._api.is_subscribed_list(self.user.screen_name, self.slug, id) +class Relation(Model): + @classmethod + def parse(cls, api, json): + result = cls(api) + for k,v in json.items(): + if k == 'value' and json['kind'] in ['Tweet', 'LookedupStatus']: + setattr(result, k, Status.parse(api, v)) + elif k == 'results': + setattr(result, k, Relation.parse_list(api, v)) + else: + setattr(result, k, v) + return result + class JSONModel(Model): @@ -308,6 +321,7 @@ class ModelFactory(object): saved_search = SavedSearch search_result = SearchResult list = List + relation = Relation json = JSONModel ids = IDModel -- 2.25.1