Skip to content

Commit 81a0826

Browse files
authored
Merge pull request #8676 from woocommerce/feat/8671-shipping-label-migration
REST API: Migrate shipping label endpoints
2 parents b926866 + c3f49c3 commit 81a0826

26 files changed

+700
-31
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,17 @@
717717
DE50296328C609DE00551736 /* jetpack-user-not-connected.json in Resources */ = {isa = PBXBuildFile; fileRef = DE50296228C609DE00551736 /* jetpack-user-not-connected.json */; };
718718
DE50296528C60A8000551736 /* JetpackUserMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE50296428C60A8000551736 /* JetpackUserMapperTests.swift */; };
719719
DE5CA111288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json in Resources */ = {isa = PBXBuildFile; fileRef = DE5CA110288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json */; };
720+
DE66C5532976508300DAA978 /* CookieNonceAuthenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */; };
720721
DE66C5552976662700DAA978 /* just-in-time-message-list-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */; };
721722
DE66C5572976913C00DAA978 /* wcpay-charge-card-present-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */; };
722723
DE66C559297799D000DAA978 /* add-on-groups-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C558297799CF00DAA978 /* add-on-groups-without-data.json */; };
723-
DE66C5532976508300DAA978 /* CookieNonceAuthenticator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */; };
724+
DE66C55B2977C1A000DAA978 /* order-shipping-labels-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C55A2977C1A000DAA978 /* order-shipping-labels-without-data.json */; };
725+
DE66C55D2977C35A00DAA978 /* shipping-label-packages-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C55C2977C35A00DAA978 /* shipping-label-packages-success-without-data.json */; };
726+
DE66C55F2977C67D00DAA978 /* shipping-label-account-settings-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */; };
727+
DE66C5612977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */; };
728+
DE66C5632977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */; };
729+
DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */; };
730+
DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */ = {isa = PBXBuildFile; fileRef = DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */; };
724731
DE6F308727966FEF004E1C9A /* CouponReportListMapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */; };
725732
DE74F29A27E08F5A0002FE59 /* SiteSettingMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */; };
726733
DE74F29C27E0A1D00002FE59 /* setting-coupon.json in Resources */ = {isa = PBXBuildFile; fileRef = DE74F29B27E0A1D00002FE59 /* setting-coupon.json */; };
@@ -1558,10 +1565,17 @@
15581565
DE50296228C609DE00551736 /* jetpack-user-not-connected.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "jetpack-user-not-connected.json"; sourceTree = "<group>"; };
15591566
DE50296428C60A8000551736 /* JetpackUserMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackUserMapperTests.swift; sourceTree = "<group>"; };
15601567
DE5CA110288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "product-malformed-variations-and-image-alt.json"; sourceTree = "<group>"; };
1568+
DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CookieNonceAuthenticator.swift; sourceTree = "<group>"; };
15611569
DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "just-in-time-message-list-without-data.json"; sourceTree = "<group>"; };
15621570
DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "wcpay-charge-card-present-without-data.json"; sourceTree = "<group>"; };
15631571
DE66C558297799CF00DAA978 /* add-on-groups-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "add-on-groups-without-data.json"; sourceTree = "<group>"; };
1564-
DE66C5522976508300DAA978 /* CookieNonceAuthenticator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CookieNonceAuthenticator.swift; sourceTree = "<group>"; };
1572+
DE66C55A2977C1A000DAA978 /* order-shipping-labels-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "order-shipping-labels-without-data.json"; sourceTree = "<group>"; };
1573+
DE66C55C2977C35A00DAA978 /* shipping-label-packages-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-packages-success-without-data.json"; sourceTree = "<group>"; };
1574+
DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-account-settings-without-data.json"; sourceTree = "<group>"; };
1575+
DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-success-without-data.json"; sourceTree = "<group>"; };
1576+
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-eligibility-failure-without-data.json"; sourceTree = "<group>"; };
1577+
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-purchase-success-without-data.json"; sourceTree = "<group>"; };
1578+
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "shipping-label-status-success-without-data.json"; sourceTree = "<group>"; };
15651579
DE6F308627966FEF004E1C9A /* CouponReportListMapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponReportListMapperTests.swift; sourceTree = "<group>"; };
15661580
DE74F29927E08F5A0002FE59 /* SiteSettingMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiteSettingMapper.swift; sourceTree = "<group>"; };
15671581
DE74F29B27E0A1D00002FE59 /* setting-coupon.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "setting-coupon.json"; sourceTree = "<group>"; };
@@ -2191,6 +2205,13 @@
21912205
B559EBA820A0B5B100836CD4 /* Responses */ = {
21922206
isa = PBXGroup;
21932207
children = (
2208+
DE66C5662977CEB800DAA978 /* shipping-label-status-success-without-data.json */,
2209+
DE66C5642977CC4300DAA978 /* shipping-label-purchase-success-without-data.json */,
2210+
DE66C5622977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json */,
2211+
DE66C5602977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json */,
2212+
DE66C55E2977C67D00DAA978 /* shipping-label-account-settings-without-data.json */,
2213+
DE66C55C2977C35A00DAA978 /* shipping-label-packages-success-without-data.json */,
2214+
DE66C55A2977C1A000DAA978 /* order-shipping-labels-without-data.json */,
21942215
DE66C558297799CF00DAA978 /* add-on-groups-without-data.json */,
21952216
DE66C5542976662700DAA978 /* just-in-time-message-list-without-data.json */,
21962217
DE66C5562976913C00DAA978 /* wcpay-charge-card-present-without-data.json */,
@@ -3047,6 +3068,7 @@
30473068
DEA6B1C9296D0E8B005AA5E9 /* systemStatusWithPluginsOnly-without-data.json in Resources */,
30483069
314EDF2927C02CC100A56B6F /* stripe-account-complete-empty-descriptor.json in Resources */,
30493070
028CB71F2902589E00331C09 /* create-account-error-invalid-email.json in Resources */,
3071+
DE66C55F2977C67D00DAA978 /* shipping-label-account-settings-without-data.json in Resources */,
30503072
E137619929151C7400FD098F /* error-wp-rest-forbidden.json in Resources */,
30513073
31A451CE27863A2E00FE81AA /* stripe-account-wrong-json.json in Resources */,
30523074
26BD9FCD2965EC3C004E0D15 /* product-variations-bulk-create.json in Resources */,
@@ -3066,13 +3088,15 @@
30663088
DEC51A9B274E3206009F3DF4 /* plugin-inactive.json in Resources */,
30673089
CCF48B382628AEAE0034EA83 /* shipping-label-account-settings-no-payment-methods.json in Resources */,
30683090
31A451D327863A2E00FE81AA /* stripe-account-complete.json in Resources */,
3091+
DE66C5632977CBC700DAA978 /* shipping-label-eligibility-failure-without-data.json in Resources */,
30693092
DE42F96F296BC9A700D514C2 /* countries-without-data.json in Resources */,
30703093
EECB7EE8286555180028C888 /* media-update-product-id.json in Resources */,
30713094
D88D5A43230BC668007B6E01 /* reviews-single.json in Resources */,
30723095
DE5CA111288A3E080077BEF9 /* product-malformed-variations-and-image-alt.json in Resources */,
30733096
02DD6492248A3EC00082523E /* product-external.json in Resources */,
30743097
03DCB7522624B3BE00C8953D /* coupons-all.json in Resources */,
30753098
02B41A94296C04BC00FE3311 /* load-site-plans-no-current-plan.json in Resources */,
3099+
DE66C5612977CB5F00DAA978 /* shipping-label-eligibility-success-without-data.json in Resources */,
30763100
028CB716290223CB00331C09 /* create-account-success.json in Resources */,
30773101
036563E129069D3500D84BFD /* just-in-time-message-list.json in Resources */,
30783102
45A4B85C25D2FAB500776FB4 /* shipping-label-address-validation-error.json in Resources */,
@@ -3123,6 +3147,7 @@
31233147
DEF13C5A296571150024A02B /* leaderboards-year-without-data.json in Resources */,
31243148
2683D70E24456DB8002A1589 /* categories-empty.json in Resources */,
31253149
D865CE67278CA225002C8520 /* stripe-payment-intent-succeeded.json in Resources */,
3150+
DE66C5652977CC4300DAA978 /* shipping-label-purchase-success-without-data.json in Resources */,
31263151
DE74F2A027E3137F0002FE59 /* setting-analytics.json in Resources */,
31273152
0272E3F5254AA48F00436277 /* order-with-line-item-attributes.json in Resources */,
31283153
3105471C262E2F8000C5C02B /* wcpay-payment-intent-requires-action.json in Resources */,
@@ -3153,6 +3178,7 @@
31533178
453305ED2459E1AA00264E50 /* site-post.json in Resources */,
31543179
74749B99224135C4005C4CF2 /* product.json in Resources */,
31553180
4515281F257A89B90076B03C /* product-attribute-create.json in Resources */,
3181+
DE66C55B2977C1A000DAA978 /* order-shipping-labels-without-data.json in Resources */,
31563182
CEF88DAF233E9F7E00BED485 /* order-details-partially-refunded.json in Resources */,
31573183
D823D9032237450A00C90817 /* shipment_tracking_new.json in Resources */,
31583184
DE4F2A442975684900B0701C /* site-api-without-data.json in Resources */,
@@ -3199,6 +3225,7 @@
31993225
74A1D264211898F000931DFA /* site-visits-week.json in Resources */,
32003226
B53EF53621813681003E146F /* generic_success.json in Resources */,
32013227
31054718262E2F5E00C5C02B /* wcpay-payment-intent-requires-confirmation.json in Resources */,
3228+
DE66C5672977CEB800DAA978 /* shipping-label-status-success-without-data.json in Resources */,
32023229
D8FBFF2922D52AFB006E3336 /* order-stats-v4-year.json in Resources */,
32033230
D865CE65278CA202002C8520 /* stripe-payment-intent-canceled.json in Resources */,
32043231
DE42F9672967F61D00D514C2 /* refunds-all-without-data.json in Resources */,
@@ -3265,6 +3292,7 @@
32653292
451A97DE260B59870059D135 /* shipping-label-packages-success.json in Resources */,
32663293
2676F4D0290B0EC800C7A15B /* product-id-only.json in Resources */,
32673294
31D27C8F2602B553002EDB1D /* plugins.json in Resources */,
3295+
DE66C55D2977C35A00DAA978 /* shipping-label-packages-success-without-data.json in Resources */,
32683296
261CF1B4255AD6B30090D8D3 /* payment-gateway-list.json in Resources */,
32693297
268B68FB24C87384007EBF1D /* leaderboards-products.json in Resources */,
32703298
0359EA2527AAF7D60048DE2D /* wcpay-charge-card.json in Resources */,

Networking/Networking/Mapper/OrderShippingLabelListMapper.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ struct OrderShippingLabelListMapper: Mapper {
3232
.orderID: orderID
3333
]
3434

35-
let envelope = try decoder.decode(OrderShippingLabelListEnvelope.self, from: response)
36-
let data = OrderShippingLabelListResponse(shippingLabels: envelope.data.shippingLabels, settings: envelope.data.settings)
37-
return data
35+
let data: OrderShippingLabelListData = try {
36+
do {
37+
return try decoder.decode(OrderShippingLabelListEnvelope.self, from: response).data
38+
} catch {
39+
return try decoder.decode(OrderShippingLabelListData.self, from: response)
40+
}
41+
}()
42+
return OrderShippingLabelListResponse(shippingLabels: data.shippingLabels, settings: data.settings)
3843
}
3944
}
4045

