From 066146062076f37677507df6312bc9374420019a Mon Sep 17 00:00:00 2001 From: Joshua Roesslein Date: Sat, 21 Dec 2013 17:42:09 -0800 Subject: [PATCH] Add API.cached_result. This will be True if the last result was cached. Otherwise this will be False if the result was freshly requested from the Twitter API servers. --- tests/test_api.py | 7 +++++++ tweepy/binder.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/tests/test_api.py b/tests/test_api.py index d83a844..c21a11e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -326,6 +326,13 @@ class TweepyAPITests(TweepyTestCase): } self.assertTrue(expected_dict in languages) + def testcachedresult(self): + self.api.cache = MemoryCache() + self.api.home_timeline() + self.assertFalse(self.api.cached_result) + self.api.home_timeline() + self.assertTrue(self.api.cached_result) + class TweepyCacheTests(unittest.TestCase): timeout = 2.0 diff --git a/tweepy/binder.py b/tweepy/binder.py index 6c58847..29eacae 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -104,6 +104,8 @@ def bind_api(**config): self.path = self.path.replace(variable, value) def execute(self): + self.api.cached_result = False + # Build the request URL url = self.api_root + self.path if len(self.parameters): @@ -123,6 +125,7 @@ def bind_api(**config): else: if isinstance(cache_result, Model): cache_result._api = self.api + self.api.cached_result = True return cache_result # Continue attempting request until successful -- 2.25.1