Skip to content

Commit a27a1b6

Browse files
committed
improve imports
1 parent b050686 commit a27a1b6

15 files changed

+60
-50
lines changed

tests/test_errors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import responses
22
import requests
33

4-
from veryfi.errors import *
5-
from veryfi import *
4+
from veryfi.errors import BadRequest, VeryfiClientError
5+
from veryfi import Client
66
import pytest
77

88

veryfi/_documents/line_items.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import *
1+
from typing import Dict
22

33
from veryfi.client_base import Client
44

@@ -7,7 +7,7 @@ class LineItems:
77
def __init__(self, client: Client):
88
self.client = client
99

10-
def get_line_items(self, document_id):
10+
def get_line_items(self, document_id: int):
1111
"""
1212
Retrieve all line items for a document.
1313
https://docs.veryfi.com/api/receipts-invoices/get-document-line-items/
@@ -17,7 +17,7 @@ def get_line_items(self, document_id):
1717
"""
1818
return self.client._request("GET", f"/documents/{document_id}/line-items/")
1919

20-
def get_line_item(self, document_id, line_item_id):
20+
def get_line_item(self, document_id: int, line_item_id: int):
2121
"""
2222
Retrieve a line item for existing document by ID.
2323
https://docs.veryfi.com/api/receipts-invoices/get-a-line-item/
@@ -53,7 +53,7 @@ def update_line_item(self, document_id: int, line_item_id: int, payload: Dict) -
5353
"PUT", f"/documents/{document_id}/line-items/{line_item_id}", payload
5454
)
5555

56-
def delete_line_items(self, document_id):
56+
def delete_line_items(self, document_id: int):
5757
"""
5858
Delete all line items on an existing document.
5959
https://docs.veryfi.com/api/receipts-invoices/delete-all-document-line-items/
@@ -62,7 +62,7 @@ def delete_line_items(self, document_id):
6262
"""
6363
self.client._request("DELETE", f"/documents/{document_id}/line-items/")
6464

65-
def delete_line_item(self, document_id, line_item_id):
65+
def delete_line_item(self, document_id: int, line_item_id: int):
6666
"""
6767
Delete an existing line item on an existing document.
6868
https://docs.veryfi.com/api/receipts-invoices/delete-a-line-item/

veryfi/_documents/pdf_split.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, List, Optional
44

55
from veryfi.client_base import Client
66

veryfi/_documents/tags.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import *
21
from veryfi.client_base import Client
32

43

veryfi/_w2s/w2_split.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, List, Optional
44

55
from veryfi.client_base import Client
66

veryfi/a_docs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, List, Optional
44

55
from veryfi.client_base import Client
66

veryfi/bank_statements.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, Optional
44

55
from veryfi.client_base import Client
66

@@ -33,7 +33,7 @@ def process_bank_statement_document_url(
3333

3434
def process_bank_statement_document(
3535
self, file_path: str, file_name: Optional[str] = None, **kwargs
36-
):
36+
) -> Dict:
3737
"""
3838
Process bank statement document from url and extract all the fields from it.
3939
https://docs.veryfi.com/api/bank-statements/process-a-bank-statement/

veryfi/bussines_cards.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, Optional
44

55
from veryfi.client_base import Client
66

@@ -33,7 +33,7 @@ def process_bussines_card_document_url(
3333

3434
def process_bussines_card_document(
3535
self, file_path: str, file_name: Optional[str] = None, **kwargs
36-
):
36+
) -> Dict:
3737
"""
3838
Process bussiness card from url and extract all the fields from it.
3939
https://docs.veryfi.com/api/business-cards/process-a-business-card/
@@ -55,7 +55,7 @@ def process_bussines_card_document(
5555
request_arguments.update(kwargs)
5656
return self.client._request("POST", endpoint_name, request_arguments)
5757

58-
def get_business_cards(self, **kwargs: Dict):
58+
def get_business_cards(self, **kwargs):
5959
"""
6060
Get list of business card documents.
6161
https://docs.veryfi.com/api/business-cards/get-business-cards/
@@ -66,7 +66,7 @@ def get_business_cards(self, **kwargs: Dict):
6666
endpoint_name = "/business-cards/"
6767
return self.client._request("GET", endpoint_name, {}, kwargs)
6868

69-
def get_business_card(self, document_id: int, **kwargs: Dict):
69+
def get_business_card(self, document_id: int, **kwargs) -> Dict:
7070
"""
7171
Get a business card document.
7272
https://docs.veryfi.com/api/business-cards/get-a-business-card/

veryfi/checks.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, List, Optional
44

55
from veryfi.client_base import Client
66

@@ -16,7 +16,7 @@ def get_checks(
1616
created_date__lt: Optional[str] = None,
1717
created_date__lte: Optional[str] = None,
1818
**kwargs,
19-
) -> List[Dict]:
19+
):
2020
"""
2121
Get list of checks
2222
https://docs.veryfi.com/api/checks/get-checks/
@@ -59,7 +59,7 @@ def process_check(
5959
self,
6060
file_path: str,
6161
**kwargs,
62-
):
62+
) -> Dict:
6363
"""
6464
Process a check document and extract all the fields from it
6565
https://docs.veryfi.com/api/checks/process-a-check/

