|
1 |
| -from typing import Optional |
| 1 | +from typing import ( |
| 2 | + Any, |
| 3 | + Dict, |
| 4 | + List, |
| 5 | + Optional, |
| 6 | +) |
2 | 7 |
|
3 | 8 | from easypost.easypost_object import convert_to_easypost_object
|
4 | 9 | from easypost.requestor import (
|
|
10 | 15 |
|
11 | 16 | class Report(Resource):
|
12 | 17 | @classmethod
|
13 |
| - def create(cls, api_key: Optional[str] = None, **params): |
| 18 | + def create(cls, api_key: Optional[str] = None, **params) -> "Report": |
14 | 19 | """Create a report."""
|
15 | 20 | requestor = Requestor(local_api_key=api_key)
|
16 | 21 | url = f"{cls.class_url()}/{params.get('type')}"
|
17 | 22 | response, api_key = requestor.request(method=RequestMethod.POST, url=url, params=params)
|
18 | 23 | return convert_to_easypost_object(response=response, api_key=api_key)
|
19 | 24 |
|
20 | 25 | @classmethod
|
21 |
| - def all(cls, api_key: Optional[str] = None, **params): |
| 26 | + def all(cls, api_key: Optional[str] = None, **params) -> List["Report"]: |
22 | 27 | """Retrieve all reports."""
|
23 | 28 | requestor = Requestor(local_api_key=api_key)
|
24 |
| - url = f"{cls.class_url()}/{params.get('type')}" |
| 29 | + type = params.pop("type") |
| 30 | + url = f"{cls.class_url()}/{type}" |
| 31 | + response, api_key = requestor.request(method=RequestMethod.GET, url=url, params=params) |
| 32 | + response["type"] = type |
| 33 | + return convert_to_easypost_object(response=response, api_key=api_key) |
| 34 | + |
| 35 | + @classmethod |
| 36 | + def get_next_page( |
| 37 | + cls, |
| 38 | + reports: Dict[str, Any], |
| 39 | + page_size: int = None, |
| 40 | + api_key: Optional[str] = None, |
| 41 | + ) -> List["Report"]: |
| 42 | + """Get next page of Report collection""" |
| 43 | + requestor = Requestor(local_api_key=api_key) |
| 44 | + type = reports.get("type") |
| 45 | + url = f"{cls.class_url()}/{type}" |
| 46 | + params = { |
| 47 | + "before_id": reports["reports"][-1].id, |
| 48 | + "page_size": page_size, |
| 49 | + } |
25 | 50 | response, api_key = requestor.request(method=RequestMethod.GET, url=url, params=params)
|
26 | 51 | return convert_to_easypost_object(response=response, api_key=api_key)
|
0 commit comments