-
Notifications
You must be signed in to change notification settings - Fork 58
Services1 #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Services1 #274
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
class Address: | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class Address(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class ApiKey(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class Batch(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class Billing(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class Brand(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class CarrierAccount(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class CustomsInfo(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class CustomsItem(EasyPostObject): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,79 @@ | ||||||
from typing import ( | ||||||
Any, | ||||||
List, | ||||||
) | ||||||
|
||||||
from easypost.easypost_object import convert_to_easypost_object | ||||||
from easypost.models.batch import Batch | ||||||
from easypost.requestor import ( | ||||||
RequestMethod, | ||||||
Requestor, | ||||||
) | ||||||
from easypost.services.base_service import BaseService | ||||||
|
||||||
|
||||||
class BatchService(BaseService): | ||||||
def __init__(self, client): | ||||||
self._client = client | ||||||
self._model_class = Batch.__name__ | ||||||
|
||||||
def create(self, **params) -> List[Any]: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"""Create a Batch.""" | ||||||
return self._create_resource(self._model_class, **params) | ||||||
|
||||||
def all(self, **params) -> List[Any]: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"""Retrieve a list of Batches.""" | ||||||
return self._all_resources(self._model_class, **params) | ||||||
|
||||||
def retrieve(self, id) -> Batch: | ||||||
"""Retrieve an Batch.""" | ||||||
return self._retrieve_resource(self._model_class, id) | ||||||
|
||||||
def create_and_buy(self, **params) -> Batch: | ||||||
"""Create and buy a Batch in a single call.""" | ||||||
url = f"{self._class_url(self._model_class)}/create_and_buy" | ||||||
wrapped_params = {self._snakecase_name(self._model_class): params} | ||||||
|
||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=wrapped_params) | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) | ||||||
|
||||||
def buy(self, id: str, **params) -> Batch: | ||||||
"""Buy a Batch.""" | ||||||
url = f"{self._instance_url(self._model_class, id)}/buy" | ||||||
|
||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params) | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) | ||||||
|
||||||
def label(self, id: str, **params) -> Batch: | ||||||
"""Create a Batch label.""" | ||||||
url = f"{self._instance_url(self._model_class, id)}/label" | ||||||
|
||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params) | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) | ||||||
|
||||||
def remove_shipments(self, id: str, **params) -> Batch: | ||||||
"""Remove Shipments from a Batch.""" | ||||||
url = f"{self._instance_url(self._model_class, id)}/remove_shipments" | ||||||
|
||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params) | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) | ||||||
|
||||||
def add_shipments(self, id: str, **params) -> Batch: | ||||||
"""Add Shipments to a Batch.""" | ||||||
url = f"{self._instance_url(self._model_class, id)}/add_shipments" | ||||||
|
||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params) | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) | ||||||
|
||||||
def create_scan_form(self, id: str, **params) -> Batch: | ||||||
"""Create a ScanForm for a Batch.""" | ||||||
url = f"{self._instance_url(self._model_class, id)}/scan_form" | ||||||
|
||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params) | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from typing import ( | ||
Any, | ||
Dict, | ||
List, | ||
) | ||
|
||
from easypost.easypost_object import convert_to_easypost_object | ||
from easypost.error import Error | ||
from easypost.models.billing import Billing | ||
from easypost.requestor import ( | ||
RequestMethod, | ||
Requestor, | ||
) | ||
from easypost.services.base_service import BaseService | ||
|
||
|
||
class BillingService(BaseService): | ||
def __init__(self, client): | ||
self._client = client | ||
self._model_class = Billing.__name__ | ||
|
||
def fund_wallet(self, amount: str, priority: str = "primary") -> None: | ||
"""Fund your EasyPost wallet by charging your primary or secondary payment method on file.""" | ||
endpoint, payment_method_id = self._get_payment_method_info(priority=priority) | ||
|
||
url = f"{endpoint}/{payment_method_id}/charges" | ||
wrapped_params = {"amount": amount} | ||
|
||
Requestor(self._client).request(method=RequestMethod.POST, url=url, params=wrapped_params) | ||
|
||
def delete_payment_method(self, priority: str) -> None: | ||
"""Delete a payment method.""" | ||
endpoint, payment_method_id = self._get_payment_method_info(priority=priority) | ||
|
||
url = f"{endpoint}/{payment_method_id}" | ||
|
||
Requestor(self._client).request(method=RequestMethod.DELETE, url=url) | ||
|
||
def retrieve_payment_methods(self, **params) -> Dict[str, Any]: | ||
"""Retrieve payment methods.""" | ||
response, api_key = Requestor(self._client).request( | ||
method=RequestMethod.GET, | ||
url="/payment_methods", | ||
params=params, | ||
) | ||
|
||
if response.get("id") is None: | ||
raise Error(message="Billing has not been setup for this user. Please add a payment method.") | ||
|
||
return convert_to_easypost_object(response=response, api_key=api_key) | ||
|
||
def _get_payment_method_info(self, priority: str = "primary") -> List[str]: | ||
"""Get payment method info (type of the payment method and ID of the payment method)""" | ||
payment_methods = self.retrieve_payment_methods() | ||
|
||
payment_method_map = { | ||
"primary": "primary_payment_method", | ||
"secondary": "secondary_payment_method", | ||
} | ||
|
||
payment_method_to_use = payment_method_map.get(priority) | ||
error_string = "The chosen payment method is not valid. Please try again." | ||
|
||
if payment_method_to_use and payment_methods[payment_method_to_use]: | ||
payment_method_id = payment_methods[payment_method_to_use]["id"] | ||
if payment_method_id.startswith("card_"): | ||
endpoint = "/credit_cards" | ||
elif payment_method_id.startswith("bank_"): | ||
endpoint = "/bank_accounts" | ||
else: | ||
raise Error(message=error_string) | ||
else: | ||
raise Error(message=error_string) | ||
|
||
return [endpoint, payment_method_id] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||
from typing import ( | ||||||
Any, | ||||||
List, | ||||||
Optional, | ||||||
) | ||||||
|
||||||
from easypost.constant import _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS | ||||||
from easypost.easypost_object import convert_to_easypost_object | ||||||
from easypost.models.carrier_account import CarrierAccount | ||||||
from easypost.requestor import ( | ||||||
RequestMethod, | ||||||
Requestor, | ||||||
) | ||||||
from easypost.services.base_service import BaseService | ||||||
|
||||||
|
||||||
class CarrierAccountService(BaseService): | ||||||
def __init__(self, client): | ||||||
self._client = client | ||||||
self._model_class = CarrierAccount.__name__ | ||||||
|
||||||
def create(self, **params) -> CarrierAccount: | ||||||
"""Creates a CarrierAccount.""" | ||||||
carrier_account_type = params.get("type") | ||||||
|
||||||
if carrier_account_type is None: | ||||||
raise ValueError("Missing required parameter 'type'") | ||||||
|
||||||
url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type) | ||||||
wrapped_params = {self._snakecase_name(self._model_class): params} | ||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=wrapped_params) | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) | ||||||
|
||||||
def all(self, **params) -> List[Any]: | ||||||
"""Retrieve a list of CarrierAccounts.""" | ||||||
return self._all_resources(self._model_class, **params) | ||||||
|
||||||
def retrieve(self, id) -> CarrierAccount: | ||||||
"""Retrieve a CarrierAccount.""" | ||||||
return self._retrieve_resource(self._model_class, id) | ||||||
|
||||||
def update(self, id, **params) -> CarrierAccount: | ||||||
"""Update a CarrierAccount.""" | ||||||
return self._update_resource(self._model_class, id, **params) | ||||||
|
||||||
def delete(self, id): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"""Delete a CarrierAccount.""" | ||||||
self._delete_resource(self._model_class, id) | ||||||
|
||||||
def types(self) -> List[str]: | ||||||
"""Get the types of CarrierAccounts available to the User.""" | ||||||
response, api_key = Requestor(self._client).request(method=RequestMethod.GET, url="/carrier_types") | ||||||
|
||||||
return convert_to_easypost_object(response=response, api_key=api_key) | ||||||
|
||||||
def _select_carrier_account_creation_endpoint(self, carrier_account_type: Optional[Any]) -> str: | ||||||
"""Determines which API endpoint to use for the creation call.""" | ||||||
if carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS: | ||||||
return "/carrier_accounts/register" | ||||||
|
||||||
return "/carrier_accounts" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from easypost.models.customs_info import CustomsInfo | ||
from easypost.services.base_service import BaseService | ||
|
||
|
||
class CustomsInfoService(BaseService): | ||
def __init__(self, client): | ||
self._client = client | ||
self._model_class = CustomsInfo.__name__ | ||
|
||
def create(self, **params) -> CustomsInfo: | ||
"""Create a CustomsInfo.""" | ||
return self._create_resource(self._model_class, **params) | ||
|
||
def retrieve(self, id) -> CustomsInfo: | ||
"""Retrieve a CustomsInfo.""" | ||
return self._retrieve_resource(self._model_class, id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from easypost.models.customs_item import CustomsItem | ||
from easypost.services.base_service import BaseService | ||
|
||
|
||
class CustomsItemService(BaseService): | ||
def __init__(self, client): | ||
self._client = client | ||
self._model_class = CustomsItem.__name__ | ||
|
||
def create(self, **params) -> CustomsItem: | ||
"""Create a CustomsItem.""" | ||
return self._create_resource(self._model_class, **params) | ||
|
||
def retrieve(self, id) -> CustomsItem: | ||
"""Retrieve a CustomsItem.""" | ||
return self._retrieve_resource(self._model_class, id) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.