@@ -310,6 +310,10 @@ func (a *StoreClient) GetSubscriptionRenewalDataStatus(ctx context.Context, prod
310
310
URL = strings .Replace (URL , "{requestIdentifier}" , requestIdentifier , - 1 )
311
311
312
312
statusCode , body , err := a .Do (ctx , http .MethodGet , URL , nil )
313
+ if err != nil {
314
+ return statusCode , nil , err
315
+ }
316
+
313
317
if statusCode != http .StatusOK {
314
318
return statusCode , nil , fmt .Errorf ("appstore api: %v return status code %v" , URL , statusCode )
315
319
}
@@ -322,54 +326,64 @@ func (a *StoreClient) GetSubscriptionRenewalDataStatus(ctx context.Context, prod
322
326
return statusCode , rsp , nil
323
327
}
324
328
329
+ // GetAllNotificationHistory returns all the NotificationHistoryResponseItem using the paginationToken on behalf of you.
330
+ func (a * StoreClient ) GetAllNotificationHistory (ctx context.Context , body NotificationHistoryRequest , duration time.Duration ) (responses []NotificationHistoryResponseItem , err error ) {
331
+ paginationToken := ""
332
+ for {
333
+ rsp , err := a .GetNotificationHistory (ctx , body , paginationToken )
334
+ if err != nil {
335
+ return nil , err
336
+ }
337
+
338
+ responses = append (responses , rsp .NotificationHistory ... )
339
+
340
+ if rsp .HasMore {
341
+ paginationToken = rsp .PaginationToken
342
+ } else {
343
+ break
344
+ }
345
+
346
+ time .Sleep (duration )
347
+ }
348
+
349
+ return responses , nil
350
+ }
351
+
325
352
// GetNotificationHistory https://developer.apple.com/documentation/appstoreserverapi/get_notification_history
326
353
// Note: Notification history is available starting on June 6, 2022. Use a startDate of June 6, 2022 or later in your request.
327
- func (a * StoreClient ) GetNotificationHistory (ctx context.Context , body NotificationHistoryRequest ) (responses [] NotificationHistoryResponseItem , err error ) {
354
+ func (a * StoreClient ) GetNotificationHistory (ctx context.Context , body NotificationHistoryRequest , paginationToken string ) (rsp * NotificationHistoryResponses , err error ) {
328
355
baseURL := HostProduction + PathGetNotificationHistory
329
356
if a .Token .Sandbox {
330
357
baseURL = HostSandBox + PathGetNotificationHistory
331
358
}
332
359
360
+ URL := baseURL
361
+ if paginationToken != "" {
362
+ query := url.Values {}
363
+ query .Set ("paginationToken" , paginationToken )
364
+ URL += "?" + query .Encode ()
365
+ }
366
+
333
367
bodyBuf := new (bytes.Buffer )
334
368
err = json .NewEncoder (bodyBuf ).Encode (body )
335
369
if err != nil {
336
370
return nil , err
337
371
}
338
372
339
- URL := baseURL
340
- for {
341
- rsp := NotificationHistoryResponses {}
342
- rsp .NotificationHistory = make ([]NotificationHistoryResponseItem , 0 )
343
-
344
- statusCode , rspBody , errOmit := a .Do (ctx , http .MethodPost , URL , bodyBuf )
345
- if errOmit != nil {
346
- return nil , errOmit
347
- }
348
-
349
- if statusCode != http .StatusOK {
350
- return nil , fmt .Errorf ("appstore api: %v return status code %v" , URL , statusCode )
351
- }
352
-
353
- err = json .Unmarshal (rspBody , & rsp )
354
- if err != nil {
355
- return nil , err
356
- }
357
-
358
- responses = append (responses , rsp .NotificationHistory ... )
359
- if ! rsp .HasMore {
360
- break
361
- }
373
+ statusCode , rspBody , err := a .Do (ctx , http .MethodPost , URL , bodyBuf )
374
+ if err != nil {
375
+ return nil , err
376
+ }
362
377
363
- data := url.Values {}
364
- if rsp .HasMore && rsp .PaginationToken != "" {
365
- data .Set ("paginationToken" , rsp .PaginationToken )
366
- URL = baseURL + "?" + data .Encode ()
367
- }
378
+ if statusCode != http .StatusOK {
379
+ return nil , fmt .Errorf ("appstore api: %v return status code %v" , URL , statusCode )
380
+ }
368
381
369
- time .Sleep (10 * time .Millisecond )
382
+ if err = json .Unmarshal (rspBody , & rsp ); err != nil {
383
+ return nil , err
370
384
}
371
385
372
- return responses , nil
386
+ return rsp , nil
373
387
}
374
388
375
389
// SendRequestTestNotification https://developer.apple.com/documentation/appstoreserverapi/request_a_test_notification
0 commit comments