diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 434837b..51e4a77 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,24 +1,24 @@ lockVersion: 2.0.0 id: 986026b6-d725-4b86-9c4d-67f6e6904a30 management: - docChecksum: aca3a63b6749e3b713cb0c95f1e09457 + docChecksum: e240e27a9d6acb009884e70a11e9ee3e docVersion: "2018-02-08" - speakeasyVersion: 1.228.1 - generationVersion: 2.292.0 - releaseVersion: 3.0.0 - configChecksum: d46cb2777c6c5993e1a1dc3c7f0b2021 + speakeasyVersion: 1.234.0 + generationVersion: 2.298.0 + releaseVersion: 3.1.0 + configChecksum: 1754b12f688d2a6d73ce40ef13360df7 repoURL: https://github.com/goshippo/shippo-python-sdk.git installationURL: https://github.com/goshippo/shippo-python-sdk.git published: true features: python: constsAndDefaults: 0.1.3 - core: 4.5.2 + core: 4.6.0 flattening: 2.81.1 globalSecurity: 2.83.5 globalServerURLs: 2.82.2 includes: 2.81.1 - nameOverrides: 2.81.1 + nameOverrides: 2.81.2 responseFormat: 0.1.0 unions: 2.82.6 generatedFiles: @@ -65,7 +65,7 @@ generatedFiles: - src/shippo/models/components/parcelcreaterequest.py - src/shippo/models/components/parceltemplateenumset.py - src/shippo/models/components/weightunit.py - - src/shippo/models/components/distanceunittemplate.py + - src/shippo/models/components/distanceunit.py - src/shippo/models/components/shipmentextra.py - src/shippo/models/components/rmanumber.py - src/shippo/models/components/ponumber.py @@ -128,8 +128,6 @@ generatedFiles: - src/shippo/models/components/defaultparceltemplate.py - src/shippo/models/components/userparceltemplate.py - src/shippo/models/components/carrierparceltemplate.py - - src/shippo/models/components/distanceunit.py - - src/shippo/models/components/distanceunitusertemplate.py - src/shippo/models/components/defaultparceltemplateupdaterequest.py - src/shippo/models/components/manifestpaginatedlist.py - src/shippo/models/components/manifest.py @@ -160,10 +158,12 @@ generatedFiles: - src/shippo/models/components/track.py - src/shippo/models/components/trackingstatus.py - src/shippo/models/components/trackingstatussubstatus.py + - src/shippo/models/components/trackingstatusenum.py - src/shippo/models/components/trackingstatuslocationbase.py - src/shippo/models/components/tracksrequest.py - src/shippo/models/components/transactionpaginatedlist.py - src/shippo/models/components/transaction.py + - src/shippo/models/components/transactionstatusenum.py - src/shippo/models/components/transactioncreaterequest.py - src/shippo/models/components/instanttransactionrequestbody.py - src/shippo/models/components/userparceltemplatewithcarriertemplatecreaterequest.py @@ -273,7 +273,7 @@ generatedFiles: - docs/models/components/parceltemplatefedex.md - docs/models/components/parceltemplateenumset.md - docs/models/components/weightunit.md - - docs/models/components/distanceunittemplate.md + - docs/models/components/distanceunit.md - docs/models/components/ancillaryendorsement.md - docs/models/components/dangerousgoodscode.md - docs/models/components/lasershipattrs.md @@ -372,8 +372,6 @@ generatedFiles: - docs/models/components/defaultparceltemplate.md - docs/models/components/userparceltemplate.md - docs/models/components/carrierparceltemplate.md - - docs/models/components/distanceunit.md - - docs/models/components/distanceunitusertemplate.md - docs/models/components/defaultparceltemplateupdaterequest.md - docs/models/components/manifestpaginatedlist.md - docs/models/components/manifeststatus.md @@ -414,15 +412,15 @@ generatedFiles: - docs/models/components/shipmentstatus.md - docs/models/components/shipment.md - docs/models/components/track.md - - docs/models/components/trackingstatusstatus.md - docs/models/components/trackingstatus.md - docs/models/components/trackingstatussubstatus.md + - docs/models/components/trackingstatusenum.md - docs/models/components/trackingstatuslocationbase.md - docs/models/components/tracksrequest.md - docs/models/components/transactionpaginatedlist.md - docs/models/components/transactionmessages.md - - docs/models/components/transactionstatus.md - docs/models/components/transaction.md + - docs/models/components/transactionstatusenum.md - docs/models/components/transactioncreaterequest.md - docs/models/components/instanttransactionrequestbodylabelfiletype.md - docs/models/components/instanttransactionrequestbody.md diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 135ba0b..85d64ae 100755 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -12,7 +12,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: true python: - version: 3.0.0 + version: 3.1.0 additionalDependencies: dependencies: {} extraDependencies: @@ -34,4 +34,5 @@ python: maxMethodParams: 4 outputModelSuffix: output packageName: shippo + projectUrls: {} responseFormat: flat diff --git a/README.md b/README.md index 0aecf5a..5d7612e 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ import requests http_client = requests.Session() http_client.headers.update({'x-custom-header': 'someValue'}) -s = shippo.Shippo(client: http_client) +s = shippo.Shippo(client=http_client) ``` diff --git a/RELEASES.md b/RELEASES.md index 0f415a3..cc1f824 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -68,4 +68,14 @@ Based on: ### Generated - [python v3.0.0] . ### Releases -- [PyPI v3.0.0] https://pypi.org/project/shippo/3.0.0 - . \ No newline at end of file +- [PyPI v3.0.0] https://pypi.org/project/shippo/3.0.0 - . + +## 2024-04-02 18:22:30 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.234.0 (2.298.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [python v3.1.0] . +### Releases +- [PyPI v3.1.0] https://pypi.org/project/shippo/3.1.0 - . \ No newline at end of file diff --git a/docs/models/components/distanceunittemplate.md b/docs/models/components/distanceunittemplate.md deleted file mode 100644 index 6332c42..0000000 --- a/docs/models/components/distanceunittemplate.md +++ /dev/null @@ -1,15 +0,0 @@ -# DistanceUnitTemplate - -The measure unit used for length, width and height. Required if template is not specified. - - -## Values - -| Name | Value | -| ----- | ----- | -| `CM` | cm | -| `IN` | in | -| `FT` | ft | -| `M` | m | -| `MM` | mm | -| `YD` | yd | \ No newline at end of file diff --git a/docs/models/components/distanceunitusertemplate.md b/docs/models/components/distanceunitusertemplate.md deleted file mode 100644 index 0c69ff8..0000000 --- a/docs/models/components/distanceunitusertemplate.md +++ /dev/null @@ -1,15 +0,0 @@ -# DistanceUnitUserTemplate - -The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty. - - -## Values - -| Name | Value | -| ----- | ----- | -| `CM` | cm | -| `IN` | in | -| `FT` | ft | -| `M` | m | -| `MM` | mm | -| `YD` | yd | \ No newline at end of file diff --git a/docs/models/components/parcel.md b/docs/models/components/parcel.md index 94c719a..74733f9 100644 --- a/docs/models/components/parcel.md +++ b/docs/models/components/parcel.md @@ -5,7 +5,7 @@ | Field | Type | Required | Description | Example | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `distance_unit` | [components.DistanceUnitTemplate](../../models/components/distanceunittemplate.md) | :heavy_check_mark: | The measure unit used for length, width and height. Required if template is not specified. | in | +| `distance_unit` | [components.DistanceUnit](../../models/components/distanceunit.md) | :heavy_check_mark: | The measure unit used for length, width and height. | in | | `height` | *str* | :heavy_check_mark: | **Required if template is not specified**

Height of the parcel. Up to six digits in front and four digits after the decimal separator are accepted. | 1 | | `length` | *str* | :heavy_check_mark: | **Required if template is not specified**

Length of the Parcel. Up to six digits in front and four digits after the decimal separator are accepted. | 1 | | `mass_unit` | [components.WeightUnit](../../models/components/weightunit.md) | :heavy_check_mark: | The unit used for weight. | lb | diff --git a/docs/models/components/parcelcreaterequest.md b/docs/models/components/parcelcreaterequest.md index 631683a..4bbacb7 100644 --- a/docs/models/components/parcelcreaterequest.md +++ b/docs/models/components/parcelcreaterequest.md @@ -5,7 +5,7 @@ | Field | Type | Required | Description | Example | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `distance_unit` | [components.DistanceUnitTemplate](../../models/components/distanceunittemplate.md) | :heavy_check_mark: | The measure unit used for length, width and height. Required if template is not specified. | in | +| `distance_unit` | [components.DistanceUnit](../../models/components/distanceunit.md) | :heavy_check_mark: | The measure unit used for length, width and height. | in | | `height` | *str* | :heavy_check_mark: | **Required if template is not specified**

Height of the parcel. Up to six digits in front and four digits after the decimal separator are accepted. | 1 | | `length` | *str* | :heavy_check_mark: | **Required if template is not specified**

