From 33d4d01806a54cf0cfc953a65b6c1e9cb46c5185 Mon Sep 17 00:00:00 2001 From: Jan Klausa Date: Mon, 15 Apr 2019 03:10:34 +0200 Subject: [PATCH 1/6] add support for specifying custom limit of objects to fetch in stats insight --- WordPressKit.podspec | 2 +- .../StatsDotComFollowersInsight.swift | 4 +-- .../Insights/StatsEmailFollowersInsight.swift | 4 +-- .../Insights/StatsLastPostInsight.swift | 2 +- WordPressKit/StatsServiceRemoteV2.swift | 25 +++++++++++-------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/WordPressKit.podspec b/WordPressKit.podspec index 1936c47c..ac39fc3a 100644 --- a/WordPressKit.podspec +++ b/WordPressKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressKit" - s.version = "4.0.0-beta.2" + s.version = "4.0.0-beta.3" s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API." s.description = <<-DESC diff --git a/WordPressKit/Insights/StatsDotComFollowersInsight.swift b/WordPressKit/Insights/StatsDotComFollowersInsight.swift index 223a6729..945d7349 100644 --- a/WordPressKit/Insights/StatsDotComFollowersInsight.swift +++ b/WordPressKit/Insights/StatsDotComFollowersInsight.swift @@ -12,9 +12,9 @@ public struct StatsDotComFollowersInsight { extension StatsDotComFollowersInsight: StatsInsightData { //MARK: - StatsInsightData Conformance - public static var queryProperties: [String: String] { + public static func queryProperties(with maxCount: Int) -> [String: String] { return ["type": "wpcom", - "max": "7"] + "max": String(maxCount)] } public static var pathComponent: String { diff --git a/WordPressKit/Insights/StatsEmailFollowersInsight.swift b/WordPressKit/Insights/StatsEmailFollowersInsight.swift index 18cace3e..0024c53b 100644 --- a/WordPressKit/Insights/StatsEmailFollowersInsight.swift +++ b/WordPressKit/Insights/StatsEmailFollowersInsight.swift @@ -12,9 +12,9 @@ public struct StatsEmailFollowersInsight { extension StatsEmailFollowersInsight: StatsInsightData { //MARK: - StatsInsightData Conformance - public static var queryProperties: [String: String] { + public static func queryProperties(with maxCount: Int) -> [String: String] { return ["type": "email", - "max": "7"] + "max": String(maxCount)] } public static var pathComponent: String { diff --git a/WordPressKit/Insights/StatsLastPostInsight.swift b/WordPressKit/Insights/StatsLastPostInsight.swift index 8ba51548..0c3fc4f2 100644 --- a/WordPressKit/Insights/StatsLastPostInsight.swift +++ b/WordPressKit/Insights/StatsLastPostInsight.swift @@ -27,7 +27,7 @@ public struct StatsLastPostInsight { extension StatsLastPostInsight: StatsInsightData { //MARK: - StatsInsightData Conformance - public static var queryProperties: [String: String] { + public static func queryProperties(with maxCount: Int) -> [String: String] { return ["order_by": "date", "number": "1", "type": "post", diff --git a/WordPressKit/StatsServiceRemoteV2.swift b/WordPressKit/StatsServiceRemoteV2.swift index ff5e1b01..e0e94090 100644 --- a/WordPressKit/StatsServiceRemoteV2.swift +++ b/WordPressKit/StatsServiceRemoteV2.swift @@ -29,8 +29,11 @@ public class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { /// Responsible for fetching Stats data for Insights — latest data about a site, /// in general — not considering a specific slice of time. /// For a possible set of returned types, see objects that conform to `StatsInsightData`. - public func getInsight(completion: @escaping ((InsightType?, Error?) -> Void)) { - let properties = InsightType.queryProperties as [String: AnyObject] + /// - parameters: + /// - limit: Limit of how many objects you want returned for your query. Default is `10`. `0` means no limit. + public func getInsight(limit: Int = 10, + completion: @escaping ((InsightType?, Error?) -> Void)) { + let properties = InsightType.queryProperties(with: limit) as [String: AnyObject] let pathComponent = InsightType.pathComponent let path = self.path(forEndpoint: "sites/\(siteID)/\(pathComponent)/", withVersion: ._1_1) @@ -59,9 +62,9 @@ public class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { /// ending date of `Feb 17 2019`. /// - limit: Limit of how many objects you want returned for your query. Default is `10`. `0` means no limit. public func getData(for period: StatsPeriodUnit, - endingOn: Date, - limit: Int = 10, - completion: @escaping ((TimeStatsType?, Error?) -> Void)) { + endingOn: Date, + limit: Int = 10, + completion: @escaping ((TimeStatsType?, Error?) -> Void)) { let pathComponent = TimeStatsType.pathComponent let path = self.path(forEndpoint: "sites/\(siteID)/\(pathComponent)/", withVersion: ._1_1) @@ -127,12 +130,12 @@ public class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { extension StatsServiceRemoteV2 { // "Last Post" Insights are "fun" in the way that they require multiple requests to actually create them, // so we do this "fun" dance in a separate method. - public func getInsight(completion: @escaping ((StatsLastPostInsight?, Error?) -> Void)) { + public func getInsight(limit: Int = 10, completion: @escaping ((StatsLastPostInsight?, Error?) -> Void)) { getLastPostInsight(completion: completion) } - private func getLastPostInsight(completion: @escaping ((StatsLastPostInsight?, Error?) -> Void)) { - let properties = StatsLastPostInsight.queryProperties as [String: AnyObject] + private func getLastPostInsight(limit: Int = 10, completion: @escaping ((StatsLastPostInsight?, Error?) -> Void)) { + let properties = StatsLastPostInsight.queryProperties(with: limit) as [String: AnyObject] let pathComponent = StatsLastPostInsight.pathComponent let path = self.path(forEndpoint: "sites/\(siteID)/\(pathComponent)", withVersion: ._1_1) @@ -246,7 +249,7 @@ extension StatsServiceRemoteV2 { // This serves both as a way to get the query properties in a "nice" way, // but also as a way to narrow down the generic type in `getInsight(completion:)` method. public protocol StatsInsightData { - static var queryProperties: [String: String] { get } + static func queryProperties(with maxCount: Int) -> [String: String] static var pathComponent: String { get } init?(jsonDictionary: [String: AnyObject]) @@ -320,8 +323,8 @@ extension StatsInsightData { // A big chunk of those use the same endpoint and queryProperties.. Let's simplify the protocol conformance in those cases. - public static var queryProperties: [String: String] { - return [:] + public static func queryProperties(with maxCount: Int) -> [String: String] { + return ["max": String(maxCount)] } public static var pathComponent: String { From 2f91d0e3ff01b1128953058ba8941d7679d4a112 Mon Sep 17 00:00:00 2001 From: Jeremy Massel Date: Mon, 8 Apr 2019 16:42:05 -0600 Subject: [PATCH 2/6] Update WordPressShared --- Podfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index f0daacd3..2105f102 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -27,7 +27,7 @@ PODS: - OHHTTPStubs/Swift (6.1.0): - OHHTTPStubs/Default - UIDeviceIdentifier (1.1.4) - - WordPressShared (1.7.2): + - WordPressShared (1.7.3): - CocoaLumberjack (~> 3.4) - FormatterKit/TimeIntervalFormatter (= 1.8.2) - wpxmlrpc (0.8.4) @@ -63,7 +63,7 @@ SPEC CHECKSUMS: OCMock: 43565190abc78977ad44a61c0d20d7f0784d35ab OHHTTPStubs: 1e21c7d2c084b8153fc53d48400d8919d2d432d0 UIDeviceIdentifier: 8f8a24b257a4d978c8d40ad1e7355b944ffbfa8c - WordPressShared: 63d57a4a07ad9f9a1ee5e8a7162e48fbb5192014 + WordPressShared: 0853172642668b0fbf5c8d56e743896ebf9aae01 wpxmlrpc: 6ba55c773cfa27083ae4a2173e69b19f46da98e2 PODFILE CHECKSUM: 2d40a9a3484ab5030d6ddd135b604a0be90271c8 From 9866fab7ed04494814ebe90088b9abb7e24be480 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Fri, 19 Apr 2019 13:09:47 -0600 Subject: [PATCH 3/6] Fix endpoint used to get Post Stats data. --- WordPressKit/StatsServiceRemoteV2.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressKit/StatsServiceRemoteV2.swift b/WordPressKit/StatsServiceRemoteV2.swift index e0e94090..60f7a604 100644 --- a/WordPressKit/StatsServiceRemoteV2.swift +++ b/WordPressKit/StatsServiceRemoteV2.swift @@ -108,7 +108,7 @@ public class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { } public func getDetails(forPostID postID: Int, completion: @escaping ((StatsPostDetails?, Error?) -> Void)) { - let path = self.path(forEndpoint: "sites/\(siteID)/post/\(postID)/", withVersion: ._1_1) + let path = self.path(forEndpoint: "sites/\(siteID)/stats/post/\(postID)/", withVersion: ._1_1) wordPressComRestApi.GET(path, parameters: [:], success: { (response, _) in guard From f254fd8ee70c6fcbb547cd039929c3fd50861afe Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Fri, 19 Apr 2019 13:28:59 -0600 Subject: [PATCH 4/6] Fixing test for Post Stats data. --- WordPressKitTests/StatsRemoteV2Tests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressKitTests/StatsRemoteV2Tests.swift b/WordPressKitTests/StatsRemoteV2Tests.swift index c5d480b0..302664b1 100644 --- a/WordPressKitTests/StatsRemoteV2Tests.swift +++ b/WordPressKitTests/StatsRemoteV2Tests.swift @@ -34,7 +34,7 @@ class StatsRemoteV2Tests: RemoteTestCase, RESTTestable { var siteVisitsDataEndpoint: String { return "sites/\(siteID)/stats/visits/" } var sitePostsDataEndpoint: String { return "sites/\(siteID)/stats/top-posts/" } var sitePublishedPostsEndpoint: String { return "sites/\(siteID)/posts/" } - var sitePostDetailsEndpoint: String { return "sites/\(siteID)/post/9001" } + var sitePostDetailsEndpoint: String { return "sites/\(siteID)/stats/post/9001" } var remote: StatsServiceRemoteV2! From a2393ee8353b51dd25bce84b9e19dff6d596c977 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 23 Apr 2019 12:56:42 -0600 Subject: [PATCH 5/6] Bumping version. --- WordPressKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressKit.podspec b/WordPressKit.podspec index ac39fc3a..eb278bd9 100644 --- a/WordPressKit.podspec +++ b/WordPressKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressKit" - s.version = "4.0.0-beta.3" + s.version = "4.0.0-beta.4" s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API." s.description = <<-DESC From b0a73b2c8a2897de61e7ae61576abfb8ce85a4d6 Mon Sep 17 00:00:00 2001 From: Stephenie Harris Date: Tue, 23 Apr 2019 13:09:25 -0600 Subject: [PATCH 6/6] Correctly bumping version. --- WordPressKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPressKit.podspec b/WordPressKit.podspec index eb278bd9..9f30c3d9 100644 --- a/WordPressKit.podspec +++ b/WordPressKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressKit" - s.version = "4.0.0-beta.4" + s.version = "4.1.0-beta.1" s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API." s.description = <<-DESC