veryfi/client.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
class Client(ClientBase, ADocs, BankStatements, BussinesCards, Checks, Documents, W2s, W8s, W9s):
1414
def __init__(
1515
self,
16-
client_id,
17-
client_secret,
18-
username,
19-
api_key,
20-
base_url=ClientBase.BASE_URL,
21-
api_version=ClientBase.API_VERSION,
22-
timeout=ClientBase.API_TIMEOUT,
16+
client_id: str,
17+
client_secret: str,
18+
username: str,
19+
api_key: str,
20+
base_url: str = ClientBase.BASE_URL,
21+
api_version: str = ClientBase.API_VERSION,
22+
timeout: int = ClientBase.API_TIMEOUT,
2323
):
2424
super().__init__(
2525
client_id=client_id,

veryfi/client_base.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import hmac
55
import json
66
import time
7-
from typing import *
8-
from urllib.parse import urlencode
7+
from typing import Dict, Optional
98

109
from veryfi.errors import VeryfiClientError
1110

@@ -18,13 +17,13 @@ class Client:
1817

1918
def __init__(
2019
self,
21-
client_id,
22-
client_secret,
23-
username,
24-
api_key,
25-
base_url=BASE_URL,
26-
api_version=API_VERSION,
27-
timeout=API_TIMEOUT,
20+
client_id: str,
21+
client_secret: str,
22+
username: str,
23+
api_key: str,
24+
base_url: str = BASE_URL,
25+
api_version: str = API_VERSION,
26+
timeout: int = API_TIMEOUT,
2827
):
2928
self.client_id = client_id
3029
self.client_secret = client_secret
@@ -53,7 +52,13 @@ def _get_headers(self) -> Dict:
5352

5453
return final_headers
5554

56-
def _request(self, http_verb, endpoint_name, request_arguments=None, query_params=None):
55+
def _request(
56+
self,
57+
http_verb: str,
58+
endpoint_name: str,
59+
request_arguments: Optional[Dict] = None,
60+
query_params: Optional[Dict] = None,
61+
):
5762
"""
5863
Submit the HTTP request.
5964
:param http_verb: HTTP Method
@@ -62,7 +67,7 @@ def _request(self, http_verb, endpoint_name, request_arguments=None, query_param
6267
:return: A JSON of the response data.
6368
"""
6469
headers = self._get_headers()
65-
api_url = "{0}/partner{1}".format(self.versioned_url, endpoint_name)
70+
api_url = f"{self.versioned_url}/partner{endpoint_name}"
6671
request_arguments = request_arguments or {}
6772

6873
if self.client_secret:
@@ -89,7 +94,7 @@ def _request(self, http_verb, endpoint_name, request_arguments=None, query_param
8994

9095
return response.json()
9196

92-
def _generate_signature(self, payload_params, timestamp):
97+
def _generate_signature(self, payload_params: Dict, timestamp: int) -> str:
9398
"""
9499
Generate unique signature for payload params.
95100
:param payload_params: JSON params to be sent to API request

veryfi/documents.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, List, Optional
44

55
from veryfi._documents.line_items import LineItems
66
from veryfi._documents.tags import Tags
@@ -79,7 +79,7 @@ def get_documents(
7979
endpoint_name = "/documents/"
8080
return self.client._request("GET", endpoint_name, {}, query_params)
8181

82-
def get_document(self, document_id, **kwargs) -> Dict:
82+
def get_document(self, document_id: int, **kwargs) -> Dict:
8383
"""
8484
Retrieve document by ID
8585
https://docs.veryfi.com/api/receipts-invoices/get-a-document/

veryfi/w2s.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, Optional
44

55
from veryfi.client_base import Client
66
from veryfi._w2s.w2_split import W2Split
@@ -32,7 +32,9 @@ def process_w2_document_url(
3232
request_arguments.update(kwargs)
3333
return self.client._request("POST", endpoint_name, request_arguments)
3434

35-
def process_w2_document(self, file_path: str, file_name: Optional[str] = None, **kwargs):
35+
def process_w2_document(
36+
self, file_path: str, file_name: Optional[str] = None, **kwargs
37+
) -> Dict:
3638
"""
3739
Process W2 Document from url and extract all the fields from it.
3840
https://docs.veryfi.com/api/w2s/process-a-w-2/

veryfi/w8s.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, Optional
44

55
from veryfi.client_base import Client
66

@@ -10,7 +10,7 @@ def __init__(self, client: Client):
1010
self.client = client
1111

1212
def process_w8_document_url(
13-
self, file_url: str, file_name: Optional[str] = None, **kwargs: Dict
13+
self, file_url: str, file_name: Optional[str] = None, **kwargs
1414
) -> Dict:
1515
"""
1616
Process W2 Document from url and extract all the fields from it.
@@ -31,7 +31,9 @@ def process_w8_document_url(
3131
request_arguments.update(kwargs)
3232
return self.client._request("POST", endpoint_name, request_arguments)
3333

34-
def process_w8_document(self, file_path: str, file_name: Optional[str] = None, **kwargs):
34+
def process_w8_document(
35+
self, file_path: str, file_name: Optional[str] = None, **kwargs
36+
) -> Dict:
3537
"""
3638
Process W8 Document from url and extract all the fields from it.
3739
https://docs.veryfi.com/api/w-8ben-e/process-a-w-8-ben-e/
@@ -71,7 +73,7 @@ def get_w8s(
7173
created_date_gte: Optional[str] = None,
7274
created_date_lt: Optional[str] = None,
7375
created_date_lte: Optional[str] = None,
74-
**kwargs: Dict,
76+
**kwargs,
7577
):
7678
"""
7779
Get list of w8s documents

veryfi/w9s.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import base64
3-
from typing import *
3+
from typing import Dict, Optional
44

55
from veryfi.client_base import Client
66

@@ -31,7 +31,9 @@ def process_w9_document_url(
3131
request_arguments.update(kwargs)
3232
return self.client._request("POST", endpoint_name, request_arguments)
3333

34-
def process_w9_document(self, file_path: str, file_name: Optional[str] = None, **kwargs):
34+
def process_w9_document(
35+
self, file_path: str, file_name: Optional[str] = None, **kwargs
36+
) -> Dict:
3537
"""
3638
Process W9 Document from url and extract all the fields from it.
3739
https://docs.veryfi.com/api/w9s/process-a-w-9/
@@ -72,7 +74,7 @@ def get_w9s(
7274
created_date_gte: Optional[str] = None,
7375
created_date_lt: Optional[str] = None,
7476
created_date_lte: Optional[str] = None,
75-
**kwargs: Dict,
77+
**kwargs,
7678
):
7779
"""
7880
Get list of w9s documents

0 commit comments

Comments
 (0)