Length of the Parcel. Up to six digits in front and four digits after the decimal separator are accepted. | 1 | | `mass_unit` | [components.WeightUnit](../../models/components/weightunit.md) | :heavy_check_mark: | The unit used for weight. | lb | diff --git a/docs/models/components/parcelrequest.md b/docs/models/components/parcelrequest.md index b525b4a..86b91a5 100644 --- a/docs/models/components/parcelrequest.md +++ b/docs/models/components/parcelrequest.md @@ -5,7 +5,7 @@ | Field | Type | Required | Description | Example | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `distance_unit` | [components.DistanceUnitTemplate](../../models/components/distanceunittemplate.md) | :heavy_check_mark: | The measure unit used for length, width and height. Required if template is not specified. | in | +| `distance_unit` | [components.DistanceUnit](../../models/components/distanceunit.md) | :heavy_check_mark: | The measure unit used for length, width and height. | in | | `height` | *str* | :heavy_check_mark: | Required if template is not specified. Height of the parcel. Up to six digits in front and four digits after the decimal separator are accepted. | 1 | | `length` | *str* | :heavy_check_mark: | Required if template is not specified. Length of the Parcel. Up to six digits in front and four digits after the decimal separator are accepted. | 1 | | `mass_unit` | [components.WeightUnit](../../models/components/weightunit.md) | :heavy_check_mark: | The unit used for weight. | lb | diff --git a/docs/models/components/trackingstatus.md b/docs/models/components/trackingstatus.md index 45cfd65..30387b9 100644 --- a/docs/models/components/trackingstatus.md +++ b/docs/models/components/trackingstatus.md @@ -11,7 +11,7 @@ The latest tracking information of this shipment. | `object_created` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_check_mark: | N/A | | | `object_id` | *str* | :heavy_check_mark: | N/A | | | `object_updated` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_check_mark: | N/A | | -| `status` | [components.TrackingStatusStatus](../../models/components/trackingstatusstatus.md) | :heavy_check_mark: | Indicates the high level status of the shipment. | DELIVERED | +| `status` | [components.TrackingStatusEnum](../../models/components/trackingstatusenum.md) | :heavy_check_mark: | Indicates the high level status of the shipment. | DELIVERED | | `status_date` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_check_mark: | Date and time when the carrier scanned this tracking event. This is displayed in UTC. | 2016-07-23T00:00:00Z | | `status_details` | *str* | :heavy_check_mark: | The human-readable description of the status. | Your shipment has been delivered at the destination mailbox. | | `substatus` | [Optional[components.TrackingStatusSubstatus]](../../models/components/trackingstatussubstatus.md) | :heavy_minus_sign: | A finer-grained classification of the tracking event. | | \ No newline at end of file diff --git a/docs/models/components/trackingstatusstatus.md b/docs/models/components/trackingstatusenum.md similarity index 93% rename from docs/models/components/trackingstatusstatus.md rename to docs/models/components/trackingstatusenum.md index 8671536..335f472 100644 --- a/docs/models/components/trackingstatusstatus.md +++ b/docs/models/components/trackingstatusenum.md @@ -1,4 +1,4 @@ -# TrackingStatusStatus +# TrackingStatusEnum Indicates the high level status of the shipment. diff --git a/docs/models/components/transaction.md b/docs/models/components/transaction.md index 83a6ac5..8dbf4ac 100644 --- a/docs/models/components/transaction.md +++ b/docs/models/components/transaction.md @@ -18,8 +18,8 @@ | `object_updated` | [date](https://docs.python.org/3/library/datetime.html#date-objects) | :heavy_minus_sign: | Date and time of last Transaction update. | | | `qr_code_url` | *Optional[str]* | :heavy_minus_sign: | A URL pointing directly to the QR code in PNG format.
A value will only be returned if requested using qr_code_requested flag and the carrier provides such an option. | https://shippo-delivery.s3.amazonaws.com/96_qr_code.pdf?Signature=PEdWrp0mFWAGwJp7FW3b%2FeA2eyY%3D&Expires=1385930652&AWSAccessKeyId=AKIAJTHP3LLFMYAWALIA | | `rate` | *Optional[str]* | :heavy_minus_sign: | ID of the Rate object for which a Label has to be obtained.
Please note that only rates that are not older than 7 days can be purchased in order to ensure up-to-date pricing. | ec9f0d3adc9441449c85d315f0997fd5 | -| `status` | [Optional[components.TransactionStatus]](../../models/components/transactionstatus.md) | :heavy_minus_sign: | Indicates the status of the Transaction. | SUCCESS | +| `status` | [Optional[components.TransactionStatusEnum]](../../models/components/transactionstatusenum.md) | :heavy_minus_sign: | Indicates the status of the Transaction. | SUCCESS | | `test` | *Optional[bool]* | :heavy_minus_sign: | Indicates whether the object has been created in test mode. | | | `tracking_number` | *Optional[str]* | :heavy_minus_sign: | The carrier-specific tracking number that can be used to track the Shipment.
A value will only be returned if the Rate is for a trackable Shipment and if the Transactions has been processed successfully. | 9499907123456123456781 | -| `tracking_status` | *Optional[str]* | :heavy_minus_sign: | Indicates the high level status of the shipment: `UNKNOWN`, `DELIVERED`, `TRANSIT`, `FAILURE`, `RETURNED`. | UNKOWN | +| `tracking_status` | [Optional[components.TrackingStatusEnum]](../../models/components/trackingstatusenum.md) | :heavy_minus_sign: | Indicates the high level status of the shipment. | DELIVERED | | `tracking_url_provider` | *Optional[str]* | :heavy_minus_sign: | A link to track this item on the carrier-provided tracking website.
A value will only be returned if tracking is available and the carrier provides such a service. | https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=9499907123456123456781 | \ No newline at end of file diff --git a/docs/models/components/transactionstatus.md b/docs/models/components/transactionstatusenum.md similarity index 94% rename from docs/models/components/transactionstatus.md rename to docs/models/components/transactionstatusenum.md index 091c72a..527845c 100644 --- a/docs/models/components/transactionstatus.md +++ b/docs/models/components/transactionstatusenum.md @@ -1,4 +1,4 @@ -# TransactionStatus +# TransactionStatusEnum Indicates the status of the Transaction. diff --git a/docs/models/components/userparceltemplate.md b/docs/models/components/userparceltemplate.md index 311dc5f..77ae4ce 100644 --- a/docs/models/components/userparceltemplate.md +++ b/docs/models/components/userparceltemplate.md @@ -5,7 +5,7 @@ | Field | Type | Required | Description | Example | | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `distance_unit` | [Optional[components.DistanceUnitUserTemplate]](../../models/components/distanceunitusertemplate.md) | :heavy_minus_sign: | The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty. | in | +| `distance_unit` | [Optional[components.DistanceUnit]](../../models/components/distanceunit.md) | :heavy_minus_sign: | The measure unit used for length, width and height. | in | | `height` | *Optional[str]* | :heavy_minus_sign: | The height of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty. | 6 | | `length` | *Optional[str]* | :heavy_minus_sign: | The length of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty. | 10 | | `name` | *Optional[str]* | :heavy_minus_sign: | The name of the User Parcel Template | My Custom Template | diff --git a/docs/models/components/userparceltemplateupdaterequest.md b/docs/models/components/userparceltemplateupdaterequest.md index d268a74..7f27b3f 100644 --- a/docs/models/components/userparceltemplateupdaterequest.md +++ b/docs/models/components/userparceltemplateupdaterequest.md @@ -5,7 +5,7 @@ | Field | Type | Required | Description | Example | | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `distance_unit` | [components.DistanceUnitUserTemplate](../../models/components/distanceunitusertemplate.md) | :heavy_check_mark: | The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty. | in | +| `distance_unit` | [components.DistanceUnit](../../models/components/distanceunit.md) | :heavy_check_mark: | The measure unit used for length, width and height. | in | | `height` | *str* | :heavy_check_mark: | The height of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty. | 6 | | `length` | *str* | :heavy_check_mark: | The length of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty. | 10 | | `name` | *str* | :heavy_check_mark: | The name of the User Parcel Template | My Custom Template | diff --git a/docs/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.md b/docs/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.md index 19a800c..92d0f2e 100644 --- a/docs/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.md +++ b/docs/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.md @@ -5,7 +5,7 @@ | Field | Type | Required | Description | Example | | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `distance_unit` | [components.DistanceUnitUserTemplate](../../models/components/distanceunitusertemplate.md) | :heavy_check_mark: | The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty. | in | +| `distance_unit` | [components.DistanceUnit](../../models/components/distanceunit.md) | :heavy_check_mark: | The measure unit used for length, width and height. | in | | `height` | *str* | :heavy_check_mark: | The height of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty. | 6 | | `length` | *str* | :heavy_check_mark: | The length of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty. | 10 | | `name` | *str* | :heavy_check_mark: | The name of the User Parcel Template | My Custom Template | diff --git a/docs/models/operations/listtransactionsrequest.md b/docs/models/operations/listtransactionsrequest.md index c8d7ab5..5fc9346 100644 --- a/docs/models/operations/listtransactionsrequest.md +++ b/docs/models/operations/listtransactionsrequest.md @@ -3,8 +3,11 @@ ## Fields -| Field | Type | Required | Description | -| ---------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------- | -| `page` | *Optional[int]* | :heavy_minus_sign: | The page number you want to select | -| `results` | *Optional[int]* | :heavy_minus_sign: | The number of results to return per page (max 100) | -| `shippo_api_version` | *Optional[str]* | :heavy_minus_sign: | String used to pick a non-default API version to use | \ No newline at end of file +| Field | Type | Required | Description | Example | +| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | +| `rate` | *Optional[str]* | :heavy_minus_sign: | Filter by rate ID | | +| `object_status` | [Optional[components.TransactionStatusEnum]](../../models/components/transactionstatusenum.md) | :heavy_minus_sign: | Filter by object status | SUCCESS | +| `tracking_status` | [Optional[components.TrackingStatusEnum]](../../models/components/trackingstatusenum.md) | :heavy_minus_sign: | Filter by tracking status | DELIVERED | +| `page` | *Optional[int]* | :heavy_minus_sign: | The page number you want to select | | +| `results` | *Optional[int]* | :heavy_minus_sign: | The number of results to return per page (max 100) | | +| `shippo_api_version` | *Optional[str]* | :heavy_minus_sign: | String used to pick a non-default API version to use | | \ No newline at end of file diff --git a/docs/sdks/addresses/README.md b/docs/sdks/addresses/README.md index 2eb8179..91d1340 100644 --- a/docs/sdks/addresses/README.md +++ b/docs/sdks/addresses/README.md @@ -51,7 +51,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -106,7 +106,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -145,7 +145,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## validate @@ -184,4 +184,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/batches/README.md b/docs/sdks/batches/README.md index d3ee8a6..f6c784d 100644 --- a/docs/sdks/batches/README.md +++ b/docs/sdks/batches/README.md @@ -116,7 +116,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -158,7 +158,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## add_shipments @@ -182,7 +182,7 @@ res = s.batches.add_shipments(batch_id='', shippo_api_version='', address_to='', parcels=[ components.ParcelCreateRequest( - distance_unit=components.DistanceUnitTemplate.IN, + distance_unit=components.DistanceUnit.IN, height='1', length='1', mass_unit=components.WeightUnit.LB, @@ -227,7 +227,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## purchase @@ -269,7 +269,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## remove_shipments @@ -311,4 +311,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/carrieraccounts/README.md b/docs/sdks/carrieraccounts/README.md index 55e655c..1260b62 100644 --- a/docs/sdks/carrieraccounts/README.md +++ b/docs/sdks/carrieraccounts/README.md @@ -58,7 +58,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -129,7 +129,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------------------- | --------------------------- | --------------------------- | | errors.BadRequestWithDetail | 400 | application/json | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -168,7 +168,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## update @@ -212,7 +212,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## register @@ -256,7 +256,7 @@ if res is not None: | Error Object | Status Code | Content Type | | -------------------------- | -------------------------- | -------------------------- | | errors.BadRequestWithError | 400 | application/json | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get_registration_status @@ -296,4 +296,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/carrierparceltemplates/README.md b/docs/sdks/carrierparceltemplates/README.md index 7247ca7..27fff69 100644 --- a/docs/sdks/carrierparceltemplates/README.md +++ b/docs/sdks/carrierparceltemplates/README.md @@ -51,7 +51,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -90,4 +90,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/customsdeclarations/README.md b/docs/sdks/customsdeclarations/README.md index f67250d..19e947b 100644 --- a/docs/sdks/customsdeclarations/README.md +++ b/docs/sdks/customsdeclarations/README.md @@ -51,7 +51,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -115,7 +115,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -155,4 +155,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/customsitems/README.md b/docs/sdks/customsitems/README.md index 8d40126..8ce2e94 100644 --- a/docs/sdks/customsitems/README.md +++ b/docs/sdks/customsitems/README.md @@ -50,7 +50,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -100,7 +100,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -140,4 +140,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/manifests/README.md b/docs/sdks/manifests/README.md index 9b03219..21a6fbe 100644 --- a/docs/sdks/manifests/README.md +++ b/docs/sdks/manifests/README.md @@ -56,7 +56,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -118,7 +118,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -157,4 +157,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/orders/README.md b/docs/sdks/orders/README.md index f356449..a4a2ea8 100644 --- a/docs/sdks/orders/README.md +++ b/docs/sdks/orders/README.md @@ -61,7 +61,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -131,7 +131,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -170,4 +170,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/parcels/README.md b/docs/sdks/parcels/README.md index 306f9e7..d79ef35 100644 --- a/docs/sdks/parcels/README.md +++ b/docs/sdks/parcels/README.md @@ -54,7 +54,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -72,7 +72,7 @@ s = shippo.Shippo( res = s.parcels.create(shippo_api_version='', parcel_request=components.ParcelRequest( - distance_unit=components.DistanceUnitTemplate.IN, + distance_unit=components.DistanceUnit.IN, height='1', length='1', mass_unit=components.WeightUnit.LB, @@ -101,7 +101,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -140,4 +140,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/pickups/README.md b/docs/sdks/pickups/README.md index f447222..0cbff49 100644 --- a/docs/sdks/pickups/README.md +++ b/docs/sdks/pickups/README.md @@ -78,4 +78,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/rates/README.md b/docs/sdks/rates/README.md index efa6706..656b968 100644 --- a/docs/sdks/rates/README.md +++ b/docs/sdks/rates/README.md @@ -49,7 +49,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## list_shipment_rates @@ -90,7 +90,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## list_shipment_rates_by_currency_code @@ -139,4 +139,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/ratesatcheckout/README.md b/docs/sdks/ratesatcheckout/README.md index df7c3a7..56878d0 100644 --- a/docs/sdks/ratesatcheckout/README.md +++ b/docs/sdks/ratesatcheckout/README.md @@ -81,7 +81,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get_default_parcel_template @@ -119,7 +119,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## update_default_parcel_template @@ -161,7 +161,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## delete_default_parcel_template @@ -199,4 +199,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/refunds/README.md b/docs/sdks/refunds/README.md index 1e87c2e..9d82f5b 100644 --- a/docs/sdks/refunds/README.md +++ b/docs/sdks/refunds/README.md @@ -53,7 +53,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## list @@ -91,7 +91,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -130,4 +130,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/servicegroups/README.md b/docs/sdks/servicegroups/README.md index b02022d..b9e2e40 100644 --- a/docs/sdks/servicegroups/README.md +++ b/docs/sdks/servicegroups/README.md @@ -50,7 +50,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -105,7 +105,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## update @@ -162,7 +162,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## delete @@ -201,4 +201,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/shipments/README.md b/docs/sdks/shipments/README.md index 05f09a4..7582688 100644 --- a/docs/sdks/shipments/README.md +++ b/docs/sdks/shipments/README.md @@ -71,7 +71,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -154,7 +154,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -193,4 +193,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/shippoaccounts/README.md b/docs/sdks/shippoaccounts/README.md index e156e9f..97f68a2 100644 --- a/docs/sdks/shippoaccounts/README.md +++ b/docs/sdks/shippoaccounts/README.md @@ -53,7 +53,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -98,7 +98,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -137,7 +137,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## update @@ -183,4 +183,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/trackingstatus/README.md b/docs/sdks/trackingstatus/README.md index b76641b..ce248ea 100644 --- a/docs/sdks/trackingstatus/README.md +++ b/docs/sdks/trackingstatus/README.md @@ -63,7 +63,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------------------- | --------------------------- | --------------------------- | | errors.BadRequestWithDetail | 400 | application/json | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -104,4 +104,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------------------- | --------------------------- | --------------------------- | | errors.BadRequestWithDetail | 400 | application/json | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/transactions/README.md b/docs/sdks/transactions/README.md index 0620350..83cc3d1 100644 --- a/docs/sdks/transactions/README.md +++ b/docs/sdks/transactions/README.md @@ -20,13 +20,18 @@ Returns a list of all transaction objects. ```python import shippo +from shippo.models import components, operations s = shippo.Shippo( api_key_header="", ) +req = operations.ListTransactionsRequest( + object_status=components.TransactionStatusEnum.SUCCESS, + tracking_status=components.TrackingStatusEnum.DELIVERED, +) -res = s.transactions.list(page=1, results=25, shippo_api_version='') +res = s.transactions.list(req) if res is not None: # handle response @@ -36,11 +41,9 @@ if res is not None: ### Parameters -| Parameter | Type | Required | Description | -| ---------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------- | -| `page` | *Optional[int]* | :heavy_minus_sign: | The page number you want to select | -| `results` | *Optional[int]* | :heavy_minus_sign: | The number of results to return per page (max 100) | -| `shippo_api_version` | *Optional[str]* | :heavy_minus_sign: | String used to pick a non-default API version to use | +| Parameter | Type | Required | Description | +| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | +| `request` | [operations.ListTransactionsRequest](../../models/operations/listtransactionsrequest.md) | :heavy_check_mark: | The request object to use for the request. | ### Response @@ -50,7 +53,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -95,7 +98,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -134,4 +137,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/docs/sdks/userparceltemplates/README.md b/docs/sdks/userparceltemplates/README.md index dc8551c..cce4458 100644 --- a/docs/sdks/userparceltemplates/README.md +++ b/docs/sdks/userparceltemplates/README.md @@ -55,7 +55,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## create @@ -104,7 +104,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## delete @@ -143,7 +143,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## get @@ -183,7 +183,7 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | ## update @@ -201,7 +201,7 @@ s = shippo.Shippo( res = s.user_parcel_templates.update(user_parcel_template_object_id='', shippo_api_version='', user_parcel_template_update_request=components.UserParcelTemplateUpdateRequest( - distance_unit=components.DistanceUnitUserTemplate.IN, + distance_unit=components.DistanceUnit.IN, height='6', length='10', name='My Custom Template', @@ -232,4 +232,4 @@ if res is not None: | Error Object | Status Code | Content Type | | --------------- | --------------- | --------------- | -| errors.SDKError | 4x-5xx | */* | +| errors.SDKError | 4xx-5xx | */* | diff --git a/pylintrc b/pylintrc index 8537761..a165907 100644 --- a/pylintrc +++ b/pylintrc @@ -441,7 +441,8 @@ disable=raw-checker-failed, too-many-nested-blocks, too-many-boolean-expressions, no-else-raise, - bare-except + bare-except, + broad-exception-caught # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/setup.py b/setup.py index f647963..46cf395 100644 --- a/setup.py +++ b/setup.py @@ -10,9 +10,10 @@ setuptools.setup( name="shippo", - version="3.0.0", + version="3.1.0", author="Shippo", description="Python Client SDK Generated by Speakeasy", + url="https://github.com/goshippo/shippo-python-sdk.git", long_description=long_description, long_description_content_type="text/markdown", packages=setuptools.find_packages(where="src"), diff --git a/src/shippo/_hooks/sdkhooks.py b/src/shippo/_hooks/sdkhooks.py index 867a074..17750b6 100644 --- a/src/shippo/_hooks/sdkhooks.py +++ b/src/shippo/_hooks/sdkhooks.py @@ -3,7 +3,7 @@ import requests from .types import SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks from .registration import init_hooks -from typing import List, Optional, Tuple, Union +from typing import List, Optional, Tuple class SDKHooks(Hooks): @@ -31,19 +31,21 @@ def sdk_init(self, base_url: str, client: requests.Session) -> Tuple[str, reques base_url, client = hook.sdk_init(base_url, client) return base_url, client - def before_request(self, hook_ctx: BeforeRequestContext, request: requests.PreparedRequest) -> Union[requests.PreparedRequest, Exception]: + def before_request(self, hook_ctx: BeforeRequestContext, request: requests.PreparedRequest) -> requests.PreparedRequest: for hook in self.before_request_hooks: - request = hook.before_request(hook_ctx, request) - if isinstance(request, Exception): - raise request + out = hook.before_request(hook_ctx, request) + if isinstance(out, Exception): + raise out + request = out return request def after_success(self, hook_ctx: AfterSuccessContext, response: requests.Response) -> requests.Response: for hook in self.after_success_hooks: - response = hook.after_success(hook_ctx, response) - if isinstance(response, Exception): - raise response + out = hook.after_success(hook_ctx, response) + if isinstance(out, Exception): + raise out + response = out return response def after_error(self, hook_ctx: AfterErrorContext, response: Optional[requests.Response], error: Optional[Exception]) -> Tuple[Optional[requests.Response], Optional[Exception]]: diff --git a/src/shippo/_hooks/types.py b/src/shippo/_hooks/types.py index a643f3d..b24c141 100644 --- a/src/shippo/_hooks/types.py +++ b/src/shippo/_hooks/types.py @@ -17,15 +17,19 @@ def __init__(self, operation_id: str, oauth2_scopes: Optional[List[str]], securi class BeforeRequestContext(HookContext): - pass + def __init__(self, hook_ctx: HookContext): + super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source) class AfterSuccessContext(HookContext): - pass + def __init__(self, hook_ctx: HookContext): + super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source) + class AfterErrorContext(HookContext): - pass + def __init__(self, hook_ctx: HookContext): + super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source) class SDKInitHook(ABC): diff --git a/src/shippo/addresses.py b/src/shippo/addresses.py index 2d4bea9..8bbde81 100644 --- a/src/shippo/addresses.py +++ b/src/shippo/addresses.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -45,29 +45,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.AddressPaginatedList]) return out @@ -108,29 +107,28 @@ def create(self, shippo_api_version: Optional[str] = None, address_create_reques client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Address]) return out @@ -168,29 +166,28 @@ def get(self, address_id: str, shippo_api_version: Optional[str] = None) -> comp client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Address]) return out @@ -228,29 +225,28 @@ def validate(self, address_id: str, shippo_api_version: Optional[str] = None) -> client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Address]) return out diff --git a/src/shippo/batches.py b/src/shippo/batches.py index 9f0f259..f832284 100644 --- a/src/shippo/batches.py +++ b/src/shippo/batches.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import List, Optional @@ -54,29 +54,28 @@ def create(self, shippo_api_version: Optional[str] = None, batch_create_request: client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Batch]) return out @@ -117,29 +116,28 @@ def get(self, batch_id: str, shippo_api_version: Optional[str] = None) -> compon client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Batch]) return out @@ -181,29 +179,28 @@ def add_shipments(self, batch_id: str, shippo_api_version: Optional[str] = None, client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Batch]) return out @@ -244,29 +241,28 @@ def purchase(self, batch_id: str, shippo_api_version: Optional[str] = None) -> c client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Batch]) return out @@ -308,29 +304,28 @@ def remove_shipments(self, batch_id: str, shippo_api_version: Optional[str] = No client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Batch]) return out diff --git a/src/shippo/carrier_accounts.py b/src/shippo/carrier_accounts.py index 4e10874..5ccc689 100644 --- a/src/shippo/carrier_accounts.py +++ b/src/shippo/carrier_accounts.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional, Union @@ -44,29 +44,28 @@ def list(self, request: operations.ListCarrierAccountsRequest) -> components.Car client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CarrierAccountPaginatedList]) return out @@ -107,36 +106,35 @@ def create(self, shippo_api_version: Optional[str] = None, connect_existing_own_ client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['400','4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CarrierAccount]) return out content_type = http_res.headers.get('Content-Type') raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) elif http_res.status_code == 400: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, errors.BadRequestWithDetail) raise out @@ -174,29 +172,28 @@ def get(self, carrier_account_id: str, shippo_api_version: Optional[str] = None) client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CarrierAccount]) return out @@ -238,29 +235,28 @@ def update(self, carrier_account_id: str, shippo_api_version: Optional[str] = No client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CarrierAccount]) return out @@ -301,36 +297,35 @@ def register(self, shippo_api_version: Optional[str] = None, request_body: Optio client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['400','4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CarrierAccount]) return out content_type = http_res.headers.get('Content-Type') raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) elif http_res.status_code == 400: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, errors.BadRequestWithError) raise out @@ -369,29 +364,28 @@ def get_registration_status(self, carrier: operations.Carrier, shippo_api_versio client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CarrierAccountRegistrationStatus]) return out diff --git a/src/shippo/carrier_parcel_templates.py b/src/shippo/carrier_parcel_templates.py index 825f122..38f7432 100644 --- a/src/shippo/carrier_parcel_templates.py +++ b/src/shippo/carrier_parcel_templates.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import List, Optional @@ -46,29 +46,28 @@ def list(self, include: Optional[operations.Include] = None, carrier: Optional[s client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[List[components.CarrierParcelTemplate]]) return out @@ -106,29 +105,28 @@ def get(self, carrier_parcel_template_token: str, shippo_api_version: Optional[s client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CarrierParcelTemplate]) return out diff --git a/src/shippo/customs_declarations.py b/src/shippo/customs_declarations.py index a0cf27a..36ab467 100644 --- a/src/shippo/customs_declarations.py +++ b/src/shippo/customs_declarations.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -46,29 +46,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CustomsDeclarationPaginatedList]) return out @@ -109,29 +108,28 @@ def create(self, shippo_api_version: Optional[str] = None, customs_declaration_c client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CustomsDeclaration]) return out @@ -171,29 +169,28 @@ def get(self, customs_declaration_id: str, page: Optional[int] = None, shippo_ap client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CustomsDeclaration]) return out diff --git a/src/shippo/customs_items.py b/src/shippo/customs_items.py index 54a27d4..e9254e6 100644 --- a/src/shippo/customs_items.py +++ b/src/shippo/customs_items.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -45,29 +45,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CustomsItemPaginatedList]) return out @@ -108,29 +107,28 @@ def create(self, shippo_api_version: Optional[str] = None, customs_item_base: Op client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CustomsItem]) return out @@ -170,29 +168,28 @@ def get(self, customs_item_id: str, page: Optional[int] = None, shippo_api_versi client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.CustomsItem]) return out diff --git a/src/shippo/manifests.py b/src/shippo/manifests.py index c0cf15a..cf4a53c 100644 --- a/src/shippo/manifests.py +++ b/src/shippo/manifests.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -51,29 +51,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ManifestPaginatedList]) return out @@ -114,29 +113,28 @@ def create(self, shippo_api_version: Optional[str] = None, manifest_create_reque client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Manifest]) return out @@ -174,29 +172,28 @@ def get(self, manifest_id: str, shippo_api_version: Optional[str] = None) -> com client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Manifest]) return out diff --git a/src/shippo/models/components/__init__.py b/src/shippo/models/components/__init__.py index 1586119..2150412 100644 --- a/src/shippo/models/components/__init__.py +++ b/src/shippo/models/components/__init__.py @@ -55,8 +55,6 @@ from .defaultparceltemplateupdaterequest import * from .departmentnumber import * from .distanceunit import * -from .distanceunittemplate import * -from .distanceunitusertemplate import * from .dryice import * from .errormessage import * from .instanttransactionrequestbody import * @@ -110,12 +108,14 @@ from .shippoaccountupdaterequest import * from .track import * from .trackingstatus import * +from .trackingstatusenum import * from .trackingstatuslocationbase import * from .trackingstatussubstatus import * from .tracksrequest import * from .transaction import * from .transactioncreaterequest import * from .transactionpaginatedlist import * +from .transactionstatusenum import * from .upsconnectexistingownaccountparameters import * from .userparceltemplate import * from .userparceltemplateupdaterequest import * @@ -123,4 +123,4 @@ from .userparceltemplatewithoutcarriertemplatecreaterequest import * from .weightunit import * -__all__ = ["Address","AddressCompleteCreateRequest","AddressCreateRequest","AddressImporter","AddressPaginatedList","AddressValidationResults","AddressValidationResultsMessage","Alcohol","AncillaryEndorsement","Attributes","B13aFilingOption","Batch","BatchCreateRequest","BatchShipment","BatchShipmentBase","BatchShipmentPaginatedList","BatchStatus","Billing","BuildingLocationType","BuildingType","CarrierAccount","CarrierAccountBase","CarrierAccountCanadaPostCreateParameters","CarrierAccountCanadaPostCreateRequest","CarrierAccountChronopostCreateRequest","CarrierAccountColissimoCreateRequest","CarrierAccountColissimoCreateRequestParameters","CarrierAccountCorreosCreateRequest","CarrierAccountCorreosCreateRequestParameters","CarrierAccountDHLExpressCreateRequest","CarrierAccountDHLExpressCreateRequestParameters","CarrierAccountDPDUKCreateRequest","CarrierAccountDPDUKCreateRequestParameters","CarrierAccountDeutschePostCreateRequest","CarrierAccountDeutschePostCreateRequestParameters","CarrierAccountDpdDeCreateRequest","CarrierAccountDpdDeCreateRequestParameters","CarrierAccountHermesUKCreateRequest","CarrierAccountHermesUKCreateRequestParameters","CarrierAccountPaginatedList","CarrierAccountPosteItalianeCreateRequest","CarrierAccountPosteItalianeCreateRequestParameters","CarrierAccountRegistrationStatus","CarrierAccountServiceLevel","CarrierAccountUPSCreateRequest","CarrierAccountUPSCreateRequestParameters","CarrierAccountUSPSCreateRequest","CarrierAccountUSPSCreateRequestParameters","CarrierParcelTemplate","Carriers","Cod","Code","ConnectExistingOwnUPSAccountRequest","ContentsType","CustomerReference","CustomsDeclaration","CustomsDeclarationAddressImporter","CustomsDeclarationCreateRequest","CustomsDeclarationCreateRequestB13aFilingOption","CustomsDeclarationCreateRequestContentsType","CustomsDeclarationCreateRequestEelPfc","CustomsDeclarationCreateRequestIncoterm","CustomsDeclarationCreateRequestNonDeliveryOption","CustomsDeclarationPaginatedList","CustomsExporterIdentification","CustomsInvoicedCharges","CustomsItem","CustomsItemBase","CustomsItemPaginatedList","CustomsTaxIdentification","CustomsTaxIdentificationType","DangerousGoodsBiologicalMaterial","DangerousGoodsCode","DangerousGoodsLithiumBatteries","DangerousGoodsObject","DefaultParcelTemplate","DefaultParcelTemplateUpdateRequest","DepartmentNumber","DistanceUnit","DistanceUnitTemplate","DistanceUnitUserTemplate","DryIce","EelPfc","ErrorMessage","Incoterm","InstantTransactionRequestBody","InstantTransactionRequestBodyLabelFileType","Insurance","InvoiceNumber","LabelFileType","LasershipAttrs","LineItem","LineItemBase","LiveRate","LiveRateCreateRequest","LiveRatePaginatedList","Location","Manifest","ManifestCreateRequest","ManifestPaginatedList","ManifestStatus","Messages","NonDeliveryOption","ObjectResults","ObjectState","Order","OrderCreateRequest","OrderCreateRequestOrderStatus","OrderPaginatedList","OrderStatus","Parameters","Parcel","ParcelCreateRequest","ParcelExtra","ParcelInsurance","ParcelInsuranceProvider","ParcelObjectState","ParcelPaginatedList","ParcelRequest","ParcelTemplateAramexAustralia","ParcelTemplateCouriersPlease","ParcelTemplateDHLeCommerce","ParcelTemplateDPDUK","ParcelTemplateFedEx","ParcelTemplateUPS","ParcelTemplateUSPS","PaymentMethod","Pickup","PickupBase","PickupStatus","PoNumber","PreferredDeliveryTimeframe","Provider","Rate","RateMessage","RatePaginatedList","RecipientType","Refund","RefundPaginatedList","RefundRequestBody","RefundStatus","ReturnServiceType","RmaNumber","Security","ServiceGroup","ServiceGroupAccountAndServiceLevel","ServiceGroupCreateRequest","ServiceGroupType","ServiceGroupUpdateRequest","ServiceLevel","ServiceLevelAPCPostal","ServiceLevelAPG","ServiceLevelAirterra","ServiceLevelAramexAustralia","ServiceLevelAsendia","ServiceLevelAustraliaPost","ServiceLevelAxleHire","ServiceLevelBetterTrucks","ServiceLevelCDL","ServiceLevelCanadaPost","ServiceLevelChronopost","ServiceLevelColissimo","ServiceLevelCorreosEspana","ServiceLevelCouriersPlease","ServiceLevelDHLExpress","ServiceLevelDHLGermany","ServiceLevelDHLeCommerce","ServiceLevelDPDDE","ServiceLevelDPDUK","ServiceLevelDeutschePost","ServiceLevelEvriUK","ServiceLevelFedEx","ServiceLevelGLSUS","ServiceLevelGlobegistics","ServiceLevelLSO","ServiceLevelLasership","ServiceLevelMaergo","ServiceLevelMondialRelay","ServiceLevelOnTrac","ServiceLevelParcelforce","ServiceLevelPostItaliane","ServiceLevelPurolator","ServiceLevelRoyalMail","ServiceLevelSendle","ServiceLevelSwyft","ServiceLevelUDS","ServiceLevelUPS","ServiceLevelUSPS","ServiceLevelVeho","ServiceLevelePostGlobal","Shipment","ShipmentCreateRequest","ShipmentExtra","ShipmentPaginatedList","ShipmentStatus","ShippoAccount","ShippoAccountPaginatedList","ShippoAccountUpdateRequest","ShopApp","SignatureConfirmation","Source","Status","Track","TrackingStatus","TrackingStatusLocationBase","TrackingStatusStatus","TrackingStatusSubstatus","TracksRequest","Transaction","TransactionCreateRequest","TransactionMessages","TransactionPaginatedList","TransactionStatus","Type","UPSConnectExistingOwnAccountParameters","UserParcelTemplate","UserParcelTemplateUpdateRequest","UserParcelTemplateWithCarrierTemplateCreateRequest","UserParcelTemplateWithoutCarrierTemplateCreateRequest","WeightUnit"] +__all__ = ["Address","AddressCompleteCreateRequest","AddressCreateRequest","AddressImporter","AddressPaginatedList","AddressValidationResults","AddressValidationResultsMessage","Alcohol","AncillaryEndorsement","Attributes","B13aFilingOption","Batch","BatchCreateRequest","BatchShipment","BatchShipmentBase","BatchShipmentPaginatedList","BatchStatus","Billing","BuildingLocationType","BuildingType","CarrierAccount","CarrierAccountBase","CarrierAccountCanadaPostCreateParameters","CarrierAccountCanadaPostCreateRequest","CarrierAccountChronopostCreateRequest","CarrierAccountColissimoCreateRequest","CarrierAccountColissimoCreateRequestParameters","CarrierAccountCorreosCreateRequest","CarrierAccountCorreosCreateRequestParameters","CarrierAccountDHLExpressCreateRequest","CarrierAccountDHLExpressCreateRequestParameters","CarrierAccountDPDUKCreateRequest","CarrierAccountDPDUKCreateRequestParameters","CarrierAccountDeutschePostCreateRequest","CarrierAccountDeutschePostCreateRequestParameters","CarrierAccountDpdDeCreateRequest","CarrierAccountDpdDeCreateRequestParameters","CarrierAccountHermesUKCreateRequest","CarrierAccountHermesUKCreateRequestParameters","CarrierAccountPaginatedList","CarrierAccountPosteItalianeCreateRequest","CarrierAccountPosteItalianeCreateRequestParameters","CarrierAccountRegistrationStatus","CarrierAccountServiceLevel","CarrierAccountUPSCreateRequest","CarrierAccountUPSCreateRequestParameters","CarrierAccountUSPSCreateRequest","CarrierAccountUSPSCreateRequestParameters","CarrierParcelTemplate","Carriers","Cod","Code","ConnectExistingOwnUPSAccountRequest","ContentsType","CustomerReference","CustomsDeclaration","CustomsDeclarationAddressImporter","CustomsDeclarationCreateRequest","CustomsDeclarationCreateRequestB13aFilingOption","CustomsDeclarationCreateRequestContentsType","CustomsDeclarationCreateRequestEelPfc","CustomsDeclarationCreateRequestIncoterm","CustomsDeclarationCreateRequestNonDeliveryOption","CustomsDeclarationPaginatedList","CustomsExporterIdentification","CustomsInvoicedCharges","CustomsItem","CustomsItemBase","CustomsItemPaginatedList","CustomsTaxIdentification","CustomsTaxIdentificationType","DangerousGoodsBiologicalMaterial","DangerousGoodsCode","DangerousGoodsLithiumBatteries","DangerousGoodsObject","DefaultParcelTemplate","DefaultParcelTemplateUpdateRequest","DepartmentNumber","DistanceUnit","DryIce","EelPfc","ErrorMessage","Incoterm","InstantTransactionRequestBody","InstantTransactionRequestBodyLabelFileType","Insurance","InvoiceNumber","LabelFileType","LasershipAttrs","LineItem","LineItemBase","LiveRate","LiveRateCreateRequest","LiveRatePaginatedList","Location","Manifest","ManifestCreateRequest","ManifestPaginatedList","ManifestStatus","Messages","NonDeliveryOption","ObjectResults","ObjectState","Order","OrderCreateRequest","OrderCreateRequestOrderStatus","OrderPaginatedList","OrderStatus","Parameters","Parcel","ParcelCreateRequest","ParcelExtra","ParcelInsurance","ParcelInsuranceProvider","ParcelObjectState","ParcelPaginatedList","ParcelRequest","ParcelTemplateAramexAustralia","ParcelTemplateCouriersPlease","ParcelTemplateDHLeCommerce","ParcelTemplateDPDUK","ParcelTemplateFedEx","ParcelTemplateUPS","ParcelTemplateUSPS","PaymentMethod","Pickup","PickupBase","PickupStatus","PoNumber","PreferredDeliveryTimeframe","Provider","Rate","RateMessage","RatePaginatedList","RecipientType","Refund","RefundPaginatedList","RefundRequestBody","RefundStatus","ReturnServiceType","RmaNumber","Security","ServiceGroup","ServiceGroupAccountAndServiceLevel","ServiceGroupCreateRequest","ServiceGroupType","ServiceGroupUpdateRequest","ServiceLevel","ServiceLevelAPCPostal","ServiceLevelAPG","ServiceLevelAirterra","ServiceLevelAramexAustralia","ServiceLevelAsendia","ServiceLevelAustraliaPost","ServiceLevelAxleHire","ServiceLevelBetterTrucks","ServiceLevelCDL","ServiceLevelCanadaPost","ServiceLevelChronopost","ServiceLevelColissimo","ServiceLevelCorreosEspana","ServiceLevelCouriersPlease","ServiceLevelDHLExpress","ServiceLevelDHLGermany","ServiceLevelDHLeCommerce","ServiceLevelDPDDE","ServiceLevelDPDUK","ServiceLevelDeutschePost","ServiceLevelEvriUK","ServiceLevelFedEx","ServiceLevelGLSUS","ServiceLevelGlobegistics","ServiceLevelLSO","ServiceLevelLasership","ServiceLevelMaergo","ServiceLevelMondialRelay","ServiceLevelOnTrac","ServiceLevelParcelforce","ServiceLevelPostItaliane","ServiceLevelPurolator","ServiceLevelRoyalMail","ServiceLevelSendle","ServiceLevelSwyft","ServiceLevelUDS","ServiceLevelUPS","ServiceLevelUSPS","ServiceLevelVeho","ServiceLevelePostGlobal","Shipment","ShipmentCreateRequest","ShipmentExtra","ShipmentPaginatedList","ShipmentStatus","ShippoAccount","ShippoAccountPaginatedList","ShippoAccountUpdateRequest","ShopApp","SignatureConfirmation","Source","Status","Track","TrackingStatus","TrackingStatusEnum","TrackingStatusLocationBase","TrackingStatusSubstatus","TracksRequest","Transaction","TransactionCreateRequest","TransactionMessages","TransactionPaginatedList","TransactionStatusEnum","Type","UPSConnectExistingOwnAccountParameters","UserParcelTemplate","UserParcelTemplateUpdateRequest","UserParcelTemplateWithCarrierTemplateCreateRequest","UserParcelTemplateWithoutCarrierTemplateCreateRequest","WeightUnit"] diff --git a/src/shippo/models/components/distanceunittemplate.py b/src/shippo/models/components/distanceunittemplate.py deleted file mode 100644 index 0532dd7..0000000 --- a/src/shippo/models/components/distanceunittemplate.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" - -from __future__ import annotations -from enum import Enum - -class DistanceUnitTemplate(str, Enum): - r"""The measure unit used for length, width and height. Required if template is not specified.""" - CM = 'cm' - IN = 'in' - FT = 'ft' - M = 'm' - MM = 'mm' - YD = 'yd' diff --git a/src/shippo/models/components/distanceunitusertemplate.py b/src/shippo/models/components/distanceunitusertemplate.py deleted file mode 100644 index 23aea48..0000000 --- a/src/shippo/models/components/distanceunitusertemplate.py +++ /dev/null @@ -1,13 +0,0 @@ -"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" - -from __future__ import annotations -from enum import Enum - -class DistanceUnitUserTemplate(str, Enum): - r"""The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty.""" - CM = 'cm' - IN = 'in' - FT = 'ft' - M = 'm' - MM = 'mm' - YD = 'yd' diff --git a/src/shippo/models/components/parcel.py b/src/shippo/models/components/parcel.py index 5d876d0..0a9d095 100644 --- a/src/shippo/models/components/parcel.py +++ b/src/shippo/models/components/parcel.py @@ -3,7 +3,7 @@ from __future__ import annotations import dataclasses import dateutil.parser -from .distanceunittemplate import DistanceUnitTemplate +from .distanceunit import DistanceUnit from .parcelextra import ParcelExtra from .parceltemplateenumset import ParcelTemplateAramexAustralia, ParcelTemplateCouriersPlease, ParcelTemplateDHLeCommerce, ParcelTemplateDPDUK, ParcelTemplateFedEx, ParcelTemplateUPS, ParcelTemplateUSPS from .weightunit import WeightUnit @@ -21,8 +21,8 @@ class ParcelObjectState(str, Enum): @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class Parcel: - distance_unit: DistanceUnitTemplate = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) - r"""The measure unit used for length, width and height. Required if template is not specified.""" + distance_unit: DistanceUnit = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) + r"""The measure unit used for length, width and height.""" height: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('height') }}) r"""**Required if template is not specified**
Height of the parcel. Up to six digits in front and four digits after the decimal separator are accepted. diff --git a/src/shippo/models/components/parcelcreaterequest.py b/src/shippo/models/components/parcelcreaterequest.py index 7f1ce4a..45b2405 100644 --- a/src/shippo/models/components/parcelcreaterequest.py +++ b/src/shippo/models/components/parcelcreaterequest.py @@ -2,7 +2,7 @@ from __future__ import annotations import dataclasses -from .distanceunittemplate import DistanceUnitTemplate +from .distanceunit import DistanceUnit from .parceltemplateenumset import ParcelTemplateAramexAustralia, ParcelTemplateCouriersPlease, ParcelTemplateDHLeCommerce, ParcelTemplateDPDUK, ParcelTemplateFedEx, ParcelTemplateUPS, ParcelTemplateUSPS from .weightunit import WeightUnit from dataclasses_json import Undefined, dataclass_json @@ -13,8 +13,8 @@ @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class ParcelCreateRequest: - distance_unit: DistanceUnitTemplate = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) - r"""The measure unit used for length, width and height. Required if template is not specified.""" + distance_unit: DistanceUnit = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) + r"""The measure unit used for length, width and height.""" height: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('height') }}) r"""**Required if template is not specified**
Height of the parcel. Up to six digits in front and four digits after the decimal separator are accepted. diff --git a/src/shippo/models/components/parcelrequest.py b/src/shippo/models/components/parcelrequest.py index 2b95a29..155f262 100644 --- a/src/shippo/models/components/parcelrequest.py +++ b/src/shippo/models/components/parcelrequest.py @@ -2,7 +2,7 @@ from __future__ import annotations import dataclasses -from .distanceunittemplate import DistanceUnitTemplate +from .distanceunit import DistanceUnit from .parcelextra import ParcelExtra from .parceltemplateenumset import ParcelTemplateAramexAustralia, ParcelTemplateCouriersPlease, ParcelTemplateDHLeCommerce, ParcelTemplateDPDUK, ParcelTemplateFedEx, ParcelTemplateUPS, ParcelTemplateUSPS from .weightunit import WeightUnit @@ -14,8 +14,8 @@ @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class ParcelRequest: - distance_unit: DistanceUnitTemplate = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) - r"""The measure unit used for length, width and height. Required if template is not specified.""" + distance_unit: DistanceUnit = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) + r"""The measure unit used for length, width and height.""" height: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('height') }}) r"""Required if template is not specified. Height of the parcel. Up to six digits in front and four digits after the decimal separator are accepted.""" length: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('length') }}) diff --git a/src/shippo/models/components/trackingstatus.py b/src/shippo/models/components/trackingstatus.py index 5c59f4d..74ce6e4 100644 --- a/src/shippo/models/components/trackingstatus.py +++ b/src/shippo/models/components/trackingstatus.py @@ -3,23 +3,14 @@ from __future__ import annotations import dataclasses import dateutil.parser +from .trackingstatusenum import TrackingStatusEnum from .trackingstatuslocationbase import TrackingStatusLocationBase from .trackingstatussubstatus import TrackingStatusSubstatus from dataclasses_json import Undefined, dataclass_json from datetime import datetime -from enum import Enum from shippo import utils from typing import Optional -class TrackingStatusStatus(str, Enum): - r"""Indicates the high level status of the shipment.""" - UNKNOWN = 'UNKNOWN' - PRE_TRANSIT = 'PRE_TRANSIT' - TRANSIT = 'TRANSIT' - DELIVERED = 'DELIVERED' - RETURNED = 'RETURNED' - FAILURE = 'FAILURE' - @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass @@ -30,7 +21,7 @@ class TrackingStatus: object_created: datetime = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('object_created'), 'encoder': utils.datetimeisoformat(False), 'decoder': dateutil.parser.isoparse }}) object_id: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('object_id') }}) object_updated: datetime = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('object_updated'), 'encoder': utils.datetimeisoformat(False), 'decoder': dateutil.parser.isoparse }}) - status: TrackingStatusStatus = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('status') }}) + status: TrackingStatusEnum = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('status') }}) r"""Indicates the high level status of the shipment.""" status_date: datetime = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('status_date'), 'encoder': utils.datetimeisoformat(False), 'decoder': dateutil.parser.isoparse }}) r"""Date and time when the carrier scanned this tracking event. This is displayed in UTC.""" diff --git a/src/shippo/models/components/trackingstatusenum.py b/src/shippo/models/components/trackingstatusenum.py new file mode 100644 index 0000000..c2458f6 --- /dev/null +++ b/src/shippo/models/components/trackingstatusenum.py @@ -0,0 +1,13 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +from __future__ import annotations +from enum import Enum + +class TrackingStatusEnum(str, Enum): + r"""Indicates the high level status of the shipment.""" + UNKNOWN = 'UNKNOWN' + PRE_TRANSIT = 'PRE_TRANSIT' + TRANSIT = 'TRANSIT' + DELIVERED = 'DELIVERED' + RETURNED = 'RETURNED' + FAILURE = 'FAILURE' diff --git a/src/shippo/models/components/transaction.py b/src/shippo/models/components/transaction.py index 1bf88d6..e8b87ca 100644 --- a/src/shippo/models/components/transaction.py +++ b/src/shippo/models/components/transaction.py @@ -5,9 +5,10 @@ import dateutil.parser from .labelfiletype import LabelFileType from .objectstate import ObjectState +from .trackingstatusenum import TrackingStatusEnum +from .transactionstatusenum import TransactionStatusEnum from dataclasses_json import Undefined, dataclass_json from datetime import datetime -from enum import Enum from shippo import utils from typing import List, Optional @@ -16,16 +17,6 @@ class TransactionMessages: pass -class TransactionStatus(str, Enum): - r"""Indicates the status of the Transaction.""" - WAITING = 'WAITING' - QUEUED = 'QUEUED' - SUCCESS = 'SUCCESS' - ERROR = 'ERROR' - REFUNDED = 'REFUNDED' - REFUNDPENDING = 'REFUNDPENDING' - REFUNDREJECTED = 'REFUNDREJECTED' - @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass @@ -71,7 +62,7 @@ class Transaction: r"""ID of the Rate object for which a Label has to be obtained. Please note that only rates that are not older than 7 days can be purchased in order to ensure up-to-date pricing. """ - status: Optional[TransactionStatus] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('status'), 'exclude': lambda f: f is None }}) + status: Optional[TransactionStatusEnum] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('status'), 'exclude': lambda f: f is None }}) r"""Indicates the status of the Transaction.""" test: Optional[bool] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('test'), 'exclude': lambda f: f is None }}) r"""Indicates whether the object has been created in test mode.""" @@ -79,8 +70,8 @@ class Transaction: r"""The carrier-specific tracking number that can be used to track the Shipment. A value will only be returned if the Rate is for a trackable Shipment and if the Transactions has been processed successfully. """ - tracking_status: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('tracking_status'), 'exclude': lambda f: f is None }}) - r"""Indicates the high level status of the shipment: `UNKNOWN`, `DELIVERED`, `TRANSIT`, `FAILURE`, `RETURNED`.""" + tracking_status: Optional[TrackingStatusEnum] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('tracking_status'), 'exclude': lambda f: f is None }}) + r"""Indicates the high level status of the shipment.""" tracking_url_provider: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('tracking_url_provider'), 'exclude': lambda f: f is None }}) r"""A link to track this item on the carrier-provided tracking website. A value will only be returned if tracking is available and the carrier provides such a service. diff --git a/src/shippo/models/components/transactionstatusenum.py b/src/shippo/models/components/transactionstatusenum.py new file mode 100644 index 0000000..8a88009 --- /dev/null +++ b/src/shippo/models/components/transactionstatusenum.py @@ -0,0 +1,14 @@ +"""Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.""" + +from __future__ import annotations +from enum import Enum + +class TransactionStatusEnum(str, Enum): + r"""Indicates the status of the Transaction.""" + WAITING = 'WAITING' + QUEUED = 'QUEUED' + SUCCESS = 'SUCCESS' + ERROR = 'ERROR' + REFUNDED = 'REFUNDED' + REFUNDPENDING = 'REFUNDPENDING' + REFUNDREJECTED = 'REFUNDREJECTED' diff --git a/src/shippo/models/components/userparceltemplate.py b/src/shippo/models/components/userparceltemplate.py index 71eb21d..21929a3 100644 --- a/src/shippo/models/components/userparceltemplate.py +++ b/src/shippo/models/components/userparceltemplate.py @@ -4,7 +4,7 @@ import dataclasses import dateutil.parser from .carrierparceltemplate import CarrierParcelTemplate -from .distanceunitusertemplate import DistanceUnitUserTemplate +from .distanceunit import DistanceUnit from .weightunit import WeightUnit from dataclasses_json import Undefined, dataclass_json from datetime import datetime @@ -15,8 +15,8 @@ @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class UserParcelTemplate: - distance_unit: Optional[DistanceUnitUserTemplate] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit'), 'exclude': lambda f: f is None }}) - r"""The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty.""" + distance_unit: Optional[DistanceUnit] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit'), 'exclude': lambda f: f is None }}) + r"""The measure unit used for length, width and height.""" height: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('height'), 'exclude': lambda f: f is None }}) r"""The height of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty.""" length: Optional[str] = dataclasses.field(default=None, metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('length'), 'exclude': lambda f: f is None }}) diff --git a/src/shippo/models/components/userparceltemplateupdaterequest.py b/src/shippo/models/components/userparceltemplateupdaterequest.py index 2b7ff1d..3836744 100644 --- a/src/shippo/models/components/userparceltemplateupdaterequest.py +++ b/src/shippo/models/components/userparceltemplateupdaterequest.py @@ -2,7 +2,7 @@ from __future__ import annotations import dataclasses -from .distanceunitusertemplate import DistanceUnitUserTemplate +from .distanceunit import DistanceUnit from .weightunit import WeightUnit from dataclasses_json import Undefined, dataclass_json from shippo import utils @@ -12,8 +12,8 @@ @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class UserParcelTemplateUpdateRequest: - distance_unit: DistanceUnitUserTemplate = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) - r"""The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty.""" + distance_unit: DistanceUnit = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) + r"""The measure unit used for length, width and height.""" height: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('height') }}) r"""The height of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty.""" length: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('length') }}) diff --git a/src/shippo/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.py b/src/shippo/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.py index 5cb081a..1f823ae 100644 --- a/src/shippo/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.py +++ b/src/shippo/models/components/userparceltemplatewithoutcarriertemplatecreaterequest.py @@ -2,7 +2,7 @@ from __future__ import annotations import dataclasses -from .distanceunitusertemplate import DistanceUnitUserTemplate +from .distanceunit import DistanceUnit from .weightunit import WeightUnit from dataclasses_json import Undefined, dataclass_json from shippo import utils @@ -12,8 +12,8 @@ @dataclass_json(undefined=Undefined.EXCLUDE) @dataclasses.dataclass class UserParcelTemplateWithoutCarrierTemplateCreateRequest: - distance_unit: DistanceUnitUserTemplate = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) - r"""The measure unit used for length, width and height. Required, but if using a preset carrier template then this field must be empty.""" + distance_unit: DistanceUnit = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('distance_unit') }}) + r"""The measure unit used for length, width and height.""" height: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('height') }}) r"""The height of the package, in units specified by the `distance_unit` attribute. Required, but if using a preset carrier template then this field must be empty.""" length: str = dataclasses.field(metadata={'dataclasses_json': { 'letter_case': utils.get_field_name('length') }}) diff --git a/src/shippo/models/operations/listtransactions.py b/src/shippo/models/operations/listtransactions.py index 18bc237..2d706dd 100644 --- a/src/shippo/models/operations/listtransactions.py +++ b/src/shippo/models/operations/listtransactions.py @@ -2,11 +2,19 @@ from __future__ import annotations import dataclasses +from ...models.components import trackingstatusenum as components_trackingstatusenum +from ...models.components import transactionstatusenum as components_transactionstatusenum from typing import Optional @dataclasses.dataclass class ListTransactionsRequest: + rate: Optional[str] = dataclasses.field(default=None, metadata={'query_param': { 'field_name': 'rate', 'style': 'form', 'explode': True }}) + r"""Filter by rate ID""" + object_status: Optional[components_transactionstatusenum.TransactionStatusEnum] = dataclasses.field(default=None, metadata={'query_param': { 'field_name': 'object_status', 'style': 'form', 'explode': True }}) + r"""Filter by object status""" + tracking_status: Optional[components_trackingstatusenum.TrackingStatusEnum] = dataclasses.field(default=None, metadata={'query_param': { 'field_name': 'tracking_status', 'style': 'form', 'explode': True }}) + r"""Filter by tracking status""" page: Optional[int] = dataclasses.field(default=1, metadata={'query_param': { 'field_name': 'page', 'style': 'form', 'explode': True }}) r"""The page number you want to select""" results: Optional[int] = dataclasses.field(default=25, metadata={'query_param': { 'field_name': 'results', 'style': 'form', 'explode': True }}) diff --git a/src/shippo/orders.py b/src/shippo/orders.py index c8285c8..c76c69c 100644 --- a/src/shippo/orders.py +++ b/src/shippo/orders.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -56,29 +56,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.OrderPaginatedList]) return out @@ -119,29 +118,28 @@ def create(self, shippo_api_version: Optional[str] = None, order_create_request: client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Order]) return out @@ -179,29 +177,28 @@ def get(self, order_id: str, shippo_api_version: Optional[str] = None) -> compon client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Order]) return out diff --git a/src/shippo/parcels.py b/src/shippo/parcels.py index d60697b..5cff7d4 100644 --- a/src/shippo/parcels.py +++ b/src/shippo/parcels.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -49,29 +49,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ParcelPaginatedList]) return out @@ -112,29 +111,28 @@ def create(self, shippo_api_version: Optional[str] = None, parcel_request: Optio client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Parcel]) return out @@ -172,29 +170,28 @@ def get(self, parcel_id: str, shippo_api_version: Optional[str] = None) -> compo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Parcel]) return out diff --git a/src/shippo/pickups.py b/src/shippo/pickups.py index b9f5233..70cec4e 100644 --- a/src/shippo/pickups.py +++ b/src/shippo/pickups.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -47,29 +47,28 @@ def create(self, shippo_api_version: Optional[str] = None, pickup_base: Optional client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Pickup]) return out diff --git a/src/shippo/rates.py b/src/shippo/rates.py index 2812dd4..0e376f7 100644 --- a/src/shippo/rates.py +++ b/src/shippo/rates.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -43,29 +43,28 @@ def get(self, rate_id: str, shippo_api_version: Optional[str] = None) -> compone client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Rate]) return out @@ -106,29 +105,28 @@ def list_shipment_rates(self, shipment_id: str, page: Optional[int] = None, resu client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.RatePaginatedList]) return out @@ -168,29 +166,28 @@ def list_shipment_rates_by_currency_code(self, request: operations.ListShipmentR client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.RatePaginatedList]) return out diff --git a/src/shippo/rates_at_checkout.py b/src/shippo/rates_at_checkout.py index 1fbda82..b54a91a 100644 --- a/src/shippo/rates_at_checkout.py +++ b/src/shippo/rates_at_checkout.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -56,29 +56,28 @@ def create(self, shippo_api_version: Optional[str] = None, live_rate_create_requ client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.LiveRatePaginatedList]) return out @@ -115,29 +114,28 @@ def get_default_parcel_template(self, shippo_api_version: Optional[str] = None) client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.DefaultParcelTemplate]) return out @@ -178,29 +176,28 @@ def update_default_parcel_template(self, shippo_api_version: Optional[str] = Non client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.DefaultParcelTemplate]) return out @@ -237,24 +234,23 @@ def delete_default_parcel_template(self, shippo_api_version: Optional[str] = Non client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('DELETE', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('DELETE', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + res = operations.DeleteDefaultParcelTemplateResponse() diff --git a/src/shippo/refunds.py b/src/shippo/refunds.py index 57352a8..502a3f8 100644 --- a/src/shippo/refunds.py +++ b/src/shippo/refunds.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -46,29 +46,28 @@ def create(self, shippo_api_version: Optional[str] = None, refund_request_body: client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Refund]) return out @@ -105,29 +104,28 @@ def list(self, shippo_api_version: Optional[str] = None) -> components.RefundPag client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.RefundPaginatedList]) return out @@ -165,29 +163,28 @@ def get(self, refund_id: str, shippo_api_version: Optional[str] = None) -> compo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Refund]) return out diff --git a/src/shippo/sdk.py b/src/shippo/sdk.py index faf15c5..4f95209 100644 --- a/src/shippo/sdk.py +++ b/src/shippo/sdk.py @@ -21,6 +21,7 @@ from .tracking_status import TrackingStatus from .transactions import Transactions from .user_parcel_templates import UserParcelTemplates +from .utils.retries import RetryConfig from shippo import utils from shippo._hooks import SDKHooks from shippo.models import components @@ -174,7 +175,7 @@ def __init__(self, server_url: Optional[str] = None, url_params: Optional[Dict[str, str]] = None, client: Optional[requests_http.Session] = None, - retry_config: Optional[utils.RetryConfig] = None + retry_config: Optional[RetryConfig] = None ) -> None: """Instantiates the SDK configuring it with the provided parameters. @@ -189,7 +190,7 @@ def __init__(self, :param client: The requests.Session HTTP client to use for all operations :type client: requests_http.Session :param retry_config: The utils.RetryConfig to use globally - :type retry_config: utils.RetryConfig + :type retry_config: RetryConfig """ if client is None: client = requests_http.Session() diff --git a/src/shippo/sdkconfiguration.py b/src/shippo/sdkconfiguration.py index 9dcd2f4..b9def45 100644 --- a/src/shippo/sdkconfiguration.py +++ b/src/shippo/sdkconfiguration.py @@ -7,7 +7,7 @@ from .utils.retries import RetryConfig from dataclasses import dataclass from shippo.models import components -from typing import Callable, Dict, Tuple, Union +from typing import Callable, Dict, Optional, Tuple, Union SERVERS = [ @@ -19,18 +19,18 @@ class SDKConfiguration: client: requests_http.Session security: Union[components.Security,Callable[[], components.Security]] = None - server_url: str = '' - server_idx: int = 0 + server_url: Optional[str] = '' + server_idx: Optional[int] = 0 language: str = 'python' openapi_doc_version: str = '2018-02-08' - sdk_version: str = '3.0.0' - gen_version: str = '2.292.0' - user_agent: str = 'speakeasy-sdk/python 3.0.0 2.292.0 2018-02-08 shippo' - retry_config: RetryConfig = None - _hooks: SDKHooks = None + sdk_version: str = '3.1.0' + gen_version: str = '2.298.0' + user_agent: str = 'speakeasy-sdk/python 3.1.0 2.298.0 2018-02-08 shippo' + retry_config: Optional[RetryConfig] = None + _hooks: Optional[SDKHooks] = None def get_server_details(self) -> Tuple[str, Dict[str, str]]: - if self.server_url: + if self.server_url is not None and self.server_url != '': return utils.remove_suffix(self.server_url, '/'), {} if self.server_idx is None: self.server_idx = 0 diff --git a/src/shippo/service_groups.py b/src/shippo/service_groups.py index 9ba760c..bdb2827 100644 --- a/src/shippo/service_groups.py +++ b/src/shippo/service_groups.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import List, Optional @@ -43,29 +43,28 @@ def list(self, shippo_api_version: Optional[str] = None) -> List[components.Serv client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[List[components.ServiceGroup]]) return out @@ -106,29 +105,28 @@ def create(self, shippo_api_version: Optional[str] = None, service_group_create_ client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ServiceGroup]) return out @@ -169,29 +167,28 @@ def update(self, shippo_api_version: Optional[str] = None, service_group_update_ client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ServiceGroup]) return out @@ -229,24 +226,23 @@ def delete(self, service_group_id: str, shippo_api_version: Optional[str] = None client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('DELETE', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('DELETE', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + res = operations.DeleteServiceGroupResponse() diff --git a/src/shippo/shipments.py b/src/shippo/shipments.py index ce5f375..4cd4526 100644 --- a/src/shippo/shipments.py +++ b/src/shippo/shipments.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -66,29 +66,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ShipmentPaginatedList]) return out @@ -129,29 +128,28 @@ def create(self, shippo_api_version: Optional[str] = None, shipment_create_reque client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Shipment]) return out @@ -189,29 +187,28 @@ def get(self, shipment_id: str, shippo_api_version: Optional[str] = None) -> com client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Shipment]) return out diff --git a/src/shippo/shippo_accounts.py b/src/shippo/shippo_accounts.py index 8450f75..c9d8c67 100644 --- a/src/shippo/shippo_accounts.py +++ b/src/shippo/shippo_accounts.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -47,29 +47,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ShippoAccountPaginatedList]) return out @@ -110,29 +109,28 @@ def create(self, shippo_api_version: Optional[str] = None, shippo_account_update client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ShippoAccount]) return out @@ -170,29 +168,28 @@ def get(self, shippo_account_id: str, shippo_api_version: Optional[str] = None) client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ShippoAccount]) return out @@ -234,29 +231,28 @@ def update(self, shippo_account_id: str, shippo_api_version: Optional[str] = Non client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.ShippoAccount]) return out diff --git a/src/shippo/tracking_status.py b/src/shippo/tracking_status.py index 1d480da..29d2e46 100644 --- a/src/shippo/tracking_status.py +++ b/src/shippo/tracking_status.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional @@ -55,36 +55,35 @@ def create(self, shippo_api_version: Optional[str] = None, tracks_request: Optio client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['400','4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Track]) return out content_type = http_res.headers.get('Content-Type') raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) elif http_res.status_code == 400: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, errors.BadRequestWithDetail) raise out @@ -123,36 +122,35 @@ def get(self, tracking_number: str, carrier: str, shippo_api_version: Optional[s client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['400','4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Track]) return out content_type = http_res.headers.get('Content-Type') raise errors.SDKError(f'unknown content-type received: {content_type}', http_res.status_code, http_res.text, http_res) elif http_res.status_code == 400: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, errors.BadRequestWithDetail) raise out diff --git a/src/shippo/transactions.py b/src/shippo/transactions.py index 0a0d6aa..165b5e1 100644 --- a/src/shippo/transactions.py +++ b/src/shippo/transactions.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import Optional, Union @@ -18,17 +18,11 @@ def __init__(self, sdk_config: SDKConfiguration) -> None: - def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo_api_version: Optional[str] = None) -> components.TransactionPaginatedList: + def list(self, request: operations.ListTransactionsRequest) -> components.TransactionPaginatedList: r"""List all shipping labels Returns a list of all transaction objects. """ hook_ctx = HookContext(operation_id='ListTransactions', oauth2_scopes=[], security_source=self.sdk_configuration.security) - request = operations.ListTransactionsRequest( - page=page, - results=results, - shippo_api_version=shippo_api_version, - ) - base_url = utils.template_url(*self.sdk_configuration.get_server_details()) url = base_url + '/transactions' @@ -45,29 +39,28 @@ def list(self, page: Optional[int] = None, results: Optional[int] = None, shippo client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.TransactionPaginatedList]) return out @@ -108,29 +101,28 @@ def create(self, shippo_api_version: Optional[str] = None, request_body: Optiona client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 201: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Transaction]) return out @@ -168,29 +160,28 @@ def get(self, transaction_id: str, shippo_api_version: Optional[str] = None) -> client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.Transaction]) return out diff --git a/src/shippo/user_parcel_templates.py b/src/shippo/user_parcel_templates.py index a66f70a..7289401 100644 --- a/src/shippo/user_parcel_templates.py +++ b/src/shippo/user_parcel_templates.py @@ -3,7 +3,7 @@ import requests as requests_http from .sdkconfiguration import SDKConfiguration from shippo import utils -from shippo._hooks import HookContext +from shippo._hooks import AfterErrorContext, AfterSuccessContext, BeforeRequestContext, HookContext from shippo.models import components, errors, operations from typing import List, Optional, Union @@ -47,29 +47,28 @@ def list(self, shippo_api_version: Optional[str] = None) -> List[components.User client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[List[components.UserParcelTemplate]]) return out @@ -116,29 +115,28 @@ def create(self, shippo_api_version: Optional[str] = None, user_parcel_template_ client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('POST', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.UserParcelTemplate]) return out @@ -176,24 +174,23 @@ def delete(self, user_parcel_template_object_id: str, shippo_api_version: Option client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('DELETE', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('DELETE', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + res = operations.DeleteUserParcelTemplateResponse() @@ -235,29 +232,28 @@ def get(self, user_parcel_template_object_id: str, shippo_api_version: Optional[ client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('GET', url, params=query_params, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('GET', url, params=query_params, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.UserParcelTemplate]) return out @@ -299,29 +295,28 @@ def update(self, user_parcel_template_object_id: str, shippo_api_version: Option client = self.sdk_configuration.client try: - req = self.sdk_configuration.get_hooks().before_request( - hook_ctx, - requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers).prepare(), - ) + req = client.prepare_request(requests_http.Request('PUT', url, params=query_params, data=data, files=form, headers=headers)) + req = self.sdk_configuration.get_hooks().before_request(BeforeRequestContext(hook_ctx), req) http_res = client.send(req) except Exception as e: - _, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, None, e) - raise e + _, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), None, e) + if e is not None: + raise e if utils.match_status_codes(['4XX','5XX'], http_res.status_code): - http_res, e = self.sdk_configuration.get_hooks().after_error(hook_ctx, http_res, None) - if e: + result, e = self.sdk_configuration.get_hooks().after_error(AfterErrorContext(hook_ctx), http_res, None) + if e is not None: raise e + if result is not None: + http_res = result else: - result = self.sdk_configuration.get_hooks().after_success(hook_ctx, http_res) - if isinstance(result, Exception): - raise result - http_res = result + http_res = self.sdk_configuration.get_hooks().after_success(AfterSuccessContext(hook_ctx), http_res) + if http_res.status_code == 200: - if utils.match_content_type(http_res.headers.get('Content-Type'), 'application/json'): + if utils.match_content_type(http_res.headers.get('Content-Type') or '', 'application/json'): out = utils.unmarshal_json(http_res.text, Optional[components.UserParcelTemplate]) return out diff --git a/src/shippo/utils/retries.py b/src/shippo/utils/retries.py index 8eba094..dd35e6a 100644 --- a/src/shippo/utils/retries.py +++ b/src/shippo/utils/retries.py @@ -75,12 +75,12 @@ def do_request(): if res.status_code == parsed_code: raise TemporaryError(res) except requests.exceptions.ConnectionError as exception: - if retries.config.config.retry_connection_errors: + if retries.config.retry_connection_errors: raise raise PermanentError(exception) from exception except requests.exceptions.Timeout as exception: - if retries.config.config.retry_connection_errors: + if retries.config.retry_connection_errors: raise raise PermanentError(exception) from exception diff --git a/tests/test_instalabel.py b/tests/test_instalabel.py index 2866b81..9dd498a 100644 --- a/tests/test_instalabel.py +++ b/tests/test_instalabel.py @@ -1,5 +1,5 @@ import shippo -from shippo.models.components import Carriers, DistanceUnitTemplate, WeightUnit, \ +from shippo.models.components import Carriers, DistanceUnit, WeightUnit, \ AddressCreateRequest, ShipmentCreateRequest, InstantTransactionRequestBody, \ ParcelCreateRequest from tests.helpers_custom import get_carrier_account @@ -41,7 +41,7 @@ def test_instalabel(self, api: shippo.Shippo): length="5", width="5", height="5", - distance_unit=DistanceUnitTemplate.CM, + distance_unit=DistanceUnit.CM, weight="2", mass_unit=WeightUnit.LB ) diff --git a/tests/test_purchase_label.py b/tests/test_purchase_label.py index 07d10dc..3afd04e 100644 --- a/tests/test_purchase_label.py +++ b/tests/test_purchase_label.py @@ -1,5 +1,5 @@ import shippo -from shippo.models.components import Carriers, ParcelRequest, DistanceUnitTemplate, WeightUnit, \ +from shippo.models.components import Carriers, ParcelRequest, DistanceUnit, WeightUnit, \ AddressCreateRequest, ShipmentCreateRequest, TransactionCreateRequest, ParcelCreateRequest from tests.helpers_custom import get_carrier_accounts @@ -38,7 +38,7 @@ def test_purchase_label(self, api: shippo.Shippo): length="5", width="5", height="5", - distance_unit=DistanceUnitTemplate.CM, + distance_unit=DistanceUnit.CM, weight="2", mass_unit=WeightUnit.LB ) @@ -82,7 +82,7 @@ def test_purchase_label_using_reference_ids(self, api: shippo.Shippo): length="5", width="5", height="5", - distance_unit=DistanceUnitTemplate.CM, + distance_unit=DistanceUnit.CM, weight="2", mass_unit=WeightUnit.LB, metadata="Wool Box1", diff --git a/tests/test_purchase_label_international.py b/tests/test_purchase_label_international.py index 9ba803c..192c1ea 100644 --- a/tests/test_purchase_label_international.py +++ b/tests/test_purchase_label_international.py @@ -3,7 +3,7 @@ import shippo from shippo.models.components import AddressCreateRequest, CustomsDeclarationCreateRequest, \ CustomsDeclarationCreateRequestIncoterm, CustomsItemBase, WeightUnit, CustomsDeclarationCreateRequestContentsType, \ - CustomsDeclarationCreateRequestNonDeliveryOption, ShipmentCreateRequest, ParcelCreateRequest, DistanceUnitTemplate, \ + CustomsDeclarationCreateRequestNonDeliveryOption, ShipmentCreateRequest, ParcelCreateRequest, DistanceUnit, \ ShipmentExtra, Insurance @@ -67,7 +67,7 @@ def test_purchase_label_international(self, api: shippo.Shippo): length="10", width="5", height="4", - distance_unit=DistanceUnitTemplate.IN, + distance_unit=DistanceUnit.IN, mass_unit=WeightUnit.LB ) ], diff --git a/tests/test_rates_at_checkout.py b/tests/test_rates_at_checkout.py index 3ecedde..87ecf06 100644 --- a/tests/test_rates_at_checkout.py +++ b/tests/test_rates_at_checkout.py @@ -3,7 +3,7 @@ import shippo from shippo.models.components import ServiceGroupCreateRequest, Carriers, \ ServiceGroupAccountAndServiceLevel, ServiceGroupType, LiveRateCreateRequest, AddressCompleteCreateRequest, \ - LineItem, WeightUnit, Parcel, DistanceUnitTemplate, ServiceLevelUPS + LineItem, WeightUnit, Parcel, DistanceUnit, ServiceLevelUPS from tests.helpers_custom import get_carrier_account @@ -78,7 +78,7 @@ def test_rates_at_checkout(self, api: shippo.Shippo): length="10", width="15", height="10", - distance_unit=DistanceUnitTemplate.IN, + distance_unit=DistanceUnit.IN, weight="1", mass_unit=WeightUnit.LB )