Skip to content

Commit cf2c1bc

Browse files
committed
Add date range to custom report
1 parent ff59dce commit cf2c1bc

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Sources/Core/Models/Codable/CustomReport.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public struct CustomReport: Codable, Hashable, Sendable, CodingKeysContaining, I
4444
public let startTime: Date?
4545
/// The end time of the report. The format is YYYY-MM-DD, such as 2024-06-30.
4646
public let endTime: Date?
47+
/// The date range of the report.
48+
///
49+
/// A date range is required only when using `WEEKLY` granularity in Impression Share Report.
50+
public let dateRange: CustomReportDateRange?
4751
/// The timestamp for the creation of the report.
4852
public let creationTime: Date?
4953
/// The most recent timestamp of report modifications
@@ -75,6 +79,7 @@ public struct CustomReport: Codable, Hashable, Sendable, CodingKeysContaining, I
7579
state: State? = nil,
7680
startTime: Date? = nil,
7781
endTime: Date? = nil,
82+
dateRange: CustomReportDateRange? = nil,
7883
creationTime: Date? = nil,
7984
modificationTime: Date? = nil,
8085
granularity: CustomReportGranularity? = nil,
@@ -88,6 +93,7 @@ public struct CustomReport: Codable, Hashable, Sendable, CodingKeysContaining, I
8893
self.state = state
8994
self.startTime = startTime
9095
self.endTime = endTime
96+
self.dateRange = dateRange
9197
self.creationTime = creationTime
9298
self.modificationTime = modificationTime
9399
self.granularity = granularity
@@ -103,6 +109,7 @@ public struct CustomReport: Codable, Hashable, Sendable, CodingKeysContaining, I
103109
case state
104110
case startTime
105111
case endTime
112+
case dateRange
106113
case creationTime
107114
case modificationTime
108115
case granularity
@@ -122,6 +129,7 @@ public struct CustomReport: Codable, Hashable, Sendable, CodingKeysContaining, I
122129
state = try container.decodeIfPresent(CustomReport.State.self, forKey: .state)
123130
startTime = try container.decodeIfPresent(String.self, forKey: .startTime).flatMap(formatter.date(from:))
124131
endTime = try container.decodeIfPresent(String.self, forKey: .endTime).flatMap(formatter.date(from:))
132+
dateRange = try container.decodeIfPresent(CustomReportDateRange.self, forKey: .dateRange)
125133
creationTime = try container.decodeIfPresent(Date.self, forKey: .creationTime)
126134
modificationTime = try container.decodeIfPresent(Date.self, forKey: .modificationTime)
127135
granularity = try container.decodeIfPresent(CustomReportGranularity.self, forKey: .granularity)
@@ -137,6 +145,7 @@ public struct CustomReport: Codable, Hashable, Sendable, CodingKeysContaining, I
137145
try container.encodeIfPresent(id, forKey: .id)
138146
try container.encodeIfPresent(name, forKey: .name)
139147
try container.encodeIfPresent(state, forKey: .state)
148+
try container.encodeIfPresent(dateRange, forKey: .dateRange)
140149
try container.encodeIfPresent(creationTime, forKey: .creationTime)
141150
try container.encodeIfPresent(modificationTime, forKey: .modificationTime)
142151
try container.encodeIfPresent(granularity, forKey: .granularity)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// The date range of the report request.
2+
public enum CustomReportDateRange: String, Codable, Hashable, Sendable {
3+
case lastWeek = "LAST_WEEK"
4+
case last2Weeks = "LAST_2_WEEKS"
5+
case last4Weeks = "LAST_4_WEEKS"
6+
}

Sources/Core/Models/Codable/CustomReportRequest.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ import Foundation
22

33
/// The Impression Share report request body.
44
public struct CustomReportRequest: Codable, Hashable, Sendable {
5-
/// The date range of the report request.
6-
public enum DateRange: String, Codable, Hashable, Sendable {
7-
case lastWeek = "LAST_WEEK"
8-
case last2Weeks = "LAST_2_WEEKS"
9-
case last4Weeks = "LAST_4_WEEKS"
10-
}
11-
125
/// A free-text field. The maximum length is 50 characters.
136
public let name: String
147
/// The start time of the report. The format is YYYY-MM-DD, such as 2024-06-01.
@@ -18,7 +11,7 @@ public struct CustomReportRequest: Codable, Hashable, Sendable {
1811
/// The date range of the report request.
1912
///
2013
/// A date range is required only when using `WEEKLY` granularity in Impression Share Report.
21-
public let dateRange: DateRange?
14+
public let dateRange: CustomReportDateRange?
2215
/// The report data organized by day or week.
2316
///
2417
/// Impression Share reports with a `WEEKLY` granularity value can’t have
@@ -35,7 +28,7 @@ public struct CustomReportRequest: Codable, Hashable, Sendable {
3528
name: String,
3629
startTime: Date? = nil,
3730
endTime: Date? = nil,
38-
dateRange: DateRange? = nil,
31+
dateRange: CustomReportDateRange? = nil,
3932
granularity: CustomReportGranularity? = nil,
4033
selector: CustomReportSelector? = nil
4134
) {
@@ -62,7 +55,7 @@ public struct CustomReportRequest: Codable, Hashable, Sendable {
6255
name = try container.decode(String.self, forKey: .name)
6356
startTime = try container.decodeIfPresent(String.self, forKey: .startTime).flatMap(formatter.date(from:))
6457
endTime = try container.decodeIfPresent(String.self, forKey: .endTime).flatMap(formatter.date(from:))
65-
dateRange = try container.decodeIfPresent(CustomReportRequest.DateRange.self, forKey: .dateRange)
58+
dateRange = try container.decodeIfPresent(CustomReportDateRange.self, forKey: .dateRange)
6659
granularity = try container.decodeIfPresent(CustomReportGranularity.self, forKey: .granularity)
6760
selector = try container.decodeIfPresent(CustomReportSelector.self, forKey: .selector)
6861
}

0 commit comments

Comments
 (0)