Skip to content

Commit bf1cb53

Browse files
committed
Fix merge conflicts
2 parents e79bc97 + 42981e7 commit bf1cb53

File tree

454 files changed

+14814
-2522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

454 files changed

+14814
-2522
lines changed

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
GIT
22
remote: https://github.com/wordpress-mobile/release-toolkit
3-
revision: d00351ee4e04d8a5f3305116dab017b2c389b1cf
4-
tag: 0.9.1
3+
revision: e426345db3afc839ee463ec1ce8432f584880957
4+
tag: 0.9.2
55
specs:
6-
fastlane-plugin-wpmreleasetoolkit (0.9.1)
6+
fastlane-plugin-wpmreleasetoolkit (0.9.2)
77
activesupport (~> 4)
88
chroma (= 0.2.0)
99
diffy (~> 3.3)
@@ -198,7 +198,7 @@ GEM
198198
octokit (4.18.0)
199199
faraday (>= 0.9)
200200
sawyer (~> 0.8.0, >= 0.5.3)
201-
oj (3.10.5)
201+
oj (3.10.6)
202202
optimist (3.0.0)
203203
options (2.3.2)
204204
os (1.0.1)

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 49 additions & 1 deletion
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>classNames</key>
6+
<dict>
7+
<key>String_HTMLTests</key>
8+
<dict>
9+
<key>testStrippingHTMLHasReasonablePerformance()</key>
10+
<dict>
11+
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
12+
<dict>
13+
<key>baselineAverage</key>
14+
<real>0.0592</real>
15+
<key>baselineIntegrationDisplayName</key>
16+
<string>Local Baseline</string>
17+
<key>maxPercentRelativeStandardDeviation</key>
18+
<real>10</real>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</dict>
23+
</dict>
24+
</plist>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>runDestinationsByUUID</key>
6+
<dict>
7+
<key>DBFB8993-CF1F-4D62-8E43-E9560E0ACF03</key>
8+
<dict>
9+
<key>localComputer</key>
10+
<dict>
11+
<key>busSpeedInMHz</key>
12+
<integer>400</integer>
13+
<key>cpuCount</key>
14+
<integer>1</integer>
15+
<key>cpuKind</key>
16+
<string>8-Core Intel Core i9</string>
17+
<key>cpuSpeedInMHz</key>
18+
<integer>2400</integer>
19+
<key>logicalCPUCoresPerPackage</key>
20+
<integer>16</integer>
21+
<key>modelCode</key>
22+
<string>MacBookPro15,3</string>
23+
<key>physicalCPUCoresPerPackage</key>
24+
<integer>8</integer>
25+
<key>platformIdentifier</key>
26+
<string>com.apple.platform.macosx</string>
27+
</dict>
28+
<key>targetArchitecture</key>
29+
<string>x86_64</string>
30+
<key>targetDevice</key>
31+
<dict>
32+
<key>modelCode</key>
33+
<string>iPhone9,1</string>
34+
<key>platformIdentifier</key>
35+
<string>com.apple.platform.iphonesimulator</string>
36+
</dict>
37+
</dict>
38+
</dict>
39+
</dict>
40+
</plist>
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
import class Aztec.HTMLParser
34

45
/// String: HTML Stripping
56
///
@@ -10,19 +11,6 @@ extension String {
1011
/// NOTE: I can be very slow ⏳ — using it in a background thread is strongly recommended.
1112
///
1213
public var strippedHTML: String {
13-
guard let data = data(using: .utf8) else {
14-
return self
15-
}
16-
17-
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
18-
.documentType: NSAttributedString.DocumentType.html,
19-
.characterEncoding: String.Encoding.utf8.rawValue
20-
]
21-
22-
guard let attributedString = try? NSAttributedString(data: data, options: options, documentAttributes: nil) else {
23-
return self
24-
}
25-
26-
return attributedString.string
14+
HTMLParser().parse(self).rawText()
2715
}
2816
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Foundation
2+
3+
/// Mapper: ProductCategory List
4+
///
5+
struct ProductCategoryListMapper: Mapper {
6+
/// Site Identifier associated to the `ProductCategories`s that will be parsed.
7+
///
8+
/// We're injecting this field via `JSONDecoder.userInfo` because SiteID is not returned in any of the ProductCategory Endpoints.
9+
///
10+
let siteID: Int64
11+
12+
/// (Attempts) to convert a dictionary into [ProductCategory].
13+
///
14+
func map(response: Data) throws -> [ProductCategory] {
15+
let decoder = JSONDecoder()
16+
decoder.userInfo = [
17+
.siteID: siteID
18+
]
19+
20+
return try decoder.decode(ProductCategoryListEnvelope.self, from: response).productCategories
21+
}
22+
}
23+
24+
25+
/// ProductCategoryListEnvelope Disposable Entity:
26+
/// `Load All Products Categories` endpoint returns the updated products document in the `data` key.
27+
/// This entity allows us to do parse all the things with JSONDecoder.
28+
///
29+
private struct ProductCategoryListEnvelope: Decodable {
30+
let productCategories: [ProductCategory]
31+
32+
private enum CodingKeys: String, CodingKey {
33+
case productCategories = "data"
34+
}
35+
}

