Created
January 29, 2021 11:09
-
-
Save minimike86/b595cb93129028a48901efb7c44c3b1e to your computer and use it in GitHub Desktop.
Nice little undocumented feature in GetFundraisingPageDonations (https://api.justgiving.com/docs/resources/v1/Fundraising/GetFundraisingPageDonations) that you need to use query strings (?pageSize=${pageSize}&pageNumber=${pageNumber}) to use the pagination... Also RxJS is the best
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getFundraisingPageDonations(pageSize: number, pageNumber: number): Observable<FundraisingPageDonations> { | |
| return this.http.get<FundraisingPageDonations>(jgEnvironment.justgiving.baseUri + | |
| `/fundraising/pages/${jgEnvironment.justgiving.pageShortName}/donations?pageSize=${pageSize}&pageNumber=${pageNumber}`, | |
| jgEnvironment.justgiving.httpOptions); | |
| } | |
| getAllJustGivingDonations(): Observable<JustGivingDonation[]> { | |
| const justGivingDonations: JustGivingDonation[] = []; | |
| // get first page | |
| return this.getFundraisingPageDonations(150, 1).pipe( | |
| // get the donations | |
| map((fundraisingPageDonations: FundraisingPageDonations) => { | |
| justGivingDonations.push(...fundraisingPageDonations.donations); | |
| return fundraisingPageDonations.pagination; | |
| }), | |
| // if more pages remain get the donations from them as well | |
| tap(pagination => range(1, pagination.totalPages).pipe( | |
| delay(5 * 1000), | |
| tap((pageNumber: number) => { | |
| console.log('pageNumber', pageNumber); | |
| this.getFundraisingPageDonations(150, pageNumber).pipe( | |
| tap((fundraisingPageDonations: FundraisingPageDonations) => { | |
| justGivingDonations.push(...fundraisingPageDonations.donations); | |
| }) | |
| ); | |
| } | |
| ))), | |
| switchMap(() => { | |
| console.log('switchMap justGivingDonations', justGivingDonations); | |
| return of(justGivingDonations); | |
| }) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment