Skip to content

Commit

Permalink
add expand field in search method of 7 classes
Browse files Browse the repository at this point in the history
  • Loading branch information
antoninnoel committed Dec 19, 2023
1 parent 23bac40 commit 1415e80
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 6 deletions.
25 changes: 24 additions & 1 deletion Sources/StripeKit/Billing/Invoices/InvoiceRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ public protocol InvoiceRoutes: 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.
/// - 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

/// Search for invoices you’ve previously created using Stripe’s Search Query Language. Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.
/// - Parameters:
/// - query: The search query string. See search query language and the list of supported query fields for invoices.
/// - 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.
/// - 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` 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?, expand:[String]?) async throws -> InvoiceSearchResult
}

public struct StripeInvoiceRoutes: InvoiceRoutes {
Expand Down Expand Up @@ -646,7 +655,21 @@ public struct StripeInvoiceRoutes: InvoiceRoutes {
}

public func search(query: String, limit: Int? = nil, page: String? = nil) async throws -> InvoiceSearchResult {
return try await search(query: query, limit: limit, page: page, expand: nil)
}

public func search(query: String,
limit: Int? = nil,
page: String? = nil,
expand:[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 +678,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)
}
}
26 changes: 25 additions & 1 deletion Sources/StripeKit/Billing/Subscriptions/SubscriptionRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ public protocol SubscriptionRoutes: 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.
/// - 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

/// Search for subscriptions you’ve previously created using Stripe’s Search Query Language. Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.
/// - Parameters:
/// - query: The search query string. See search query language and the list of supported query fields for invoices.
/// - 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.
/// - 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` 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?, expand:[String]?) async throws -> SubscriptionSearchResult

}

public struct StripeSubscriptionRoutes: SubscriptionRoutes {
Expand Down Expand Up @@ -614,7 +624,21 @@ public struct StripeSubscriptionRoutes: SubscriptionRoutes {
}

public func search(query: String, limit: Int? = nil, page: String? = nil) async throws -> SubscriptionSearchResult {
return try await self.search(query: query, limit:limit, page:page, expand:nil)
}

public func search(query: String,
limit: Int? = nil,
page: String? = nil,
expand:[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 +647,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)
}
}
25 changes: 24 additions & 1 deletion Sources/StripeKit/Core Resources/Charges/ChargeRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public protocol ChargeRoutes: 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.
/// - 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

/// Search for charges you’ve previously created using Stripe’s Search Query Language. Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.
/// - Parameters:
/// - query: The search query string. See search query language and the list of supported query fields for charges.
/// - 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.
/// - 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 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?, expand:[String]?) async throws -> ChargeSearchResult
}

public struct StripeChargeRoutes: ChargeRoutes {
Expand Down Expand Up @@ -329,7 +338,21 @@ public struct StripeChargeRoutes: ChargeRoutes {
public func search(query: String,
limit: Int? = nil,
page: String? = nil) async throws -> ChargeSearchResult {
return try await self.search(query: query, limit:limit, page:page, expand:nil)
}

public func search(query: String,
limit: Int? = nil,
page: String? = nil,
expand:[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 +361,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)
}
}
10 changes: 9 additions & 1 deletion Sources/StripeKit/Core Resources/Customers/CustomerRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public protocol CustomerRoutes: StripeAPIRoute {
/// - 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

}

public struct StripeCustomerRoutes: CustomerRoutes {
Expand Down Expand Up @@ -412,7 +413,14 @@ public struct StripeCustomerRoutes: CustomerRoutes {
if let page {
queryParams["page"] = page
}
var body: [String: Any] = [:]

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

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 @@ -240,9 +240,19 @@ public protocol PaymentIntentRoutes: StripeAPIRoute {
/// - query: The search query string. See search query language and the list of supported query fields for payment intents.
/// - 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.
/// - 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 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

/// Search for PaymentIntents you’ve previously created using Stripe’s Search Query Language. Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.
/// - Parameters:
/// - query: The search query string. See search query language and the list of supported query fields for payment intents.
/// - 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?, expand:[String]?) async throws -> PaymentIntentSearchResult


/// Verifies microdeposits on a PaymentIntent object.
/// - Parameters:
/// - intent: The id of the intent.
Expand Down Expand Up @@ -708,7 +718,21 @@ public struct StripePaymentIntentRoutes: PaymentIntentRoutes {
public func search(query: String,
limit: Int? = nil,
page: String? = nil) async throws -> PaymentIntentSearchResult {
return try await self.search(query: query, limit:limit, page:page, expand:nil)
}

public func search(query: String,
limit: Int? = nil,
page: String? = nil,
expand:[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 +741,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
26 changes: 25 additions & 1 deletion Sources/StripeKit/Products/Prices/PriceRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public protocol PriceRoutes: 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.
/// - 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


/// Search for prices you’ve previously created using Stripe’s Search Query Language. Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.
/// - Parameters:
/// - query: The search query string. See search query language and the list of supported query fields for prices.
/// - 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.
/// - 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` 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?, expand:[String]?) async throws -> PriceSearchResult
}

public struct StripePriceRoutes: PriceRoutes {
Expand Down Expand Up @@ -268,7 +278,21 @@ public struct StripePriceRoutes: PriceRoutes {
public func search(query: String,
limit: Int? = nil,
page: String? = nil) async throws -> PriceSearchResult {
return try await self.search(query: query, limit: limit, page:page, expand:nil)
}

public func search(query: String,
limit: Int? = nil,
page: String? = nil,
expand:[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 +301,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)
}
}
Loading

0 comments on commit 1415e80

Please sign in to comment.