Skip to content

Commit

Permalink
Accept dedicated List objects for listAll Endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
winsmith committed Jan 17, 2025
1 parent 2978742 commit da11604
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
17 changes: 17 additions & 0 deletions Sources/StripeKit/Billing/Meters/Meter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,20 @@ public enum MeterDefaultAggregationFormula: String, Codable {
/// Sum each event’s value.
case sum
}

public struct MeterList: Codable {
public var object: String
public var hasMore: Bool?
public var url: String?
public var data: [Meter]?

public init(object: String,
hasMore: Bool? = nil,
url: String? = nil,
data: [Meter]? = nil) {
self.object = object
self.hasMore = hasMore
self.url = url
self.data = data
}
}
17 changes: 17 additions & 0 deletions Sources/StripeKit/Billing/Meters/MeterEventSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@ public enum MeterEventSummaryValueGroupingWindow: String, Codable {
case day
case hour
}

public struct MeterEventSummaryList: Codable {
public var object: String
public var hasMore: Bool?
public var url: String?
public var data: [MeterEventSummary]?

public init(object: String,
hasMore: Bool? = nil,
url: String? = nil,
data: [MeterEventSummary]? = nil) {
self.object = object
self.hasMore = hasMore
self.url = url
self.data = data
}
}
9 changes: 4 additions & 5 deletions Sources/StripeKit/Billing/Meters/MeterRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public protocol MeterRoutes: StripeAPIRoute {
func retrieve(id: String) async throws -> Meter

/// Returns a list of your billing meters.
func listAll() async throws -> [Meter]
func listAll() async throws -> MeterList

/// Deactivates a billing meter.
///
Expand All @@ -68,7 +68,7 @@ public protocol MeterRoutes: StripeAPIRoute {
valueGroupingWindow: MeterEventSummaryValueGroupingWindow?,
endingBefore: String?,
limit: Int?,
startingAfter: String?) async throws -> [MeterEventSummary]
startingAfter: String?) async throws -> MeterEventSummaryList
}

public struct StripeMeterRoutes: MeterRoutes {
Expand Down Expand Up @@ -135,7 +135,7 @@ public struct StripeMeterRoutes: MeterRoutes {
return try await apiHandler.send(method: .GET, path: "\(meters)/\(id)", headers: headers)
}

public func listAll() async throws -> [Meter] {
public func listAll() async throws -> MeterList {
return try await apiHandler.send(
method: .GET,
path: meters,
Expand Down Expand Up @@ -167,9 +167,8 @@ public struct StripeMeterRoutes: MeterRoutes {
valueGroupingWindow: MeterEventSummaryValueGroupingWindow?,
endingBefore: String?,
limit: Int?,
startingAfter: String?) async throws -> [MeterEventSummary]
startingAfter: String?) async throws -> MeterEventSummaryList
{

var queryParams: [String: Any] = [
"customer": customer,
"end_time": Int(endTime.timeIntervalSince1970),
Expand Down

0 comments on commit da11604

Please sign in to comment.