Networking/Networking/Model/Product/Product.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public struct Product: Codable {
8787
return ProductStatus(rawValue: statusKey)
8888
}
8989

90+
public var productCatalogVisibility: ProductCatalogVisibility {
91+
return ProductCatalogVisibility(rawValue: catalogVisibilityKey)
92+
}
93+
9094
public var productStockStatus: ProductStockStatus {
9195
return ProductStockStatus(rawValue: stockStatusKey)
9296
}
@@ -266,17 +270,17 @@ public struct Product: Codable {
266270

267271
let regularPrice = try container.decodeIfPresent(String.self, forKey: .regularPrice)
268272

273+
let onSale = try container.decode(Bool.self, forKey: .onSale)
274+
269275
// Even though a plain install of WooCommerce Core provides string values,
270276
// some plugins alter the field value from String to Int or Decimal.
271277
var salePrice = ""
272278
if let parsedSalePriceString = container.failsafeDecodeIfPresent(stringForKey: .salePrice) {
273-
salePrice = parsedSalePriceString
279+
salePrice = (onSale && parsedSalePriceString.isEmpty) ? "0" : parsedSalePriceString
274280
} else if let parsedSalePriceDecimal = container.failsafeDecodeIfPresent(decimalForKey: .salePrice) {
275281
salePrice = NSDecimalNumber(decimal: parsedSalePriceDecimal).stringValue
276282
}
277283

278-
let onSale = try container.decode(Bool.self, forKey: .onSale)
279-
280284
let purchasable = try container.decode(Bool.self, forKey: .purchasable)
281285
let totalSales = container.failsafeDecodeIfPresent(Int.self, forKey: .totalSales) ?? 0
282286
let virtual = try container.decode(Bool.self, forKey: .virtual)
@@ -450,6 +454,13 @@ public struct Product: Codable {
450454

451455
// Brief description (short description).
452456
try container.encode(briefDescription, forKey: .briefDescription)
457+
458+
// Product Settings
459+
try container.encode(statusKey, forKey: .statusKey)
460+
try container.encode(featured, forKey: .featured)
461+
try container.encode(catalogVisibilityKey, forKey: .catalogVisibilityKey)
462+
try container.encode(slug, forKey: .slug)
463+
try container.encode(purchaseNote, forKey: .purchaseNote)
453464
}
454465
}
455466

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import Foundation
2+
3+
4+
/// Represents a ProductCatalogVisibility Entity.
5+
///
6+
public enum ProductCatalogVisibility: Decodable, Hashable {
7+
case visible
8+
case catalog
9+
case search
10+
case hidden
11+
case custom(String) // in case there are extensions modifying product catalog visibilities
12+
}
13+
14+
15+
/// RawRepresentable Conformance
16+
///
17+
extension ProductCatalogVisibility: RawRepresentable {
18+
19+
/// Designated Initializer.
20+
///
21+
public init(rawValue: String) {
22+
switch rawValue {
23+
case Keys.visible:
24+
self = .visible
25+
case Keys.catalog:
26+
self = .catalog
27+
case Keys.search:
28+
self = .search
29+
case Keys.hidden:
30+
self = .hidden
31+
default:
32+
self = .custom(rawValue)
33+
}
34+
}
35+
36+
/// Returns the current Enum Case's Raw Value
37+
///
38+
public var rawValue: String {
39+
switch self {
40+
case .visible: return Keys.visible
41+
case .catalog: return Keys.catalog
42+
case .search: return Keys.search
43+
case .hidden: return Keys.hidden
44+
case .custom(let payload): return payload
45+
}
46+
}
47+
48+
/// Returns the localized text version of the Enum
49+
///
50+
public var description: String {
51+
switch self {
52+
case .visible:
53+
return NSLocalizedString("Shop and search results", comment: "Display label for the product's catalog visibility")
54+
case .catalog:
55+
return NSLocalizedString("Shop only", comment: "Display label for the product's catalog visibility")
56+
case .search:
57+
return NSLocalizedString("Search results only", comment: "Display label for the product's catalog visibility")
58+
case .hidden:
59+
return NSLocalizedString("Hidden", comment: "Display label for the product's catalog visibility")
60+
case .custom(let payload):
61+
return payload // unable to localize at runtime.
62+
}
63+
}
64+
}
65+
66+
67+
/// Enum containing the 'Known' ProductType Keys
68+
///
69+
private enum Keys {
70+
static let visible = "visible"
71+
static let catalog = "catalog"
72+
static let search = "search"
73+
static let hidden = "hidden"
74+
}

