11import datetime
22from time import sleep
3- from typing import Generator , Optional , Tuple
3+ from typing import Dict , Generator , Optional , Tuple
44
55from requests import PreparedRequest , Request , Response , Session
66from requests .auth import AuthBase
@@ -37,12 +37,15 @@ def request(
3737 self ,
3838 method : str ,
3939 path : str ,
40+ params : Optional [Dict [str , str ]] = None ,
4041 timeout : Optional [Tuple [int , int ]] = None ,
4142 ** kwargs ,
4243 ) -> Tuple [PreparedRequest , Response ]:
4344 full_url = f"{ self .api_url } /{ path } "
4445
45- request = Request (method = method .upper (), url = full_url , ** kwargs )
46+ request = Request (
47+ method = method .upper (), url = full_url , params = params , ** kwargs
48+ )
4649 prepped = self .session .prepare_request (request )
4750 response = self .session .send (prepped , timeout = timeout )
4851
@@ -52,14 +55,19 @@ def request_paginated(
5255 self ,
5356 method : str ,
5457 path : str ,
58+ params : Optional [Dict [str , str ]] = None ,
5559 timeout : Optional [Tuple [int , int ]] = None ,
5660 ** kwargs ,
5761 ) -> Generator [Tuple [PreparedRequest , Response ], None , None ]:
5862 next_path : Optional [str ] = path
5963
6064 while next_path is not None :
6165 request , response = self .request (
62- method = method , path = next_path , timeout = timeout , ** kwargs
66+ method = method ,
67+ path = next_path ,
68+ timeout = timeout ,
69+ params = params ,
70+ ** kwargs ,
6371 )
6472 yield request , response
6573
@@ -82,6 +90,10 @@ def request_paginated(
8290 next_url = response .links ["next" ]["url" ]
8391 next_path = next_url .replace (f"{ self .api_url } /" , "" )
8492
93+ # Resetting the params because the next_path will provide the query
94+ # parameters.
95+ params = {}
96+
8597 def accounts_verify_credentials (self ) -> Tuple [PreparedRequest , Response ]:
8698 return self .request ("GET" , "accounts/verify_credentials" )
8799
@@ -100,10 +112,17 @@ def accounts_following(
100112 )
101113
102114 def accounts_statuses (
103- self , account_id : str
115+ self ,
116+ account_id : str ,
117+ since_id : Optional [str ] = None ,
104118 ) -> Generator [Tuple [PreparedRequest , Response ], None , None ]:
119+ params = {"limit" : "40" }
120+
121+ if since_id is not None :
122+ params ["since_id" ] = since_id
123+
105124 return self .request_paginated (
106- "GET" , f"accounts/{ account_id } /statuses" , params = { "limit" : "40" }
125+ "GET" , f"accounts/{ account_id } /statuses" , params = params
107126 )
108127
109128 def bookmarks (
0 commit comments