Networking/Networking/Mapper/ShippingLabelAccountSettingsMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct ShippingLabelAccountSettingsMapper: Mapper {
1717
.siteID: siteID
1818
]
1919

20-
return try decoder.decode(ShippingLabelAccountSettingsMapperEnvelope.self, from: response).data
20+
do {
21+
return try decoder.decode(ShippingLabelAccountSettingsMapperEnvelope.self, from: response).data
22+
} catch {
23+
return try decoder.decode(ShippingLabelAccountSettings.self, from: response)
24+
}
2125
}
2226
}
2327

Networking/Networking/Mapper/ShippingLabelAddressValidationSuccessMapper.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ struct ShippingLabelAddressValidationSuccessMapper: Mapper {
88
///
99
func map(response: Data) throws -> ShippingLabelAddressValidationSuccess {
1010
let decoder = JSONDecoder()
11-
return try decoder.decode(ShippingLabelAddressValidationResponseEnvelope.self, from: response)
12-
.data
13-
.result
14-
.get()
11+
let data: ShippingLabelAddressValidationResponse = try {
12+
do {
13+
return try decoder.decode(ShippingLabelAddressValidationResponseEnvelope.self, from: response).data
14+
} catch {
15+
return try decoder.decode(ShippingLabelAddressValidationResponse.self, from: response)
16+
}
17+
}()
18+
return try data.result.get()
1519
}
1620
}
1721

