Skip to content

Commit f6cfb61

Browse files
authored
Merge pull request #184 from tutorcruncher/pagination-section
Added Pagination Section
2 parents b53857c + 790d7d2 commit f6cfb61

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed

pages/api.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ info_sections:
2020
title: Custom Fields
2121
id: custom-fields
2222
layout: /custom-fields/custom-fields.yml
23+
-
24+
title: Pagination
25+
id: pagination
26+
layout: /pagination/pagination.yml
2327
# -
2428
# title: Filters
2529
# id: filters

pages/pagination/list-pagination.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"count": 125,
3+
"next": "https://secure.tutorcruncher.com/api/contractors/?page=2",
4+
"previous": null,
5+
"results": [
6+
{ "id": 1, "first_name": "John", "last_name": "Doe", ... },
7+
{ "id": 2, "first_name": "Jane", "last_name": "Smith", ... },
8+
...
9+
]
10+
}
11+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
attributes:
2+
-
3+
name: count
4+
type: integer
5+
description: The total number of objects available.
6+
-
7+
name: next
8+
type: string
9+
description: The URL of the next page of objects.
10+
-
11+
name: previous
12+
type: string
13+
description: The URL of the previous page of objects.
14+
15+

pages/pagination/pagination.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
All list-based GET requests in the TutorCruncher API are paginated to handle large datasets efficiently.
2+
Each page contains up to 100 result objects.

pages/pagination/pagination.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pprint
2+
import requests
3+
4+
headers = {'Authorization': 'token <API KEY>'}
5+
url = 'https://secure.tutorcruncher.com/api/contractors/'
6+
7+
response = requests.get(url, headers=headers)
8+
data = response.json()
9+
pprint.pprint(data['results'])
10+
11+
while data.get('next_page'):
12+
url = data['next_page']
13+
response = requests.get(url, headers=headers)
14+
data = response.json()
15+
pprint.pprint(data['results'])

pages/pagination/pagination.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sections:
2+
-
3+
description: /pagination/pagination.md
4+
attributes: /pagination/pagination-object.yml
5+
code: /pagination/pagination.py
6+
code_type: GET
7+
response: /pagination/list-pagination.json
8+
response_title: RESPONSE
9+

0 commit comments

Comments
 (0)