Skip to content

Commit

Permalink
make search request able to expand objects
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninnoel committed Dec 12, 2023
1 parent 23bac40 commit a10a6a6
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 18 deletions.
13 changes: 10 additions & 3 deletions Sources/StripeKit/Billing/Invoices/InvoiceRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public protocol InvoiceRoutes: StripeAPIRoute {
/// - limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
/// - page: A cursor for pagination across multiple pages of results. Don’t include this parameter on the first call. Use the `next_page` value returned in a previous response to request subsequent results.
/// - Returns: A dictionary with a `data` property that contains an array of up to `limit` invoices. If no objects match the query, the resulting array will be empty. See the related guide on expanding properties in lists.
func search(query: String, limit: Int?, page: String?) async throws -> InvoiceSearchResult
func search(query: String, expand:[String]?, limit: Int?, page: String?) async throws -> InvoiceSearchResult
}

public struct StripeInvoiceRoutes: InvoiceRoutes {
Expand Down Expand Up @@ -645,8 +645,15 @@ public struct StripeInvoiceRoutes: InvoiceRoutes {
return try await apiHandler.send(method: .GET, path: invoices, query: queryParams, headers: headers)
}

public func search(query: String, limit: Int? = nil, page: String? = nil) async throws -> InvoiceSearchResult {
public func search(query: String, expand:[String]? = nil, limit: Int? = nil, page: String? = nil) async throws -> InvoiceSearchResult {
var queryParams: [String: Any] = ["query": query]

var body: [String: Any] = [:]

if let expand {
body["expand"] = expand
}

if let limit {
queryParams["limit"] = limit
}
Expand All @@ -655,6 +662,6 @@ public struct StripeInvoiceRoutes: InvoiceRoutes {
queryParams["page"] = page
}

return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, headers: headers)
return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, body: .string(body.queryParameters), headers: headers)
}
}
16 changes: 13 additions & 3 deletions Sources/StripeKit/Billing/Subscriptions/SubscriptionRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public protocol SubscriptionRoutes: StripeAPIRoute {
/// - limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
/// - page: A cursor for pagination across multiple pages of results. Don’t include this parameter on the first call. Use the `next_page` value returned in a previous response to request subsequent results.
/// - Returns: A dictionary with a `data` property that contains an array of up to `limit` subscriptions. If no objects match the query, the resulting array will be empty. See the related guide on expanding properties in lists.
func search(query: String, limit: Int?, page: String?) async throws -> SubscriptionSearchResult
func search(query: String, expand:[String]?, limit: Int?, page: String?) async throws -> SubscriptionSearchResult
}

public struct StripeSubscriptionRoutes: SubscriptionRoutes {
Expand Down Expand Up @@ -613,8 +613,18 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes {
return try await apiHandler.send(method: .GET, path: subscriptions, query: queryParams, headers: headers)
}

public func search(query: String, limit: Int? = nil, page: String? = nil) async throws -> SubscriptionSearchResult {
public func search(query: String,
expand:[String]? = nil,
limit: Int? = nil,
page: String? = nil) async throws -> SubscriptionSearchResult {
var queryParams: [String: Any] = ["query": query]

var body: [String: Any] = [:]

if let expand {
body["expand"] = expand
}

if let limit {
queryParams["limit"] = limit
}
Expand All @@ -623,6 +633,6 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes {
queryParams["page"] = page
}

return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, headers: headers)
return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, body: .string(body.queryParameters), headers: headers)
}
}
12 changes: 10 additions & 2 deletions Sources/StripeKit/Core Resources/Charges/ChargeRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public protocol ChargeRoutes: StripeAPIRoute {
/// - limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
/// - page: A cursor for pagination across multiple pages of results. Don’t include this parameter on the first call. Use the `next_page` value returned in a previous response to request subsequent results.
/// - Returns: A dictionary with a data property that contains an array of up to limit charges. If no objects match the query, the resulting array will be empty. See the related guide on expanding properties in lists.
func search(query: String, limit: Int?, page: String?) async throws -> ChargeSearchResult
func search(query: String, expand:[String]?, limit: Int?, page: String?) async throws -> ChargeSearchResult
}

public struct StripeChargeRoutes: ChargeRoutes {
Expand Down Expand Up @@ -327,9 +327,17 @@ public struct StripeChargeRoutes: ChargeRoutes {
}

public func search(query: String,
expand:[String]? = nil,
limit: Int? = nil,
page: String? = nil) async throws -> ChargeSearchResult {
var queryParams: [String: Any] = ["query": query]

var body: [String: Any] = [:]

if let expand {
body["expand"] = expand
}

if let limit {
queryParams["limit"] = limit
}
Expand All @@ -338,6 +346,6 @@ public struct StripeChargeRoutes: ChargeRoutes {
queryParams["page"] = page
}

return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, headers: headers)
return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, body: .string(body.queryParameters), headers: headers)
}
}
15 changes: 11 additions & 4 deletions Sources/StripeKit/Core Resources/Customers/CustomerRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public protocol CustomerRoutes: StripeAPIRoute {
/// - page: A cursor for pagination across multiple pages of results. Don’t include this parameter on the first call. Use the `next_page` value returned in a previous response to request subsequent results.
/// - expand: Specifies which fields in the response should be expanded.
/// - Returns: A dictionary with a data property that contains an array of up to limit customers. If no objects match the query, the resulting array will be empty. See the related guide on expanding properties in lists.
func search(query: String, limit: Int?, page: String?, expand: [String]?) async throws -> CustomerSearchResult
func search(query: String, expand:[String]?, limit: Int?, page: String?) async throws -> CustomerSearchResult
}

public struct StripeCustomerRoutes: CustomerRoutes {
Expand Down Expand Up @@ -401,10 +401,17 @@ public struct StripeCustomerRoutes: CustomerRoutes {
}

public func search(query: String,
expand: [String]? = nil,
limit: Int? = nil,
page: String? = nil,
expand: [String]? = nil) async throws -> CustomerSearchResult {
page: String? = nil) async throws -> CustomerSearchResult {
var queryParams: [String: Any] = ["query": query]

var body: [String: Any] = [:]

if let expand {
body["expand"] = expand
}

if let limit {
queryParams["limit"] = limit
}
Expand All @@ -413,6 +420,6 @@ public struct StripeCustomerRoutes: CustomerRoutes {
queryParams["page"] = page
}

return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, headers: headers)
return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, body: .string(body.queryParameters), headers: headers)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public protocol PaymentIntentRoutes: StripeAPIRoute {
/// - limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
/// - page: A cursor for pagination across multiple pages of results. Don’t include this parameter on the first call. Use the `next_page` value returned in a previous response to request subsequent results.
/// - Returns: A dictionary with a data property that contains an array of up to limit PaymentIntents. If no objects match the query, the resulting array will be empty. See the related guide on expanding properties in lists.
func search(query: String, limit: Int?, page: String?) async throws -> PaymentIntentSearchResult
func search(query: String, expand:[String]?, limit: Int?, page: String?) async throws -> PaymentIntentSearchResult

/// Verifies microdeposits on a PaymentIntent object.
/// - Parameters:
Expand Down Expand Up @@ -706,9 +706,17 @@ public struct StripePaymentIntentRoutes: PaymentIntentRoutes {
}

public func search(query: String,
expand:[String]? = nil,
limit: Int? = nil,
page: String? = nil) async throws -> PaymentIntentSearchResult {
var queryParams: [String: Any] = ["query": query]

var body: [String: Any] = [:]

if let expand {
body["expand"] = expand
}

if let limit {
queryParams["limit"] = limit
}
Expand All @@ -717,7 +725,7 @@ public struct StripePaymentIntentRoutes: PaymentIntentRoutes {
queryParams["page"] = page
}

return try await apiHandler.send(method: .GET, path: "\(paymentintents)/search", query: queryParams.queryParameters, headers: headers)
return try await apiHandler.send(method: .GET, path: "\(paymentintents)/search", query: queryParams.queryParameters, body: .string(body.queryParameters), headers: headers)
}

public func verifyMicroDeposits(intent: String,
Expand Down
12 changes: 10 additions & 2 deletions Sources/StripeKit/Products/Prices/PriceRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public protocol PriceRoutes: StripeAPIRoute {
/// - limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
/// - page: A cursor for pagination across multiple pages of results. Don’t include this parameter on the first call. Use the `next_page` value returned in a previous response to request subsequent results.
/// - Returns: A dictionary with a `data` property that contains an array of up to `limit` prices. If no objects match the query, the resulting array will be empty. See the related guide on expanding properties in lists.
func search(query: String, limit: Int?, page: String?) async throws -> PriceSearchResult
func search(query: String, expand:[String]?, limit: Int?, page: String?) async throws -> PriceSearchResult
}

public struct StripePriceRoutes: PriceRoutes {
Expand Down Expand Up @@ -266,9 +266,17 @@ public struct StripePriceRoutes: PriceRoutes {
}

public func search(query: String,
expand:[String]? = nil,
limit: Int? = nil,
page: String? = nil) async throws -> PriceSearchResult {
var queryParams: [String: Any] = ["query": query]

var body: [String: Any] = [:]

if let expand {
body["expand"] = expand
}

if let limit {
queryParams["limit"] = limit
}
Expand All @@ -277,6 +285,6 @@ public struct StripePriceRoutes: PriceRoutes {
queryParams["page"] = page
}

return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, headers: headers)
return try await apiHandler.send(method: .GET, path: search, query: queryParams.queryParameters, body: .string(body.queryParameters), headers: headers)
}
}
12 changes: 10 additions & 2 deletions Sources/StripeKit/Products/Products/ProductRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public protocol ProductRoutes: StripeAPIRoute {
/// - limit: A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
/// - page: A cursor for pagination across multiple pages of results. Don’t include this parameter on the first call. Use the `next_page` value returned in a previous response to request subsequent results.
/// - Returns: A dictionary with a `data` property that contains an array of up to `limit` products. If no objects match the query, the resulting array will be empty. See the related guide on expanding properties in lists.
func search(query: String, limit: Int?, page: String?) async throws -> ProductSearchResult
func search(query: String, expand:[String]?, limit: Int?, page: String?) async throws -> ProductSearchResult
}

public struct StripeProductRoutes: ProductRoutes {
Expand Down Expand Up @@ -262,10 +262,18 @@ public struct StripeProductRoutes: ProductRoutes {
try await apiHandler.send(method: .DELETE, path: "\(products)/\(id)", headers: headers)
}

public func search(query: String,
public func search(query: String,
expand:[String]? = nil,
limit: Int? = nil,
page: String? = nil) async throws -> ProductSearchResult {
var queryParams: [String: Any] = ["query": query]

var body: [String: Any] = [:]

if let expand {
body["expand"] = expand
}

if let limit {
queryParams["limit"] = limit
}
Expand Down

0 comments on commit a10a6a6

Please sign in to comment.