-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into feature/woo-2.0-brand-updates
- Loading branch information
Showing
299 changed files
with
16,427 additions
and
2,655 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
Networking/Networking/Mapper/SystemStatusReportMapper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
|
||
/// Mapper: System Status Report | ||
/// | ||
struct SystemStatusReportMapper: Mapper { | ||
|
||
/// Site Identifier associated to the system status that will be parsed. | ||
/// We're injecting this field via `JSONDecoder.userInfo` because the remote endpoints don't return the SiteID in the system plugin endpoint. | ||
/// | ||
let siteID: Int64 | ||
|
||
/// (Attempts) to convert a dictionary into SystemStatusReport | ||
/// | ||
func map(response: Data) throws -> SystemStatusReport { | ||
let decoder = JSONDecoder() | ||
decoder.userInfo = [ | ||
.siteID: siteID | ||
] | ||
|
||
if hasDataEnvelope(in: response) { | ||
return try decoder.decode(SystemStatusReportEnvelope.self, from: response).systemStatusReport | ||
} else { | ||
return try decoder.decode(SystemStatusReport.self, from: response) | ||
} | ||
} | ||
} | ||
|
||
/// System Status Report endpoint returns the requested account in the `data` key. This entity | ||
/// allows us to parse it with JSONDecoder. | ||
/// | ||
struct SystemStatusReportEnvelope: Decodable { | ||
let systemStatusReport: SystemStatusReport | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case systemStatusReport = "data" | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Networking/Networking/Mapper/WooShippingOriginAddressesMapper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
|
||
struct WooShippingOriginAddressesMapper: Mapper { | ||
/// (Attempts) to convert a dictionary into WooShippingOriginAddress array. | ||
/// | ||
func map(response: Data) throws -> [WooShippingOriginAddress] { | ||
let decoder = JSONDecoder() | ||
if hasDataEnvelope(in: response) { | ||
return try decoder.decode(WooShippingOriginAddressesMapperEnvelope.self, from: response).data | ||
} else { | ||
return try decoder.decode([WooShippingOriginAddress].self, from: response) | ||
} | ||
} | ||
} | ||
|
||
/// WooShippingOriginAddressesMapperEnvelope Disposable Entity: | ||
/// `Woo Shipping Origin Addresses` endpoint returns the shipping label origin addresses in the `data` key. | ||
/// This entity allows us to do parse all the things with JSONDecoder. | ||
/// | ||
private struct WooShippingOriginAddressesMapperEnvelope: Decodable { | ||
let data: [WooShippingOriginAddress] | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case data = "data" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Foundation | ||
|
||
/// Notification settings for a user | ||
/// | ||
public struct NotificationSettings: Equatable, Encodable { | ||
|
||
/// Settings for different blogs connected to the user. | ||
public let blogs: [Blog] | ||
|
||
/// Convenience init to create notification settings for a given device ID. | ||
/// | ||
public init(deviceID: Int64, enabledSites: [Int64], disabledSites: [Int64]) { | ||
let enabledSiteSettings = enabledSites.map { siteID in | ||
Blog(blogID: siteID, devices: [ | ||
Device(deviceID: deviceID, | ||
newComment: true, | ||
storeOrder: true) | ||
]) | ||
} | ||
|
||
let disabledSiteSettings = disabledSites.map { siteID in | ||
Blog(blogID: siteID, devices: [ | ||
Device(deviceID: deviceID, | ||
newComment: false, | ||
storeOrder: false) | ||
]) | ||
} | ||
|
||
self.init(blogs: (enabledSiteSettings + disabledSiteSettings)) | ||
} | ||
|
||
public init(blogs: [Blog]) { | ||
self.blogs = blogs | ||
} | ||
} | ||
|
||
public extension NotificationSettings { | ||
/// Notification settings for a blog | ||
struct Blog: Equatable, Encodable { | ||
/// ID of the blog | ||
public let blogID: Int64 | ||
|
||
/// List of settings for registered devices | ||
public let devices: [Device] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case blogID = "blog_id" | ||
case devices | ||
} | ||
} | ||
|
||
/// Notification settings for a device | ||
struct Device: Equatable, Encodable { | ||
/// Unique ID of the device | ||
public let deviceID: Int64 | ||
|
||
/// Whether a notification should be sent when there is a new comment on the blog | ||
public let newComment: Bool | ||
|
||
/// Whether a notification should be sent when there is a new order on the store. | ||
public let storeOrder: Bool | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case deviceID = "device_id" | ||
case newComment = "new_comment" | ||
case storeOrder = "store_order" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.