import { findMaxLastSyncedAt } from "./findMaxLastSyncedAt" ; import { getApiUrl } from "./getApiUrl" ; import { getApiKey } from "./getApiKey" ; export function downloadSets ( ) { const apiUrl = getApiUrl ( ) ; const apiKey = getApiKey ( ) ; let done = false ; let startAt = undefined ; const limit = 30 ; const allSets = [ ] ; while ( done === false ) { const response = UrlFetchApp . fetch ( apiUrl + `/download-sets?softLimit=${ limit }&${ typeof startAt !== "undefined" ? "startAt=" + startAt : "" }` , { method : "get" , headers : { Authorization : "Bearer " + apiKey } } ) ; const result = JSON . parse ( response . getContentText ( ) ) ; startAt = findMaxLastSyncedAt ( result . setList ) ; allSets . push ( ... result . setList ) ; done = result . noMore ; } return allSets ; }