Skip to content

Commit a7f5f18

Browse files
committed
Add views to SiteVisitStats
1 parent 6b87459 commit a7f5f18

File tree

14 files changed

+83
-19
lines changed

14 files changed

+83
-19
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,8 @@ extension Networking.SiteVisitStatsItem {
16111611
public static func fake() -> Networking.SiteVisitStatsItem {
16121612
.init(
16131613
period: .fake(),
1614-
visitors: .fake()
1614+
visitors: .fake(),
1615+
views: .fake()
16151616
)
16161617
}
16171618
}

Networking/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,14 +1936,17 @@ extension Networking.SiteVisitStats {
19361936
extension Networking.SiteVisitStatsItem {
19371937
public func copy(
19381938
period: CopiableProp<String> = .copy,
1939-
visitors: CopiableProp<Int> = .copy
1939+
visitors: CopiableProp<Int> = .copy,
1940+
views: CopiableProp<Int> = .copy
19401941
) -> Networking.SiteVisitStatsItem {
19411942
let period = period ?? self.period
19421943
let visitors = visitors ?? self.visitors
1944+
let views = views ?? self.views
19431945

19441946
return Networking.SiteVisitStatsItem(
19451947
period: period,
1946-
visitors: visitors
1948+
visitors: visitors,
1949+
views: views
19471950
)
19481951
}
19491952
}

Networking/Networking/Model/Stats/SiteVisitStats.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public struct SiteVisitStats: Decodable, GeneratedCopiable, GeneratedFakeable {
2525
let rawData: [[AnyCodable]] = try container.decode([[AnyCodable]].self, forKey: .data)
2626
let rawDataContainers = rawData.map({ MIContainer(data: $0.map({ $0.value }), fieldNames: fieldNames) })
2727
let items = rawDataContainers.map({ SiteVisitStatsItem(period: $0.fetchStringValue(for: ItemFieldNames.period),
28-
visitors: $0.fetchIntValue(for: ItemFieldNames.visitors)) })
28+
visitors: $0.fetchIntValue(for: ItemFieldNames.visitors),
29+
views: $0.fetchIntValue(for: ItemFieldNames.views)) })
2930

