Skip to content

Commit 76a7bf2

Browse files
committed
Add method and tests for getting threads on specific pages in the games forum category
1 parent d31c857 commit 76a7bf2

2 files changed

Lines changed: 436 additions & 0 deletions

File tree

loading_api_wrapper/api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,24 @@ def get_thread(self, thread_id, page=None):
129129
successful_response = {"code": response.status_code, "post": data}
130130

131131
return successful_response
132+
133+
def get_games(self, page=None):
134+
url = f"{API_URL}/{API_VERSION}/posts/"
135+
headers = {"User-Agent": USER_AGENT, "games": "games"}
136+
137+
# Chooses a specific page instead of the first page which is the default page.
138+
if page and page > 1:
139+
headers["page"] = str(page)
140+
141+
# Doing this checks to make sure it only return data from a page that exists.
142+
if page and page < 1:
143+
return {"code": 404, "post": {"posts": [], "users": []}}
144+
145+
response = requests.get(url, headers=headers)
146+
data = response.json()
147+
148+
# Page out of range.
149+
if not len(data["posts"]):
150+
return {"code": 404, "post": data}
151+
152+
return {"code": 200, "post": data}

0 commit comments

Comments
 (0)