Switch search to API v1.1 endpoint.
authorJoshua Roesslein <jroesslein@gmail.com>
Sat, 8 Jun 2013 21:56:06 +0000 (14:56 -0700)
committerJoshua Roesslein <jroesslein@gmail.com>
Sat, 8 Jun 2013 21:56:06 +0000 (14:56 -0700)
tweepy/__init__.py
tweepy/api.py
tweepy/models.py

index 6ec29ea727e6bfbf57a1c7f08d6f9695b7d4094a..24529e7d40983cbb27877c32d782298baea2e24c 100644 (file)
@@ -9,7 +9,7 @@ __version__ = '2.0'
 __author__ = 'Joshua Roesslein'
 __license__ = 'MIT'
 
-from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResult, ModelFactory, Category
+from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResults, ModelFactory, Category
 from tweepy.error import TweepError
 from tweepy.api import API
 from tweepy.cache import Cache, MemoryCache, FileCache
index 3e9fe2a7a4b6bdfecb8b7ac28db554ba5cf64e9b..3ad49d8998798bebb5abd93d6118442fa533a5db 100644 (file)
@@ -628,12 +628,10 @@ class API(object):
 
     """ search """
     search = bind_api(
-        search_api = True,
-        path = '/search.json',
-        payload_type = 'search_result', payload_list = True,
-        allowed_param = ['q', 'lang', 'locale', 'rpp', 'page', 'since_id', 'geocode', 'show_user', 'max_id', 'since', 'until', 'result_type']
+        path = '/search/tweets.json',
+        payload_type = 'search_results',
+        allowed_param = ['q', 'lang', 'locale', 'since_id', 'geocode', 'show_user', 'max_id', 'since', 'until', 'result_type']
     )
-    search.pagination_mode = 'page'
 
     """ trends/daily """
     trends_daily = bind_api(
index 8257e51096e9ce38f30051000b0494a918f82848..a0b78cd112e964cea4779c3fa90d874105c91bd3 100644 (file)
@@ -209,34 +209,20 @@ class SavedSearch(Model):
         return self._api.destroy_saved_search(self.id)
 
 
-class SearchResult(Model):
+class SearchResults(ResultSet):
 
     @classmethod
     def parse(cls, api, json):
-        result = cls()
-        for k, v in json.items():
-            if k == 'created_at':
-                setattr(result, k, parse_search_datetime(v))
-            elif k == 'source':
-                setattr(result, k, parse_html_value(unescape_html(v)))
-            else:
-                setattr(result, k, v)
-        return result
-
-    @classmethod
-    def parse_list(cls, api, json_list, result_set=None):
-        results = ResultSet()
-        results.max_id = json_list.get('max_id')
-        results.since_id = json_list.get('since_id')
-        results.refresh_url = json_list.get('refresh_url')
-        results.next_page = json_list.get('next_page')
-        results.results_per_page = json_list.get('results_per_page')
-        results.page = json_list.get('page')
-        results.completed_in = json_list.get('completed_in')
-        results.query = json_list.get('query')
-
-        for obj in json_list['results']:
-            results.append(cls.parse(api, obj))
+        results = SearchResults()
+        metadata = json['search_metadata']
+        results.max_id = metadata.get('max_id')
+        results.since_id = metadata.get('since_id')
+        results.refresh_url = metadata.get('refresh_url')
+        results.completed_in = metadata.get('completed_in')
+        results.query = metadata.get('query')
+
+        for status in json['statuses']:
+            results.append(Status.parse(api, status))
         return results
 
 
@@ -414,7 +400,7 @@ class ModelFactory(object):
     direct_message = DirectMessage
     friendship = Friendship
     saved_search = SavedSearch
-    search_result = SearchResult
+    search_results = SearchResults
     category = Category
     list = List
     relation = Relation