Skip to content

Commit f8615d5

Browse files
author
Christopher Merrick
committed
remove namespace, tighter exception raising
1 parent 8b9cb68 commit f8615d5

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

stitch/client.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,20 @@ def take(self, batch_size_bytes, batch_delay_millis):
6060

6161
_buffer = Buffer()
6262

63-
def __init__(self, \
64-
client_id, \
65-
token, \
66-
namespace, \
67-
table_name = None, \
68-
key_names = None, \
69-
callback_function = None, \
70-
stitch_url = DEFAULT_STITCH_URL, \
71-
batch_size_bytes = DEFAULT_BATCH_SIZE_BYTES, \
72-
batch_delay_millis = DEFAULT_BATCH_DELAY_MILLIS):
63+
def __init__(self,
64+
client_id,
65+
token,
66+
table_name=None,
67+
key_names=None,
68+
callback_function=None,
69+
stitch_url=DEFAULT_STITCH_URL,
70+
batch_size_bytes=DEFAULT_BATCH_SIZE_BYTES,
71+
batch_delay_millis=DEFAULT_BATCH_DELAY_MILLIS):
7372

7473
assert isinstance(client_id, int), 'client_id is not an integer: {}'.format(client_id)
7574

7675
self.client_id = client_id
7776
self.token = token
78-
self.namespace = namespace
7977
self.table_name = table_name
8078
self.key_names = key_names
8179
self.stitch_url = stitch_url
@@ -99,7 +97,6 @@ def push(self, message, callback_arg = None):
9997
raise ValueError('Message action property must be one of: "upsert", "switch_view"')
10098

10199
message['client_id'] = self.client_id
102-
message['namespace'] = self.namespace
103100
message.setdefault('table_name', self.table_name)
104101

105102
with StringIO() as s:
@@ -145,6 +142,8 @@ def _send_batch(self, batch):
145142
if response.status < 300:
146143
if self.callback_function is not None:
147144
self.callback_function([x.callback_arg for x in batch])
145+
else:
146+
raise RuntimeError("Error sending data to the Stitch API, with response status code {}".format(response.status))
148147

149148

150149
def flush(self):
@@ -164,7 +163,7 @@ def __exit__(self, exception_type, exception_value, traceback):
164163
if __name__ == "__main__":
165164
logging.basicConfig(level=logging.DEBUG)
166165

167-
with Client(int(os.environ['STITCH_CLIENT_ID']), os.environ['STITCH_TOKEN'], os.environ['STITCH_NAMESPACE'], callback_function=print) as c:
166+
with Client(int(os.environ['STITCH_CLIENT_ID']), os.environ['STITCH_TOKEN'], callback_function=print) as c:
168167
for i in range(1,10):
169168
c.push({'action': 'upsert',
170169
'table_name': 'cm_test_table',

0 commit comments

Comments
 (0)