Skip to content

Commit 494cc4f

Browse files
committed
Provisions for non-API connections (beacon)
1 parent 2c285cf commit 494cc4f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ The CircuitPython version of the data API wrapper for a high-school STEM competi
77

88
# Example code:
99
``` Python
10-
from server import CubeServer, Text
10+
from server import Connection, Text
1111

1212
print("Connecting to the server...")
13-
connection = CubeServer()
13+
connection = Connection()
1414
print("Connected!")
1515

1616
connection.post(Text("Test from CircuitPython!"))

code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Example code"""
22

3-
from server import CubeServer, Text
3+
from server import Connection, Text
44

55
print("Connecting to the server...")
6-
connection = CubeServer()
6+
connection = Connection()
77
print("Connected!")
88

99
connection.post(Text("Test from CircuitPython!"))

server.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ConnectionError(Exception):
118118
class AuthorizationError(ConnectionError):
119119
"""Indicates an issue with the team credentials"""
120120

121-
class CubeServerConfig:
121+
class ConnectionConfig:
122122
"""The configuration of the connection to the server"""
123123
TIMEOUT: int = 60
124124
if 'client_config' in globals():
@@ -132,7 +132,7 @@ class CubeServerConfig:
132132
API_HOST: str = "https://api.local"
133133
API_PORT: int = 8081
134134

135-
CUBESERVER_DEFAULT_CONFIG = CubeServerConfig()
135+
CUBESERVER_DEFAULT_CONFIG = ConnectionConfig()
136136

137137
GameStatus = namedtuple("GameStatus",
138138
['unix_time',
@@ -150,7 +150,7 @@ def _if_conf_exists(key: str):
150150
return None
151151
return getattr(client_config, key)
152152

153-
class CubeServer:
153+
class Connection:
154154
"""A class for connecting to the server"""
155155

156156
def __init__(
@@ -159,14 +159,16 @@ def __init__(
159159
team_secret: str = _if_conf_exists('TEAM_SECRET'),
160160
server_cert: str = _if_conf_exists('SERVER_CERT'),
161161
conf = CUBESERVER_DEFAULT_CONFIG,
162-
verbose: bool = False
162+
verbose: bool = False,
163+
_force: bool = False
163164
):
164165
"""Initializes the connection to the server"""
165166
# Check parameters:
166-
if team_name is None or \
167+
if not _force and \
168+
team_name is None or \
167169
team_secret is None or \
168170
server_cert is None or \
169-
not isinstance(conf, CubeServerConfig):
171+
not isinstance(conf, ConnectionConfig):
170172
raise TypeError("Bad parameters or client config")
171173
self.team_name = team_name
172174
self.team_secret = team_secret
@@ -234,6 +236,9 @@ def _do_request(
234236
content_type: str = None,
235237
headers: list[str] = []
236238
) -> str:
239+
if self.team_name is None:
240+
raise TypeError("This connection instance is not configured properly for making REST requests.")
241+
237242
if self.v:
238243
print(f"Making {method} request to {path}...")
239244

0 commit comments

Comments
 (0)