// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. import Foundation class _StatisticsAPI: StatisticsAPI { private let client: Client init(client: Client) { self.client = client } public func getStatistics(request: Operations.GetStatisticsRequest) async throws -> Response { return try await client.makeRequest( configureRequest: { configuration in try configureGetStatisticsRequest(with: configuration, request: request) }, handleResponse: handleGetStatisticsResponse ) } public func getResourcesStatistics(request: Operations.GetResourcesStatisticsRequest) async throws -> Response { return try await client.makeRequest( configureRequest: { configuration in try configureGetResourcesStatisticsRequest(with: configuration, request: request) }, handleResponse: handleGetResourcesStatisticsResponse ) } public func getBandwidthStatistics(request: Operations.GetBandwidthStatisticsRequest) async throws -> Response { return try await client.makeRequest( configureRequest: { configuration in try configureGetBandwidthStatisticsRequest(with: configuration, request: request) }, handleResponse: handleGetBandwidthStatisticsResponse ) } } // MARK: - Request Configuration private func configureGetStatisticsRequest(with configuration: URLRequestConfiguration, request: Operations.GetStatisticsRequest) throws { configuration.path = "/statistics/media" configuration.method = .get configuration.queryParameterSerializable = request configuration.telemetryHeader = .userAgent } private func configureGetResourcesStatisticsRequest(with configuration: URLRequestConfiguration, request: Operations.GetResourcesStatisticsRequest) throws { configuration.path = "/statistics/resources" configuration.method = .get configuration.queryParameterSerializable = request configuration.telemetryHeader = .userAgent } private func configureGetBandwidthStatisticsRequest(with configuration: URLRequestConfiguration, request: Operations.GetBandwidthStatisticsRequest) throws { configuration.path = "/statistics/bandwidth" configuration.method = .get configuration.queryParameterSerializable = request configuration.telemetryHeader = .userAgent } // MARK: - Response Handlers private func handleGetStatisticsResponse(response: Client.APIResponse) throws -> Operations.GetStatisticsResponse { let httpResponse = response.httpResponse if httpResponse.statusCode == 200 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .object(try JSONDecoder().decode(Operations.GetStatisticsResponseBody.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 400 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .badRequest(try JSONDecoder().decode(Operations.GetStatisticsBadRequest.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 401 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .unauthorized(try JSONDecoder().decode(Operations.GetStatisticsUnauthorized.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } return .empty } private func handleGetResourcesStatisticsResponse(response: Client.APIResponse) throws -> Operations.GetResourcesStatisticsResponse { let httpResponse = response.httpResponse if httpResponse.statusCode == 200 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .object(try JSONDecoder().decode(Operations.GetResourcesStatisticsResponseBody.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 400 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .badRequest(try JSONDecoder().decode(Operations.GetResourcesStatisticsBadRequest.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 401 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .unauthorized(try JSONDecoder().decode(Operations.GetResourcesStatisticsUnauthorized.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } return .empty } private func handleGetBandwidthStatisticsResponse(response: Client.APIResponse) throws -> Operations.GetBandwidthStatisticsResponse { let httpResponse = response.httpResponse if httpResponse.statusCode == 200 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .object(try JSONDecoder().decode(Operations.GetBandwidthStatisticsResponseBody.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 400 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .badRequest(try JSONDecoder().decode(Operations.GetBandwidthStatisticsBadRequest.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 401 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .unauthorized(try JSONDecoder().decode(Operations.GetBandwidthStatisticsUnauthorized.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } return .empty }