#!/usr/bin/env python3 # -*- coding: utf-8 -*- import requests class TeamSpeakApi: """ class to interact with the teamspeak rest api """ def __init__(self, apikey: str, url: str): # variables self._apikey = apikey self._url = url # define api handler self.cmd = self._rest self.session = requests.Session() @property def _auth(self): if self._apikey is not None: return {"x-api-key": self._apikey} def _rest(self, command: str) -> dict: # add authentication header to the session obj auth_header = self._auth # build get request r = self.session.get("/".join([self._url, command]), headers=auth_header, verify=False) # proceed if response is ok if r.ok: return r.json() return {}