Skip to content

Commit

Permalink
Merge pull request #1535 from rusanpas/master
Browse files Browse the repository at this point in the history
  • Loading branch information
saleweaver committed Sep 16, 2024
2 parents b5032ae + 15dffad commit 848e4d3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion sp_api/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.6.37'
__version__ = '1.6.39'
39 changes: 26 additions & 13 deletions sp_api/api/shipping/shippingV2.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import enum
import os
import urllib.parse
from datetime import datetime

from sp_api.base import Client, sp_endpoint, fill_query_params, ApiResponse
from sp_api.base import Client, sp_endpoint, fill_query_params, ApiResponse, Marketplaces


class AmznShippingBusiness(str, enum.Enum):
AmazonShipping_US = "AmazonShipping_US"
AmazonShipping_IN = "AmazonShipping_IN"
AmazonShipping_UK = "AmazonShipping_UK"
AmazonShipping_UAE = "AmazonShipping_UAE"
AmazonShipping_SA = "AmazonShipping_SA"
AmazonShipping_EG = "AmazonShipping_EG"
AmazonShipping_IT = "AmazonShipping_IT"
AmazonShipping_ES = "AmazonShipping_ES"
AmazonShipping_FR = "AmazonShipping_FR"
AmazonShipping_JP = "AmazonShipping_JP"
US = "AmazonShipping_US"
IN = "AmazonShipping_IN"
UK = "AmazonShipping_UK"
AE = "AmazonShipping_UAE"
SA = "AmazonShipping_SA"
IT = "AmazonShipping_IT"
EG = "AmazonShipping_EG"
ES = "AmazonShipping_ES"
FR = "AmazonShipping_FR"
JP = "AmazonShipping_JP"

@classmethod
def has_key(cls, name):
return name in cls.__members__


class Shipping(Client):
Expand All @@ -26,11 +31,19 @@ class Shipping(Client):
Provides programmatic access to Amazon Shipping APIs.
"""

amzn_shipping_business: AmznShippingBusiness = AmznShippingBusiness.AmazonShipping_UK
amzn_shipping_business: AmznShippingBusiness = AmznShippingBusiness.US

def __init__(self, *args, **kwargs):
if 'amzn_shipping_business' in kwargs:
self.amzn_shipping_business = kwargs.pop('amzn_shipping_business', AmznShippingBusiness.AmazonShipping_UK)
self.amzn_shipping_business = kwargs.pop('amzn_shipping_business', AmznShippingBusiness.US)
else:
marketplace = args[0] if len(args) > 0 else Marketplaces.US
if os.environ.get('SP_API_DEFAULT_MARKETPLACE', None):
marketplace = Marketplaces[os.environ.get('SP_API_DEFAULT_MARKETPLACE')]

if AmznShippingBusiness.has_key(marketplace.name):
self.amzn_shipping_business = AmznShippingBusiness[marketplace.name]

super().__init__(*args, **kwargs)

@property
Expand Down
8 changes: 3 additions & 5 deletions tests/api/shipping/test_shipping_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_get_rates():
res = Shipping().get_rates(
res = Shipping(amzn_shipping_business=AmznShippingBusiness.UK).get_rates(
**{
"shipTo": {
"name": "Arlene Purdy",
Expand All @@ -25,7 +25,6 @@ def test_get_rates():
"email": "[email protected]",
"phoneNumber": "662-302-7817",
},
"shipDate": "2024-09-11T14:15:22Z",
"shipperInstruction": {
"deliveryNotes": "TEST"
},
Expand Down Expand Up @@ -184,7 +183,7 @@ def test_get_access_points():


def test_one_click_shipment():
res = Shipping().one_click_shipment(
res = Shipping(amzn_shipping_business=AmznShippingBusiness.UK).one_click_shipment(
**{
"shipTo": {
"name": "Arlene Purdy",
Expand All @@ -204,7 +203,6 @@ def test_one_click_shipment():
"email": "[email protected]",
"phoneNumber": "662-302-7817",
},
"shipDate": "2024-09-11T14:15:22Z",
"shipperInstruction": {
"deliveryNotes": "TEST"
},
Expand Down Expand Up @@ -261,4 +259,4 @@ def test_one_click_shipment():
assert res.errors is None
assert res.payload.get('shipmentId')
assert res.payload.get('packageDocumentDetails')[0]['trackingId']
assert len(res.payload.get('packageDocumentDetails')[0]['packageDocuments']) > 0
assert len(res.payload.get('packageDocumentDetails')[0]['packageDocuments']) > 0

0 comments on commit 848e4d3

Please sign in to comment.