@@ -8,7 +8,7 @@ public protocol ProductsRemoteProtocol {
88 func addProduct( product: Product , completion: @escaping ( Result < Product , Error > ) -> Void )
99 func deleteProduct( for siteID: Int64 , productID: Int64 , completion: @escaping ( Result < Product , Error > ) -> Void )
1010 func loadProduct( for siteID: Int64 , productID: Int64 , completion: @escaping ( Result < Product , Error > ) -> Void )
11- func loadProducts( for siteID: Int64 , by productIDs: [ Int64 ] , pageNumber: Int , pageSize: Int , completion : @escaping ( Result < [ Product ] , Error > ) -> Void )
11+ func loadProducts( for siteID: Int64 , by productIDs: [ Int64 ] , pageNumber: Int , pageSize: Int ) async throws -> [ Product ]
1212 func loadAllProducts( for siteID: Int64 ,
1313 context: String ? ,
1414 pageNumber: Int ,
@@ -29,18 +29,15 @@ public protocol ProductsRemoteProtocol {
2929 productStatus: ProductStatus ? ,
3030 productType: ProductType ? ,
3131 productCategory: ProductCategory ? ,
32- excludedProductIDs: [ Int64 ] ,
33- completion: @escaping ( Result < [ Product ] , Error > ) -> Void )
32+ excludedProductIDs: [ Int64 ] ) async throws -> [ Product ]
3433 func searchProductsBySKU( for siteID: Int64 ,
3534 keyword: String ,
3635 pageNumber: Int ,
37- pageSize: Int ,
38- completion: @escaping ( Result < [ Product ] , Error > ) -> Void )
36+ pageSize: Int ) async throws -> [ Product ]
3937 func searchProductsByGlobalUniqueIdentifier( for siteID: Int64 ,
4038 keyword: String ,
4139 pageNumber: Int ,
42- pageSize: Int ,
43- completion: @escaping ( Result < [ Product ] , Error > ) -> Void )
40+ pageSize: Int ) async throws -> [ Product ]
4441 func searchSku( for siteID: Int64 ,
4542 sku: String ,
4643 completion: @escaping ( Result < String , Error > ) -> Void )
@@ -102,12 +99,11 @@ public protocol ProductsRemoteProtocol {
10299}
103100
104101extension ProductsRemoteProtocol {
105- public func loadProducts( for siteID: Int64 , by productIDs: [ Int64 ] , completion: @escaping ( Result < [ Product ] , Error > ) -> Void ) {
106- loadProducts ( for: siteID,
107- by: productIDs,
108- pageNumber: ProductsRemote . Default. pageNumber,
109- pageSize: ProductsRemote . Default. pageSize,
110- completion: completion)
102+ public func loadProducts( for siteID: Int64 , by productIDs: [ Int64 ] ) async throws -> [ Product ] {
103+ try await loadProducts ( for: siteID,
104+ by: productIDs,
105+ pageNumber: ProductsRemote . Default. pageNumber,
106+ pageSize: ProductsRemote . Default. pageSize)
111107 }
112108}
113109
@@ -387,16 +383,13 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
387383 /// - productIDs: The array of product IDs that are requested.
388384 /// - pageNumber: Number of page that should be retrieved.
389385 /// - pageSize: Number of products to be retrieved per page.
390- /// - completion: Closure to be executed upon completion.
391386 ///
392387 public func loadProducts( for siteID: Int64 ,
393388 by productIDs: [ Int64 ] ,
394389 pageNumber: Int = Default . pageNumber,
395- pageSize: Int = Default . pageSize,
396- completion: @escaping ( Result < [ Product ] , Error > ) -> Void ) {
390+ pageSize: Int = Default . pageSize) async throws -> [ Product ] {
397391 guard productIDs. isEmpty == false else {
398- completion ( . success( [ ] ) )
399- return
392+ return [ ]
400393 }
401394
402395 let stringOfProductIDs = productIDs. map { String ( $0) }
@@ -409,9 +402,9 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
409402 ]
410403 let path = Path . products
411404 let request = JetpackRequest ( wooApiVersion: . mark3, method: . get, siteID: siteID, path: path, parameters: parameters, availableAsRESTRequest: true )
412- let mapper = ProductListMapper ( siteID: siteID)
405+ let mapper = ListMapper < Product > ( siteID: siteID)
413406
414- enqueue ( request, mapper: mapper, completion : completion )
407+ return try await enqueue ( request, mapper: mapper)
415408 }
416409
417410
@@ -438,7 +431,6 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
438431 /// - pageNumber: Number of page that should be retrieved.
439432 /// - pageSize: Number of products to be retrieved per page.
440433 /// - excludedProductIDs: a list of product IDs to be excluded from the results.
441- /// - completion: Closure to be executed upon completion.
442434 ///
443435 public func searchProducts( for siteID: Int64 ,
444436 keyword: String ,
@@ -448,8 +440,7 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
448440 productStatus: ProductStatus ? = nil ,
449441 productType: ProductType ? = nil ,
450442 productCategory: ProductCategory ? = nil ,
451- excludedProductIDs: [ Int64 ] = [ ] ,
452- completion: @escaping ( Result < [ Product ] , Error > ) -> Void ) {
443+ excludedProductIDs: [ Int64 ] = [ ] ) async throws -> [ Product ] {
453444 let stringOfExcludedProductIDs = excludedProductIDs. map { String ( $0) }
454445 . joined ( separator: " , " )
455446
@@ -471,9 +462,9 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
471462
472463 let path = Path . products
473464 let request = JetpackRequest ( wooApiVersion: . mark3, method: . get, siteID: siteID, path: path, parameters: parameters, availableAsRESTRequest: true )
474- let mapper = ProductListMapper ( siteID: siteID)
465+ let mapper = ListMapper < Product > ( siteID: siteID)
475466
476- enqueue ( request, mapper: mapper, completion : completion )
467+ return try await enqueue ( request, mapper: mapper)
477468 }
478469
479470 /// Retrieves all of the `Product`s that match the SKU. Partial SKU search is supported for WooCommerce version 6.6+, otherwise full SKU match is performed.
@@ -482,12 +473,10 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
482473 /// - keyword: Search string that should be matched by the SKU (partial or full depending on the WC version).
483474 /// - pageNumber: Number of page that should be retrieved.
484475 /// - pageSize: Number of products to be retrieved per page.
485- /// - completion: Closure to be executed upon completion.
486476 public func searchProductsBySKU( for siteID: Int64 ,
487477 keyword: String ,
488478 pageNumber: Int ,
489- pageSize: Int ,
490- completion: @escaping ( Result < [ Product ] , Error > ) -> Void ) {
479+ pageSize: Int ) async throws -> [ Product ] {
491480 let parameters = [
492481 ParameterKey . sku: keyword,
493482 ParameterKey . partialSKUSearch: keyword,
@@ -497,15 +486,14 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
497486 ]
498487 let path = Path . products
499488 let request = JetpackRequest ( wooApiVersion: . mark3, method: . get, siteID: siteID, path: path, parameters: parameters, availableAsRESTRequest: true )
500- let mapper = ProductListMapper ( siteID: siteID)
501- enqueue ( request, mapper: mapper, completion : completion )
489+ let mapper = ListMapper < Product > ( siteID: siteID)
490+ return try await enqueue ( request, mapper: mapper)
502491 }
503492
504493 public func searchProductsByGlobalUniqueIdentifier( for siteID: Int64 ,
505494 keyword: String ,
506495 pageNumber: Int ,
507- pageSize: Int ,
508- completion: @escaping ( Result < [ Product ] , Error > ) -> Void ) {
496+ pageSize: Int ) async throws -> [ Product ] {
509497 let parameters = [
510498 ParameterKey . globalUniqueID: keyword,
511499 ParameterKey . page: String ( pageNumber) ,
@@ -514,8 +502,8 @@ public final class ProductsRemote: Remote, ProductsRemoteProtocol {
514502 ]
515503 let path = Path . products
516504 let request = JetpackRequest ( wooApiVersion: . mark3, method: . get, siteID: siteID, path: path, parameters: parameters, availableAsRESTRequest: true )
517- let mapper = ProductListMapper ( siteID: siteID)
518- enqueue ( request, mapper: mapper, completion : completion )
505+ let mapper = ListMapper < Product > ( siteID: siteID)
506+ return try await enqueue ( request, mapper: mapper)
519507 }
520508
521509 /// Retrieves a product SKU if available.
0 commit comments