Networking/Networking/Model/Product/ProductCategory.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,41 @@ import Foundation
55
///
66
public struct ProductCategory: Decodable {
77
public let categoryID: Int64
8+
public let siteID: Int64
9+
public let parentID: Int64
810
public let name: String
911
public let slug: String
1012

1113
/// ProductCategory initializer.
1214
///
1315
public init(categoryID: Int64,
16+
siteID: Int64,
17+
parentID: Int64,
1418
name: String,
1519
slug: String) {
1620
self.categoryID = categoryID
21+
self.siteID = siteID
22+
self.parentID = parentID
1723
self.name = name
1824
self.slug = slug
1925
}
2026

2127
/// Public initializer for ProductCategory.
2228
///
2329
public init(from decoder: Decoder) throws {
30+
guard let siteID = decoder.userInfo[.siteID] as? Int64 else {
31+
throw ProductCategoryDecodingError.missingSiteID
32+
}
33+
2434
let container = try decoder.container(keyedBy: CodingKeys.self)
2535

2636
let categoryID = try container.decode(Int64.self, forKey: .categoryID)
37+
// Some product endpoints don't include the parent category ID
38+
let parentID = container.failsafeDecodeIfPresent(Int64.self, forKey: .parentID) ?? 0
2739
let name = try container.decode(String.self, forKey: .name)
2840
let slug = try container.decode(String.self, forKey: .slug)
2941

30-
self.init(categoryID: categoryID, name: name, slug: slug)
42+
self.init(categoryID: categoryID, siteID: siteID, parentID: parentID, name: name, slug: slug)
3143
}
3244
}
3345

@@ -39,6 +51,7 @@ private extension ProductCategory {
3951
case categoryID = "id"
4052
case name = "name"
4153
case slug = "slug"
54+
case parentID = "parent"
4255
}
4356
}
4457

@@ -48,6 +61,8 @@ private extension ProductCategory {
4861
extension ProductCategory: Comparable {
4962
public static func == (lhs: ProductCategory, rhs: ProductCategory) -> Bool {
5063
return lhs.categoryID == rhs.categoryID &&
64+
lhs.siteID == rhs.siteID &&
65+
lhs.parentID == rhs.parentID &&
5166
lhs.name == rhs.name &&
5267
lhs.slug == rhs.slug
5368
}
@@ -58,3 +73,16 @@ extension ProductCategory: Comparable {
5873
(lhs.categoryID == rhs.categoryID && lhs.name == rhs.name && lhs.slug < rhs.slug)
5974
}
6075
}
76+
77+
// MARK: - Constants
78+
//
79+
public extension ProductCategory {
80+
/// Value the API sends on the `parentID` field when a category does not have a parent.
81+
static let noParentID: Int64 = 0
82+
}
83+
84+
// MARK: - Decoding Errors
85+
//
86+
enum ProductCategoryDecodingError: Error {
87+
case missingSiteID
88+
}

Networking/Networking/Model/Product/ProductStatus.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ extension ProductStatus: RawRepresentable {
5050
public var description: String {
5151
switch self {
5252
case .publish:
53-
return NSLocalizedString("Publish", comment: "Display label for the product's published status")
53+
return NSLocalizedString("Published", comment: "Display label for the product's published status")
5454
case .draft:
5555
return NSLocalizedString("Draft", comment: "Display label for the product's draft status")
5656
case .pending:
57-
return NSLocalizedString("Pending", comment: "Display label for the product's pending status")
57+
return NSLocalizedString("Pending review", comment: "Display label for the product's pending status")
5858
case .privateStatus:
5959
return NSLocalizedString("Private", comment: "Display label for the product's private status")
6060
case .custom(let payload):

0 commit comments

Comments
 (0)