3031
self.init(siteID: siteID, date: date, granularity: granularity, items: items)
3132
}
@@ -79,11 +80,12 @@ extension SiteVisitStats: Equatable {
7980
//
8081
private extension SiteVisitStats {
8182

82-
/// Defines all of the possbile fields for a SiteVisitStatsItem.
83+
/// Defines all of the possible fields for a SiteVisitStatsItem.
8384
///
8485
enum ItemFieldNames: String {
85-
case period = "period"
86-
case visitors = "visitors"
86+
case period
87+
case visitors
88+
case views
8789
}
8890
}
8991

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import Foundation
22
import Codegen
33

4-
/// Represents an single site visit stat for a specific period.
4+
/// Represents a single site visit stat for a specific period.
55
///
66
public struct SiteVisitStatsItem: Equatable, GeneratedCopiable, GeneratedFakeable {
77
public let period: String
88
public let visitors: Int
9+
public let views: Int
910

1011
/// SiteVisitStatsItem struct initializer.
1112
///
12-
public init(period: String, visitors: Int) {
13+
public init(period: String, visitors: Int, views: Int) {
1314
self.period = period
1415
self.visitors = visitors
16+
self.views = views
1517
}
1618
}
1719

@@ -21,6 +23,6 @@ public struct SiteVisitStatsItem: Equatable, GeneratedCopiable, GeneratedFakeabl
2123
extension SiteVisitStatsItem: Comparable {
2224
public static func < (lhs: SiteVisitStatsItem, rhs: SiteVisitStatsItem) -> Bool {
2325
return lhs.period < rhs.period ||
24-
(lhs.period == rhs.period && lhs.visitors < rhs.visitors)
26+
(lhs.period == rhs.period && lhs.visitors < rhs.visitors && lhs.views < rhs.views)
2527
}
2628
}

Networking/Networking/Remote/SiteStatsRemote.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SiteStatsRemote: Remote {
2727
let parameters = [ParameterKeys.unit: unit.rawValue,
2828
ParameterKeys.date: dateFormatter.string(from: latestDateToInclude),
2929
ParameterKeys.quantity: String(quantity),
30-
ParameterKeys.statFields: ParameterValues.visitors]
30+
ParameterKeys.statFields: "\(ParameterValues.visitors),\(ParameterValues.views)"]
3131
let request = DotcomRequest(wordpressApiVersion: .mark1_1, method: .get, path: path, parameters: parameters)
3232
let mapper = SiteVisitStatsMapper(siteID: siteID)
3333
enqueue(request, mapper: mapper, completion: completion)
@@ -52,5 +52,6 @@ private extension SiteStatsRemote {
5252

5353
enum ParameterValues {
5454
static let visitors: String = "visitors"
55+
static let views: String = "views"
5556
}
5657
}

Networking/NetworkingTests/Mapper/SiteVisitStatsMapperTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class SiteVisitStatsMapperTests: XCTestCase {
2424
let sampleItem1 = dayStats.items![0]
2525
XCTAssertEqual(sampleItem1.period, "2018-07-26")
2626
XCTAssertEqual(sampleItem1.visitors, 101)
27+
XCTAssertEqual(sampleItem1.views, 202)
2728

2829
let sampleItem2 = dayStats.items![11]
2930
XCTAssertEqual(sampleItem2.period, "2018-08-06")
3031
XCTAssertEqual(sampleItem2.visitors, 2)
32+
XCTAssertEqual(sampleItem2.views, 4)
3133
}
3234

3335
/// Verifies that all of the week unit SiteVisitStats fields are parsed correctly.
@@ -47,10 +49,12 @@ class SiteVisitStatsMapperTests: XCTestCase {
4749
let sampleItem1 = weekStats.items![0]
4850
XCTAssertEqual(sampleItem1.period, "2018W05W21")
4951
XCTAssertEqual(sampleItem1.visitors, 4)
52+
XCTAssertEqual(sampleItem1.views, 8)
5053

5154
let sampleItem2 = weekStats.items![11]
5255
XCTAssertEqual(sampleItem2.period, "2018W08W06")
5356
XCTAssertEqual(sampleItem2.visitors, 123123123)
57+
XCTAssertEqual(sampleItem2.views, 246246246)
5458
}
5559

5660
/// Verifies that all of the month unit SiteVisitStats fields are parsed correctly.
@@ -70,10 +74,12 @@ class SiteVisitStatsMapperTests: XCTestCase {
7074
let sampleItem1 = monthStats.items![0]
7175
XCTAssertEqual(sampleItem1.period, "2017-09-01")
7276
XCTAssertEqual(sampleItem1.visitors, 224)
77+
XCTAssertEqual(sampleItem1.views, 448)
7378

7479
let sampleItem2 = monthStats.items![10]
7580
XCTAssertEqual(sampleItem2.period, "2018-07-01")
7681
XCTAssertEqual(sampleItem2.visitors, 6)
82+
XCTAssertEqual(sampleItem2.views, 12)
7783
}
7884

7985
/// Verifies that all of the year unit SiteVisitStats fields are parsed correctly.
@@ -93,10 +99,12 @@ class SiteVisitStatsMapperTests: XCTestCase {
9399
let sampleItem1 = yearStats.items![0]
94100
XCTAssertEqual(sampleItem1.period, "2014-01-01")
95101
XCTAssertEqual(sampleItem1.visitors, 1145)
102+
XCTAssertEqual(sampleItem1.views, 2290)
96103

97104
let sampleItem2 = yearStats.items![3]
98105
XCTAssertEqual(sampleItem2.period, "2017-01-01")
99106
XCTAssertEqual(sampleItem2.visitors, 144)
107+
XCTAssertEqual(sampleItem2.views, 288)
100108
}
101109
}
102110

Networking/NetworkingTests/Responses/site-visits-day.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,68 @@
33
"unit": "day",
44
"fields": [
55
"period",
6+
"views",
67
"visitors"
78
],
89
"data": [
910
[
1011
"2018-07-26",
12+
202,
1113
101
1214
],
1315
[
1416
"2018-07-27",
17+
0,
1518
0
1619
],
1720
[
1821
"2018-07-28",
22+
0,
1923
0
2024
],
2125
[
2226
"2018-07-29",
27+
0,
2328
0
2429
],
2530
[
2631
"2018-07-30",
32+
0,
2733
0
2834
],
2935
[
3036
"2018-07-31",
37+
2,
3138
1
3239
],
3340
[
3441
"2018-08-01",
42+
0,
3543
0
3644
],
3745
[
3846
"2018-08-02",
47+
2,
3948
1
4049
],
4150
[
4251
"2018-08-03",
52+
0,
4353
0
4454
],
4555
[
4656
"2018-08-04",
57+
0,
4758
0
4859
],
4960
[
5061
"2018-08-05",
62+
0,
5163
0
5264
],
5365
[
5466
"2018-08-06",
67+
4,
5568
2
5669
]
5770
]

Networking/NetworkingTests/Responses/site-visits-month.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,68 @@
33
"unit": "month",
44
"fields": [
55
"period",
6+
"views",
67
"visitors"
78
],
89
"data": [
910
[
1011
"2017-09-01",
12+
448,
1113
224
1214
],
1315
[
1416
"2017-10-01",
17+
14,
1518
7
1619
],
1720
[
1821
"2017-11-01",
22+
24,
1923
12
2024
],
2125
[
2226
"2017-12-01",
27+
6,
2328
3
2429
],
2530
[
2631
"2018-01-01",
32+
6,
2733
3
2834
],
2935
[
3036
"2018-02-01",
37+
10,
3138
5
3239
],
3340
[
3441
"2018-03-01",
42+
12,
3543
6
3644
],
3745
[
3846
"2018-04-01",
47+
26,
3948
13
4049
],
4150
[
4251
"2018-05-01",
52+
14,
4353
7
4454
],
4555
[
4656
"2018-06-01",
57+
10,
4758
5
4859
],
4960
[
5061
"2018-07-01",
62+
12,
5163
6
5264
],
5365
[
5466
"2018-08-01",
67+
2,
5568
1
5669
]
5770
]

Networking/NetworkingTests/Responses/site-visits-week.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,68 @@
33
"unit": "week",
44
"fields": [
55
"period",
6+
"views",
67
"visitors"
78
],
89
"data": [
910
[
1011
"2018W05W21",
12+
8,
1113
4
1214
],
1315
[
1416
"2018W05W28",
17+
0,
1518
0
1619
],
1720
[
1821
"2018W06W04",
22+
2,
1923
1
2024
],
2125
[
2226
"2018W06W11",
27+
2,
2328
1
2429
],
2530
[
2631
"2018W06W18",
32+
4,
2733
2
2834
],
2935
[
3036
"2018W06W25",
37+
2,
3138
1
3239
],
3340
[
3441
"2018W07W02",
42+
4,
3543
2
3644
],
3745
[
3846
"2018W07W09",
47+
4,
3948
2
4049
],
4150
[
4251
"2018W07W16",
52+
4,
4353
2
4454
],
4555
[
4656
"2018W07W23",
57+
6,
4758
3
4859
],
4960
[
5061
"2018W07W30",
62+
200,
5163
100
5264
],
5365
[
5466
"2018W08W06",
67+
246246246,
5568
123123123
5669
]
5770
]

Networking/NetworkingTests/Responses/site-visits-year.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@
33
"unit": "year",
44
"fields": [
55
"period",
6+
"views",
67
"visitors"
78
],
89
"data": [
910
[
1011
"2014-01-01",
12+
2290,
1113
1145
1214
],
1315
[
1416
"2015-01-01",
17+
3258,
1518
1629
1619
],
1720
[
1821
"2016-01-01",
22+
744,
1923
372
2024
],
2125
[
2226
"2017-01-01",
27+
288,
2328
144
2429
],
2530
[
2631
"2018-01-01",
32+
92,
2733
46
2834
]
2935
]

0 commit comments

Comments
 (0)