RetrieveCategoryStatistics
public class RetrieveCategoryStatistics : RetrieveGlobalStatistics
The Statistic.Category
class is used to make the
Get Category Stats
API call. At minimum you need to specify a start date.
do {
let now = Date()
let lastMonth = now.addingTimeInterval(-2592000) // 30 days
let request = RetrieveCategoryStatistics(
startDate: lastMonth,
endDate: now,
aggregatedBy: .week,
categories: "Foo", "Bar"
)
try Session.shared.send(modeledRequest: request) { result in
switch result {
case .success(_, let model):
// The `model` variable will be an array of `Statistic` structs.
model.forEach { _ in
// Do something with the stats here...
}
case .failure(let err):
print(err)
}
}
} catch {
print(error)
}
-
Initializes the request with a start date and categories, as well as an end date and/or aggregation method.
Declaration
Swift
public init(startDate: Date, endDate: Date? = nil, aggregatedBy: Statistic.Aggregation? = nil, categories: [String])
Parameters
startDate
The starting date of the statistics to retrieve.
endDate
The end date of the statistics to retrieve.
aggregatedBy
Indicates how the statistics should be grouped.
categories
An array of categories to retrieve stats for.
-
Initializes the request with a start date and categories, as well as an end date and/or aggregation method.
Declaration
Swift
public convenience init(startDate: Date, endDate: Date? = nil, aggregatedBy: Statistic.Aggregation? = nil, categories: String...)
Parameters
startDate
The starting date of the statistics to retrieve.
endDate
The end date of the statistics to retrieve.
aggregatedBy
Indicates how the statistics should be grouped.
categories
An array of categories to retrieve stats for.
-
Validates that there are no more than 10 categories specified.
Declaration
Swift
public override func validate() throws