Networking/Networking/Mapper/ShippingLabelCarriersAndRatesMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ struct ShippingLabelCarriersAndRatesMapper: Mapper {
88
///
99
func map(response: Data) throws -> [ShippingLabelCarriersAndRates] {
1010
let decoder = JSONDecoder()
11-
return try decoder.decode(ShippingLabelDataEnvelope.self, from: response).data.rates.boxes
11+
do {
12+
return try decoder.decode(ShippingLabelDataEnvelope.self, from: response).data.rates.boxes
13+
} catch {
14+
return try decoder.decode(ShippingLabelRatesEnvelope.self, from: response).rates.boxes
15+
}
1216
}
1317
}
1418

Networking/Networking/Mapper/ShippingLabelCreationEligibilityMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ struct ShippingLabelCreationEligibilityMapper: Mapper {
77
///
88
func map(response: Data) throws -> ShippingLabelCreationEligibilityResponse {
99
let decoder = JSONDecoder()
10-
return try decoder.decode(ShippingLabelCreationEligibilityMapperEnvelope.self, from: response).eligibility
10+
do {
11+
return try decoder.decode(ShippingLabelCreationEligibilityMapperEnvelope.self, from: response).eligibility
12+
} catch {
13+
return try decoder.decode(ShippingLabelCreationEligibilityResponse.self, from: response)
14+
}
1115
}
1216
}
1317

