Skip to content

Commit 71025bf

Browse files
Merge pull request #1 from alexanderjordanbaker/AddingNotificationHistory
Adding Notification History endpoint
2 parents 3067f21 + 9d37646 commit 71025bf

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

Sources/AppStoreServerLibrary/AppStoreServerAPIClient.swift

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class AppStoreServerAPIClient {
5858

5959
if let b = body {
6060
let jsonEncoder = JSONEncoder()
61+
jsonEncoder.dateEncodingStrategy = .millisecondsSince1970
6162
let encodedBody = try jsonEncoder.encode(b)
6263
urlRequest.httpBody = encodedBody
6364
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
@@ -94,13 +95,15 @@ public class AppStoreServerAPIClient {
9495
private func makeRequestWithResponseBody<T: Encodable, R: Decodable>(path: String, method: String, queryParameters: [String: [String]], body: T?) async -> APIResult<R> {
9596
let response = await makeRequest(path: path, method: method, queryParameters: queryParameters, body: body)
9697
switch response {
97-
case .success(let data):
98-
guard let decodedBody = try? JSONDecoder().decode(R.self, from: data) else {
99-
return APIResult.failure(statusCode: nil, apiError: nil, causedBy: nil)
100-
}
101-
return APIResult.success(response: decodedBody)
102-
case .failure(let statusCode, let apiError, let error):
103-
return APIResult.failure(statusCode: statusCode, apiError: apiError, causedBy: error)
98+
case .success(let data):
99+
let decoder = JSONDecoder();
100+
decoder.dateDecodingStrategy = .millisecondsSince1970
101+
guard let decodedBody = try? decoder.decode(R.self, from: data) else {
102+
return APIResult.failure(statusCode: nil, apiError: nil, causedBy: nil)
103+
}
104+
return APIResult.success(response: decodedBody)
105+
case .failure(let statusCode, let apiError, let error):
106+
return APIResult.failure(statusCode: statusCode, apiError: apiError, causedBy: error)
104107
}
105108
}
106109

@@ -269,6 +272,20 @@ public class AppStoreServerAPIClient {
269272
return await makeRequestWithResponseBody(path: "/inApps/v1/notifications/test", method: "POST", queryParameters: [:], body: body)
270273
}
271274

275+
///Get a list of notifications that the App Store server attempted to send to your server.
276+
///
277+
///- Parameter paginationToken: An optional token you use to get the next set of up to 20 notification history records. All responses that have more records available include a paginationToken. Omit this parameter the first time you call this endpoint.
278+
///- Parameter notificationHistoryRequest: The request body that includes the start and end dates, and optional query constraints.
279+
///- Returns: A response that contains the App Store Server Notifications history for your app.
280+
///[Get Notification History](https://developer.apple.com/documentation/appstoreserverapi/get_notification_history)
281+
public func getNotificationHistory(paginationToken: String?, notificationHistoryRequest: NotificationHistoryRequest) async -> APIResult<NotificationHistoryResponse> {
282+
var queryParams: [String: [String]] = [:]
283+
if let innerPaginationToken = paginationToken {
284+
queryParams["paginationToken"] = [innerPaginationToken]
285+
}
286+
return await makeRequestWithResponseBody(path: "/inApps/v1/notifications/history", method: "POST", queryParameters: queryParams, body: notificationHistoryRequest)
287+
}
288+
272289
///Send consumption information about a consumable in-app purchase to the App Store after your server receives a consumption request notification.
273290
///
274291
///- Parameter transactionId: The transaction identifier for which you’re providing consumption information. You receive this identifier in the CONSUMPTION_REQUEST notification the App Store sends to your server.

0 commit comments

Comments
 (0)