RetrieveGlobalStatistics

public class RetrieveGlobalStatistics : ModeledRequest<[Statistic], RetrieveStatisticsParameters>

The Statistic.Global class is used to make the Get Global 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 = RetrieveGlobalStatistics(
        startDate: lastMonth,
        endDate: now,
        aggregatedBy: .week
    )
    try Session.shared.send(modeledRequest: request) { result in
        switch result {
        case .success(_, let model):
            // The `model` property 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, as well as an end date and/or aggregation method.

    Declaration

    Swift

    public convenience init(startDate: Date, endDate: Date? = nil, aggregatedBy: Statistic.Aggregation? = nil)

    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.

  • Validates that the end date (if present) is not earlier than the start date.

    Declaration

    Swift

    public override func validate() throws