Networking/Networking/Mapper/ShippingLabelPackagesMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ struct ShippingLabelPackagesMapper: Mapper {
88
///
99
func map(response: Data) throws -> ShippingLabelPackagesResponse {
1010
let decoder = JSONDecoder()
11-
return try decoder.decode(ShippingLabelPackagesMapperEnvelope.self, from: response).data
11+
do {
12+
return try decoder.decode(ShippingLabelPackagesMapperEnvelope.self, from: response).data
13+
} catch {
14+
return try decoder.decode(ShippingLabelPackagesResponse.self, from: response)
15+
}
1216
}
1317
}
1418

Networking/Networking/Mapper/ShippingLabelPrintDataMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ struct ShippingLabelPrintDataMapper: Mapper {
88
///
99
func map(response: Data) throws -> ShippingLabelPrintData {
1010
let decoder = JSONDecoder()
11-
return try decoder.decode(ShippingLabelPrintDataEnvelope.self, from: response).printData
11+
do {
12+
return try decoder.decode(ShippingLabelPrintDataEnvelope.self, from: response).printData
13+
} catch {
14+
return try decoder.decode(ShippingLabelPrintData.self, from: response)
15+
}
1216
}
1317
}
1418

Networking/Networking/Mapper/ShippingLabelPurchaseMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ struct ShippingLabelPurchaseMapper: Mapper {
2525
.orderID: orderID
2626
]
2727

28-
return try decoder.decode(ShippingLabelPurchaseResponse.self, from: response).data.labels
28+
do {
29+
return try decoder.decode(ShippingLabelPurchaseResponse.self, from: response).data.labels
30+
} catch {
31+
return try decoder.decode(ShippingLabelPurchaseEnvelope.self, from: response).labels
32+
}
2933
}
3034
}
3135

Networking/Networking/Mapper/ShippingLabelRefundMapper.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ struct ShippingLabelRefundMapper: Mapper {
99
func map(response: Data) throws -> ShippingLabelRefund {
1010
let decoder = JSONDecoder()
1111
decoder.dateDecodingStrategy = .millisecondsSince1970
12-
return try decoder.decode(ShippingLabelRefundResponse.self, from: response).data.refund
12+
do {
13+
return try decoder.decode(ShippingLabelRefundResponse.self, from: response).data.refund
14+
} catch {
15+
return try decoder.decode(ShippingLabelRefundEnvelope.self, from: response).refund
16+
}
1317
}
1418
}
1519

0 commit comments

Comments
 (0)