Created
June 25, 2021 20:02
-
-
Save dwcoltri/f1c0c718ea53edde348b6cade48ab311 to your computer and use it in GitHub Desktop.
This file contains 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
import requests | |
import json | |
class GameClient: | |
def __init__(self): | |
self.uri = 'https://lq-space.herokuapp.com' | |
self.headers = None | |
def login(self, email, password): | |
response = requests.post(f"{self.uri}/sessions.json", data={"email": email, "password": password}) | |
token = json.loads(response.text)["token"] | |
self.headers = { "Authorization": token } | |
def get(self, endpoint): | |
response = requests.get(f"{self.uri}/{endpoint}.json", headers=self.headers) | |
return json.loads(response.text) | |
@property | |
def locations(self): | |
return self.get('locations') | |
@property | |
def contracts(self): | |
return self.get('contracts') | |
@property | |
def players(self): | |
return self.get('players') | |
def send_command(self, command, args={}): | |
requests.post(f"{self.uri}/send_command.json", data={"command": command, "args": args}, headers=self.headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment