Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 71c7a0f

Browse files
committed
Merge branch 'develop'
2 parents e56cdab + 82749d1 commit 71c7a0f

File tree

5 files changed

+124
-8
lines changed

5 files changed

+124
-8
lines changed

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "4.3.0"
3+
s.version = "4.4.0-beta.1"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@
423423
93F50A441F227CFB00B5BEBA /* UsersServiceRemoteXMLRPCTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F50A431F227CFB00B5BEBA /* UsersServiceRemoteXMLRPCTests.swift */; };
424424
93F50A471F227F3600B5BEBA /* xmlrpc-response-getprofile.xml in Resources */ = {isa = PBXBuildFile; fileRef = 93F50A451F227F3600B5BEBA /* xmlrpc-response-getprofile.xml */; };
425425
93F50A481F227F3600B5BEBA /* xmlrpc-response-valid-but-unexpected-dictionary.xml in Resources */ = {isa = PBXBuildFile; fileRef = 93F50A461F227F3600B5BEBA /* xmlrpc-response-valid-but-unexpected-dictionary.xml */; };
426+
984E34EB22EF7209005C3F92 /* StatsFileDownloadsTimeIntervalData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 984E34EA22EF7209005C3F92 /* StatsFileDownloadsTimeIntervalData.swift */; };
427+
984E34F422EF9465005C3F92 /* stats-file-downloads.json in Resources */ = {isa = PBXBuildFile; fileRef = 984E34F322EF9464005C3F92 /* stats-file-downloads.json */; };
426428
98DC787522BAEBF200267279 /* StatsAllAnnualInsight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98DC787422BAEBF100267279 /* StatsAllAnnualInsight.swift */; };
427429
9A2D0B28225E0119009E585F /* JetpackServiceRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2D0B27225E0119009E585F /* JetpackServiceRemote.swift */; };
428430
9A2D0B2B225E0E22009E585F /* JetpackServiceRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A2D0B2A225E0E22009E585F /* JetpackServiceRemoteTests.swift */; };
@@ -945,6 +947,8 @@
945947
93F50A431F227CFB00B5BEBA /* UsersServiceRemoteXMLRPCTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UsersServiceRemoteXMLRPCTests.swift; sourceTree = "<group>"; };
946948
93F50A451F227F3600B5BEBA /* xmlrpc-response-getprofile.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "xmlrpc-response-getprofile.xml"; sourceTree = "<group>"; };
947949
93F50A461F227F3600B5BEBA /* xmlrpc-response-valid-but-unexpected-dictionary.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "xmlrpc-response-valid-but-unexpected-dictionary.xml"; sourceTree = "<group>"; };
950+
984E34EA22EF7209005C3F92 /* StatsFileDownloadsTimeIntervalData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatsFileDownloadsTimeIntervalData.swift; sourceTree = "<group>"; };
951+
984E34F322EF9464005C3F92 /* stats-file-downloads.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "stats-file-downloads.json"; sourceTree = "<group>"; };
948952
98DC787422BAEBF100267279 /* StatsAllAnnualInsight.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatsAllAnnualInsight.swift; sourceTree = "<group>"; };
949953
9A2D0B27225E0119009E585F /* JetpackServiceRemote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackServiceRemote.swift; sourceTree = "<group>"; };
950954
9A2D0B2A225E0E22009E585F /* JetpackServiceRemoteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JetpackServiceRemoteTests.swift; sourceTree = "<group>"; };
@@ -1078,15 +1082,16 @@
10781082
404057C3221B30140060250C /* Time Interval */ = {
10791083
isa = PBXGroup;
10801084
children = (
1085+
984E34EA22EF7209005C3F92 /* StatsFileDownloadsTimeIntervalData.swift */,
1086+
40819772221E10C900A298E4 /* StatsPublishedPostsTimeIntervalData.swift */,
10811087
404057C4221B30400060250C /* StatsSearchTermTimeIntervalData.swift */,
1088+
40819777221F00E600A298E4 /* StatsSummaryTimeIntervalData.swift */,
10821089
404057C8221B789B0060250C /* StatsTopAuthorsTimeIntervalData.swift */,
1083-
4081976E221DDE9B00A298E4 /* StatsTopPostsTimeIntervalData.swift */,
1084-
404057CD221C38130060250C /* StatsTopVideosTimeIntervalData.swift */,
1085-
404057D1221C56AB0060250C /* StatsTopCountryTimeIntervalData.swift */,
10861090
404057D5221C92660060250C /* StatsTopClicksTimeIntervalData.swift */,
1091+
404057D1221C56AB0060250C /* StatsTopCountryTimeIntervalData.swift */,
1092+
4081976E221DDE9B00A298E4 /* StatsTopPostsTimeIntervalData.swift */,
10871093
404057D9221C9D560060250C /* StatsTopReferrersTimeIntervalData.swift */,
1088-
40819777221F00E600A298E4 /* StatsSummaryTimeIntervalData.swift */,
1089-
40819772221E10C900A298E4 /* StatsPublishedPostsTimeIntervalData.swift */,
1094+
404057CD221C38130060250C /* StatsTopVideosTimeIntervalData.swift */,
10901095
);
10911096
path = "Time Interval";
10921097
sourceTree = "<group>";
@@ -1631,6 +1636,7 @@
16311636
404057CA221B80BC0060250C /* stats-top-authors.json */,
16321637
40F9880D221ACFB400B7B369 /* stats-streak-result.json */,
16331638
404057C6221B36070060250C /* stats-search-term-result.json */,
1639+
984E34F322EF9464005C3F92 /* stats-file-downloads.json */,
16341640
826016F61F9FAF6300533B6C /* activity-log-auth-failure.json */,
16351641
826016F81F9FAF6300533B6C /* activity-log-bad-json-failure.json */,
16361642
826016F51F9FAF6300533B6C /* activity-log-success-1.json */,
@@ -2184,6 +2190,7 @@
21842190
7403A2F91EF06FEB00DED7DC /* me-settings-change-email-success.json in Resources */,
21852191
439A44DC2107CE3C00795ED7 /* site-plans-v3-empty-failure.json in Resources */,
21862192
9AB6D64F218731AB0008F274 /* post-revisions-failure.json in Resources */,
2193+
984E34F422EF9465005C3F92 /* stats-file-downloads.json in Resources */,
21872194
93F50A3C1F226C0100B5BEBA /* WordPressComRestApiFailThrottled.json in Resources */,
21882195
740B23ED1F17FB7E00067A2A /* xmlrpc-bad-username-password-error.xml in Resources */,
21892196
9A881754223C01E400A3AB20 /* jetpack-service-error-activation-install.json in Resources */,
@@ -2486,6 +2493,7 @@
24862493
93188D1F1F2262BF0028ED4D /* RemotePostTag.m in Sources */,
24872494
9368C7BC1EC630270092CE8E /* StatsVisits.m in Sources */,
24882495
74D67F081F15BEB70010C5ED /* RemotePerson.swift in Sources */,
2496+
984E34EB22EF7209005C3F92 /* StatsFileDownloadsTimeIntervalData.swift in Sources */,
24892497
40AB1ADA200FED25009B533D /* PluginDirectoryFeedPage.swift in Sources */,
24902498
436D56352118D85800CEAA33 /* Country.swift in Sources */,
24912499
74A44DCB1F13C533006CD8F4 /* NotificationSettingsServiceRemote.swift in Sources */,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
public struct StatsFileDownloadsTimeIntervalData {
2+
public let period: StatsPeriodUnit
3+
public let periodEndDate: Date
4+
5+
public let totalDownloadsCount: Int
6+
public let otherDownloadsCount: Int
7+
public let fileDownloads: [StatsFileDownload]
8+
9+
public init(period: StatsPeriodUnit,
10+
periodEndDate: Date,
11+
fileDownloads: [StatsFileDownload],
12+
totalDownloadsCount: Int,
13+
otherDownloadsCount: Int) {
14+
self.period = period
15+
self.periodEndDate = periodEndDate
16+
self.fileDownloads = fileDownloads
17+
self.totalDownloadsCount = totalDownloadsCount
18+
self.otherDownloadsCount = otherDownloadsCount
19+
}
20+
}
21+
22+
public struct StatsFileDownload {
23+
public let file: String
24+
public let downloadCount: Int
25+
26+
public init(file: String,
27+
downloadCount: Int) {
28+
self.file = file
29+
self.downloadCount = downloadCount
30+
}
31+
}
32+
33+
extension StatsFileDownloadsTimeIntervalData: StatsTimeIntervalData {
34+
public static var pathComponent: String {
35+
return "stats/file-downloads"
36+
}
37+
38+
public static func queryProperties(with date: Date, period: StatsPeriodUnit, maxCount: Int) -> [String: String] {
39+
// num = number of periods to include in the query. default: 1.
40+
return ["num": String(maxCount)]
41+
}
42+
43+
public init?(date: Date, period: StatsPeriodUnit, jsonDictionary: [String : AnyObject]) {
44+
guard
45+
let unwrappedDays = type(of: self).unwrapDaysDictionary(jsonDictionary: jsonDictionary),
46+
let fileDownloadsDict = unwrappedDays["files"] as? [[String: AnyObject]]
47+
else {
48+
return nil
49+
}
50+
51+
let fileDownloads: [StatsFileDownload] = fileDownloadsDict.compactMap {
52+
// TODO: these keys are a total guess. Verify/update when the endpoint is actually live.
53+
guard let file = $0["file"] as? String, let downloads = $0["downloads"] as? Int else {
54+
return nil
55+
}
56+
57+
return StatsFileDownload(file: file, downloadCount: downloads)
58+
}
59+
60+
self.periodEndDate = date
61+
self.period = period
62+
self.fileDownloads = fileDownloads
63+
self.totalDownloadsCount = unwrappedDays["total_downloads"] as? Int ?? 0
64+
self.otherDownloadsCount = unwrappedDays["other_downloads"] as? Int ?? 0
65+
}
66+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"date": "2019-07-29",
3+
"period": "month",
4+
"days": {
5+
"2019-07-01": {
6+
"files": [],
7+
"other_downloads": 0,
8+
"total_downloads": 0
9+
}
10+
}
11+
}

WordPressKitTests/StatsRemoteV2Tests.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class StatsRemoteV2Tests: RemoteTestCase, RESTTestable {
2020
let getVisitsMonthMockFilename = "stats-visits-month.json"
2121
let getPostsMockFilename = "stats-posts-data.json"
2222
let getPublishedPostsFilename = "stats-published-posts.json"
23+
let getDownloadsDataFilename = "stats-file-downloads.json"
2324
let getPostsDetailsFilename = "stats-post-details.json"
2425

2526
// MARK: - Properties
@@ -34,9 +35,9 @@ class StatsRemoteV2Tests: RemoteTestCase, RESTTestable {
3435
var siteVisitsDataEndpoint: String { return "sites/\(siteID)/stats/visits/" }
3536
var sitePostsDataEndpoint: String { return "sites/\(siteID)/stats/top-posts/" }
3637
var sitePublishedPostsEndpoint: String { return "sites/\(siteID)/posts/" }
38+
var siteDownloadsDataEndpoint: String { return "sites/\(siteID)/stats/file-downloads/" }
3739
var sitePostDetailsEndpoint: String { return "sites/\(siteID)/stats/post/9001" }
3840

39-
4041
var remote: StatsServiceRemoteV2!
4142

4243
// MARK: - Overridden Methods
@@ -364,7 +365,37 @@ class StatsRemoteV2Tests: RemoteTestCase, RESTTestable {
364365

365366
waitForExpectations(timeout: timeout, handler: nil)
366367
}
367-
368+
369+
func testFetchDownloadsData() {
370+
371+
// TODO: update with real data once endpoint is live
372+
373+
let expect = expectation(description: "It should return file download data for a month")
374+
375+
let dateComponents = DateComponents(year: 2019, month: 7, day: 29)
376+
let date = Calendar.autoupdatingCurrent.date(from: dateComponents)!
377+
378+
stubRemoteResponse(siteDownloadsDataEndpoint, filename: getDownloadsDataFilename, contentType: .ApplicationJSON)
379+
380+
remote.getData(for: .month, endingOn: date) { (fileDownloads: StatsFileDownloadsTimeIntervalData?, error: Error?) in
381+
XCTAssertNil(error)
382+
XCTAssertNotNil(fileDownloads)
383+
384+
XCTAssertEqual(fileDownloads?.otherDownloadsCount, 0)
385+
XCTAssertEqual(fileDownloads?.totalDownloadsCount, 0)
386+
387+
XCTAssertEqual(fileDownloads?.fileDownloads.count, 0)
388+
389+
// TODO: enable these (with valid tests) when endpoint is live
390+
// XCTAssertEqual(fileDownloads?.fileDownloads.first!.file, "")
391+
// XCTAssertEqual(fileDownloads?.fileDownloads.first!.downloadCount, 666)
392+
393+
expect.fulfill()
394+
}
395+
396+
waitForExpectations(timeout: timeout, handler: nil)
397+
}
398+
368399
func testVisitsForDay() {
369400
let expect = expectation(description: "It should return visits data for a day")
370401

0 commit comments

Comments
 (0)