11import concurrent .futures
22import threading
33import time
4+ from typing import Dict , Optional
45
56import requests
67from requests .adapters import HTTPAdapter
1314from .version import ClientVersion
1415
1516
17+ class HTTPMethods :
18+ GET = 'get'
19+ POST = 'post'
20+ PUT = 'put'
21+ DELETE = 'delete'
22+ PATCH = 'patch'
23+ HEAD = 'head'
24+
1625class HTTPClient (object ):
1726 """HTTP Client base that automatically handles the following:
18- - Shared thread/session object
19- - Client version headers
20- - Automated retries
27+ - Shared thread/session object
28+ - Client version headers
29+ - Automated retries
2130
22- Args:
23- threads (int): Number of threads to use concurrently.
2431 """
2532
26- def __init__ (self , threads = default_thread_count ):
33+ def __init__ (self , threads : Optional [int ] = default_thread_count ):
34+ """
35+ :param threads: Number of threads to use concurrently.
36+ """
37+
2738 # Setup number of threads to use
2839 self .threads = threads
2940
@@ -72,7 +83,7 @@ class APIClient(HTTPClient, object):
7283 progress (bool): If True, show status bars in console.
7384 """
7485
75- def __init__ (self , token , host , threads , progress ):
86+ def __init__ (self , token : str , host : str , threads : int , progress : bool ):
7687 super ().__init__ (threads )
7788 self .host = host
7889 self .token = token
@@ -82,10 +93,10 @@ def __init__(self, token, host, threads, progress):
8293 self .session = self ._get_session ()
8394 self .auth_header = {"Authorization" : "Bearer {}" .format (self .token )}
8495
85- def _format_api_call (self , endpoint ):
96+ def _format_api_call (self , endpoint : str ):
8697 return "{}/v2{}" .format (self .host , endpoint )
8798
88- def _api_call (self , method , endpoint , payload = {}, limit = None ):
99+ def _api_call (self , method , endpoint : str , payload : Dict = {}, limit : Optional [ int ] = None ):
89100 headers = {** self .shared_headers , ** self .auth_header }
90101
91102 r = self .session .request (
@@ -117,7 +128,7 @@ def _api_call(self, method, endpoint, payload={}, limit=None):
117128
118129 return r .raise_for_status ()
119130
120- def get_specific_page (self , method , endpoint , payload , page ):
131+ def get_specific_page (self , method : HTTPMethods , endpoint : str , payload : Dict , page : int ):
121132 """
122133 Gets a specific page for that endpoint, used by Pagination Class
123134
@@ -127,11 +138,11 @@ def get_specific_page(self, method, endpoint, payload, page):
127138 payload (dict): Request payload
128139 page (int): What page to get
129140 """
130- if method == "get" :
141+ if method == HTTPMethods . GET :
131142 endpoint = "{}?page={}" .format (endpoint , page )
132143 return self ._api_call (method , endpoint )
133144
134- if method == "post" :
145+ if method == HTTPMethods . POST :
135146 payload ["page" ] = page
136147 return self ._api_call (method , endpoint , payload = payload )
137148
0 commit comments