Skip to content

Commit 657f19c

Browse files
committed
Support output=void and create a new AsyncResponse object
1 parent 53e7169 commit 657f19c

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

Algorithmia/algorithm.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import base64
44
import re
5+
from async_response import AsyncResponse
56

67
class algorithm(object):
78
def __init__(self, client, algoRef, **query_parameters):
@@ -23,6 +24,8 @@ def __init__(self, client, algoRef, **query_parameters):
2324
def pipe(self, input1):
2425
if self.output == 'raw':
2526
return self.__postRawOutput(input1)
27+
elif self.output == 'void':
28+
return self.__postVoidOutput(input1)
2629
else:
2730
responseJson = self.client.postJsonHelper(self.url, input1, **self.query_parameters)
2831

@@ -50,4 +53,11 @@ def __postRawOutput(self, input1):
5053
elif response.status_code == 500:
5154
raise Exception(response.text)
5255
else:
53-
return response.text
56+
return response.text
57+
58+
def __postVoidOutput(self, input1):
59+
responseJson = self.client.postJsonHelper(self.url, input1, **self.query_parameters)
60+
if 'error' in responseJson:
61+
raise Exception(responseJson['error']['message'])
62+
else:
63+
return AsyncResponse(responseJson)

Algorithmia/async_response.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class AsyncResponse(object):
2+
'''
3+
Response from the API for an asynchronous request (output=void)
4+
'''
5+
def __init__(self, server_response):
6+
self.async_protocol = server_response['async']
7+
self.request_id = server_response['request_id']
8+
9+
def __repr__(self):
10+
return 'AsyncResponse(async_protocol=%s, request_id=%s)' % (self.async_protocol, self.request_id)

0 commit comments

Comments
 (0)