Skip to content

Commit

Permalink
Merge pull request #5 from InvisibleSymbol/master
Browse files Browse the repository at this point in the history
 add remaining api functions
  • Loading branch information
tybug authored Feb 15, 2019
2 parents 8f6f2b8 + 31ad8bf commit 4c1ced0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# osuAPI

OsuAPI is a minimal python wrapper for the osu api. Endpoints are implemented as necessary for the [circleguard](https://github.com/circleguard/circleguard) project. Passed keys (endpoint parameter key/value pairs, not the api key) are checked to make sure the api will accept them, and that all required keys are present. No attempt is made to check http status codes or retry requests that fail.

Currently, only the `get_replay`, `get_scores`, `get_user_best` and `get_user_recent` endpoints are implemented. Should you be a completionist, you are more than welcome to PR the rest in.
OsuAPI is a minimal python wrapper for the osu api. This wrapper was created for, and is used in, the [circleguard](https://github.com/circleguard/circleguard) project. Passed keys (endpoint parameter key/value pairs, not the api key) are checked to make sure the api will accept them, and that all required keys are present. No attempt is made to check http status codes or retry requests that fail.

### Usage

Expand Down
15 changes: 15 additions & 0 deletions osuAPI/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# can't use nested enums, so even though it hurts my soul...nested classes it is
class ENDPOINTS():
class GET_BEATMAPS():
EXTENSION = "get_beatmaps"
REQUIRED = [] # this is according to https://github.com/ppy/osu-api/wiki
POSSIBLE = ["since", "s", "b", "u", "type", "m", "a", "h", "limit"]

class GET_MATCH():
EXTENSION = "get_match"
REQUIRED = ["mp"]
POSSIBLE = ["mp"]

class GET_SCORES():
EXTENSION = "get_scores"
REQUIRED = ["b"]
Expand All @@ -10,6 +20,11 @@ class GET_REPLAY():
REQUIRED = ["m", "b", "u"]
POSSIBLE = ["m", "b", "u", "mods"]

class GET_USER():
EXTENSION = "get_user"
REQUIRED = ["u"]
POSSIBLE = ["u", "m", "type", "event_days"]

class GET_USER_BEST():
EXTENSION = "get_user_best"
REQUIRED = ["m", "u"]
Expand Down
24 changes: 24 additions & 0 deletions osuAPI/osuAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def _process_url(self, url):
"""Makes a request to the osu api and returns the json response."""
return requests.get(url).json()

def get_beatmaps(self, params):
"""Retrieves a list of maps an their information."""
ep = ENDPOINTS.GET_BEATMAPS
self._check_parameters(ep, params)
url = self.base_url.format(ep.EXTENSION)
url = self._extend_url(url, params)
return self._process_url(url)

def get_match(self, params):
"""Retrieves information about a multiplayer match."""
ep = ENDPOINTS.GET_MATCH
self._check_parameters(ep, params)
url = self.base_url.format(ep.EXTENSION)
url = self._extend_url(url, params)
return self._process_url(url)

def get_scores(self, params):
"""Retrieves score data about the leaderboards of a map."""
ep = ENDPOINTS.GET_SCORES
Expand All @@ -52,6 +68,14 @@ def get_replay(self, params):
url = self._extend_url(url, params)
return self._process_url(url)

def get_user(self, params):
"""Retrieves information about a user."""
ep = ENDPOINTS.GET_USER
self._check_parameters(ep, params)
url = self.base_url.format(ep.EXTENSION)
url = self._extend_url(url, params)
return self._process_url(url)

def get_user_best(self, params):
"""Retrieves top scores of a user."""
ep = ENDPOINTS.GET_USER_BEST
Expand Down

0 comments on commit 4c1ced0

Please sign in to comment.