You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

41 lines
1.2 KiB

import requests
from collections import namedtuple
import datetime
class FortniteAPIClient():
"""Thin API client to work with the Fortnite API at fortniteapi.com
Parameters:
token: API token to use for all requests."""
base_url = "https://fortnite-api.theapinetwork.com"
def __init__(self, token):
self.token = token
def _api_request(self, url) -> dict:
"""Return a JSON response from the API endpoint."""
r = requests.get(url, headers={"Authorization": self.token})
return r.json()["data"]
class FortniteItemClient(FortniteAPIClient):
"""Dedicated subclass to access item endpoints."""
def __init__(self, token):
super().__init__(token)
@property
def store(self) -> list:
"""Return a list of the current items in the store."""
return super()._api_request(self.base_url + "/store/get")
@property
def upcoming(self) -> list:
"""Return a list of unreleased items."""
return super()._api_request(self.base_url + "/upcoming/get")
@property
def item_list(self) -> list:
"""Return a list of all items"""
return super()._api_request(self.base_url + "/items/list")