Skip to content

Commit 75f3750

Browse files
Merge pull request #137 from woocommerce/issue/90-sync-sites-action
AccountStore: Sync Sites Action
2 parents e87fa79 + a9defec commit 75f3750

File tree

16 files changed

+441
-39
lines changed

16 files changed

+441
-39
lines changed

Networking/Networking/Model/Site.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ public struct Site: Decodable {
77

88
/// WordPress.com Site Identifier.
99
///
10-
let siteID: Int
10+
public let siteID: Int
1111

1212
/// Site's Name.
1313
///
14-
let name: String
14+
public let name: String
1515

1616
/// Site's Description.
1717
///
18-
let description: String
18+
public let description: String
1919

2020
/// Site's URL.
2121
///
22-
let url: String
22+
public let url: String
2323

2424
/// Indicates if this site hosts a WordPress Store.
2525
///
26-
let isWordPressStore: Bool
26+
public let isWordPressStore: Bool
2727

2828

29-
/// Designated Initializer.
29+
/// Decodable Conformance.
3030
///
3131
public init(from decoder: Decoder) throws {
3232
let siteContainer = try decoder.container(keyedBy: SiteKeys.self)
@@ -39,6 +39,16 @@ public struct Site: Decodable {
3939
let optionsContainer = try siteContainer.nestedContainer(keyedBy: OptionKeys.self, forKey: .options)
4040
isWordPressStore = try optionsContainer.decode(Bool.self, forKey: .isWordPressStore)
4141
}
42+
43+
/// Designated Initializer.
44+
///
45+
public init(siteID: Int, name: String, description: String, url: String, isWordPressStore: Bool) {
46+
self.siteID = siteID
47+
self.name = name
48+
self.description = description
49+
self.url = url
50+
self.isWordPressStore = isWordPressStore
51+
}
4252
}
4353

4454

Networking/Networking/Remote/AccountRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class AccountRemote: Remote {
88

99
/// Loads the Account Details associated with the Credential's authToken.
1010
///
11-
public func loadAccountDetails(completion: @escaping (Account?, Error?) -> Void) {
11+
public func loadAccount(completion: @escaping (Account?, Error?) -> Void) {
1212
let path = "me"
1313
let request = DotcomRequest(wordpressApiVersion: .mark1_1, method: .get, path: path)
1414
let mapper = AccountMapper()

Networking/NetworkingTests/Remote/AccountRemoteTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AccountRemoteTests: XCTestCase {
2525

2626
network.simulateResponse(requestUrlSuffix: "me", filename: "me")
2727

28-
remote.loadAccountDetails { (account, error) in
28+
remote.loadAccount { (account, error) in
2929
XCTAssertNil(error)
3030
XCTAssertNotNil(account)
3131

Storage/Storage.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
68BC97FB41770051C287D1A8 /* Pods_StorageTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 47556EE256120BEE49FF5FD3 /* Pods_StorageTests.framework */; };
1111
7028A41485A08AC748206184 /* Pods_Storage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF3D3B298350F68191CD1DAD /* Pods_Storage.framework */; };
12+
B505255420EE6914008090F5 /* StorageType+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505255320EE6914008090F5 /* StorageType+Extensions.swift */; };
1213
B505F6DA20BEEA3200BB1B69 /* Account+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */; };
1314
B505F6DB20BEEA3200BB1B69 /* Account+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */; };
1415
B505F6DE20BEEA4F00BB1B69 /* CoreDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B505F6DD20BEEA4F00BB1B69 /* CoreDataManager.swift */; };
@@ -27,6 +28,8 @@
2728
B59E11DA20A9D00C004121A4 /* WooCommerce.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = B59E11D820A9D00C004121A4 /* WooCommerce.xcdatamodeld */; };
2829
B59E11DE20A9F1FB004121A4 /* CoreDataManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59E11DD20A9F1FB004121A4 /* CoreDataManagerTests.swift */; };
2930
B59E11E020A9F5E6004121A4 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59E11DF20A9F5E6004121A4 /* Constants.swift */; };
31+
B5B914C520EFF03500F2F832 /* Site+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B914C320EFF03500F2F832 /* Site+CoreDataClass.swift */; };
32+
B5B914C620EFF03500F2F832 /* Site+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B914C420EFF03500F2F832 /* Site+CoreDataProperties.swift */; };
3033
B5DC3CAA20D1B2FE0063AC41 /* WooCommerce.xcdatamodeld in Resources */ = {isa = PBXBuildFile; fileRef = B59E11D820A9D00C004121A4 /* WooCommerce.xcdatamodeld */; };
3134
/* End PBXBuildFile section */
3235

@@ -45,6 +48,7 @@
4548
5D12CAE2D0EA6AB66F162FF9 /* Pods-StorageTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StorageTests.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-StorageTests/Pods-StorageTests.debug.xcconfig"; sourceTree = "<group>"; };
4649
7C81935EDD982072BBDCC837 /* Pods-Storage.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Storage.release.xcconfig"; path = "../Pods/Target Support Files/Pods-Storage/Pods-Storage.release.xcconfig"; sourceTree = "<group>"; };
4750
A3821B262583F14863740A37 /* Pods-Storage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Storage.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Storage/Pods-Storage.debug.xcconfig"; sourceTree = "<group>"; };
51+
B505255320EE6914008090F5 /* StorageType+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StorageType+Extensions.swift"; sourceTree = "<group>"; };
4852
B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Account+CoreDataProperties.swift"; sourceTree = "<group>"; };
4953
B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Account+CoreDataClass.swift"; sourceTree = "<group>"; };
5054
B505F6DD20BEEA4F00BB1B69 /* CoreDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoreDataManager.swift; sourceTree = "<group>"; };
@@ -66,6 +70,8 @@
6670
B59E11D920A9D00C004121A4 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
6771
B59E11DD20A9F1FB004121A4 /* CoreDataManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataManagerTests.swift; sourceTree = "<group>"; };
6872
B59E11DF20A9F5E6004121A4 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
73+
B5B914C320EFF03500F2F832 /* Site+CoreDataClass.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Site+CoreDataClass.swift"; sourceTree = "<group>"; };
74+
B5B914C420EFF03500F2F832 /* Site+CoreDataProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Site+CoreDataProperties.swift"; sourceTree = "<group>"; };
6975
BB0EDB0E92A719168B18DAFE /* Pods-StorageTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-StorageTests.release.xcconfig"; path = "../Pods/Target Support Files/Pods-StorageTests/Pods-StorageTests.release.xcconfig"; sourceTree = "<group>"; };
7076
DF3D3B298350F68191CD1DAD /* Pods_Storage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Storage.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7177
/* End PBXFileReference section */
@@ -103,6 +109,14 @@
103109
name = Pods;
104110
sourceTree = "<group>";
105111
};
112+
B505255520EE694F008090F5 /* Tools */ = {
113+
isa = PBXGroup;
114+
children = (
115+
B505255320EE6914008090F5 /* StorageType+Extensions.swift */,
116+
);
117+
path = Tools;
118+
sourceTree = "<group>";
119+
};
106120
B505F6DC20BEEA4F00BB1B69 /* CoreData */ = {
107121
isa = PBXGroup;
108122
children = (
@@ -156,6 +170,7 @@
156170
B52B0F7C20AA2D9900477698 /* Protocols */,
157171
B54CA5BE20A4BD9A00F38CD1 /* Extensions */,
158172
B59E11D720A9CFF3004121A4 /* Model */,
173+
B505255520EE694F008090F5 /* Tools */,
159174
B505F6DC20BEEA4F00BB1B69 /* CoreData */,
160175
B54CA59C20A4BBA500F38CD1 /* Storage.h */,
161176
B54CA59D20A4BBA600F38CD1 /* Info.plist */,
@@ -209,6 +224,8 @@
209224
B59E11D820A9D00C004121A4 /* WooCommerce.xcdatamodeld */,
210225
B505F6D920BEEA3200BB1B69 /* Account+CoreDataClass.swift */,
211226
B505F6D820BEEA3100BB1B69 /* Account+CoreDataProperties.swift */,
227+
B5B914C320EFF03500F2F832 /* Site+CoreDataClass.swift */,
228+
B5B914C420EFF03500F2F832 /* Site+CoreDataProperties.swift */,
212229
);
213230
path = Model;
214231
sourceTree = "<group>";
@@ -392,14 +409,17 @@
392409
isa = PBXSourcesBuildPhase;
393410
buildActionMask = 2147483647;
394411
files = (
412+
B5B914C520EFF03500F2F832 /* Site+CoreDataClass.swift in Sources */,
395413
B54CA5BB20A4BD2800F38CD1 /* NSManagedObject+Object.swift in Sources */,
414+
B5B914C620EFF03500F2F832 /* Site+CoreDataProperties.swift in Sources */,
396415
B505F6DB20BEEA3200BB1B69 /* Account+CoreDataClass.swift in Sources */,
397416
B54CA5BD20A4BD3B00F38CD1 /* NSManagedObjectContext+Storage.swift in Sources */,
398417
B59E11DA20A9D00C004121A4 /* WooCommerce.xcdatamodeld in Sources */,
399418
B52B0F7920AA287C00477698 /* StorageManagerType.swift in Sources */,
400419
B505F6E020BEEA8100BB1B69 /* StorageType.swift in Sources */,
401420
B54CA5C920A4C17800F38CD1 /* NSObject+Storage.swift in Sources */,
402421
B505F6DA20BEEA3200BB1B69 /* Account+CoreDataProperties.swift in Sources */,
422+
B505255420EE6914008090F5 /* StorageType+Extensions.swift in Sources */,
403423
B52B0F7B20AA28A800477698 /* Object.swift in Sources */,
404424
B505F6DE20BEEA4F00BB1B69 /* CoreDataManager.swift in Sources */,
405425
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Foundation
2+
import CoreData
3+
4+
5+
@objc(Site)
6+
public class Site: NSManagedObject {
7+
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
import CoreData
3+
4+
5+
extension Site {
6+
@nonobjc public class func fetchRequest() -> NSFetchRequest<Site> {
7+
return NSFetchRequest<Site>(entityName: "Site")
8+
}
9+
10+
@NSManaged public var siteID: Int64
11+
@NSManaged public var name: String?
12+
@NSManaged public var tagline: String?
13+
@NSManaged public var url: String?
14+
@NSManaged public var isWordPressStore: NSNumber?
15+
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14133" systemVersion="17E202" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
2+
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="14135" systemVersion="17F77" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
33
<entity name="Account" representedClassName="Account" syncable="YES">
44
<attribute name="displayName" optional="YES" attributeType="String" syncable="YES"/>
55
<attribute name="email" optional="YES" attributeType="String" syncable="YES"/>
66
<attribute name="gravatarUrl" optional="YES" attributeType="String" syncable="YES"/>
77
<attribute name="userID" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
88
<attribute name="username" attributeType="String" syncable="YES"/>
99
</entity>
10+
<entity name="Site" representedClassName="Site" syncable="YES">
11+
<attribute name="isWordPressStore" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES" syncable="YES"/>
12+
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
13+
<attribute name="siteID" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES" syncable="YES"/>
14+
<attribute name="tagline" optional="YES" attributeType="String" syncable="YES"/>
15+
<attribute name="url" optional="YES" attributeType="String" syncable="YES"/>
16+
</entity>
1017
<elements>
1118
<element name="Account" positionX="-63" positionY="-18" width="128" height="120"/>
19+
<element name="Site" positionX="-63" positionY="18" width="128" height="120"/>
1220
</elements>
1321
</model>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
3+
4+
// MARK: - StorageType DataModel Specific Extensions
5+
//
6+
public extension StorageType {
7+
8+
/// Retrieves the Stored Account.
9+
///
10+
public func loadAccount(userId: Int) -> Account? {
11+
let predicate = NSPredicate(format: "userID = %ld", userId)
12+
return firstObject(ofType: Account.self, matching: predicate)
13+
}
14+
15+
/// Retrieves the Stored Site.
16+
///
17+
public func loadSite(siteID: Int) -> Site? {
18+
let predicate = NSPredicate(format: "siteID = %ld", siteID)
19+
return firstObject(ofType: Site.self, matching: predicate)
20+
}
21+
}

0 commit comments

Comments
 (0)