-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiAccess.py
executable file
·55 lines (41 loc) · 1.46 KB
/
ApiAccess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import httplib2
def SubmitWeight(workOrderNumber, weight, testingMode):
"""submit weight to web api"""
# make some fake apiResult data if we're testing
if (testingMode):
pass
#result = ApiResponse(200, "everything is awesome!")
#return result
try:
h = httplib2.Http('.cache')
url = 'http://incomtek3/api/partWeights/records/scale/' + workOrderNumber + "/" + weight
response, content = h.request(url, "POST", headers={'content-length':'0'} )
responseStatus = response.status
data = content.decode("utf-8") # convert byte to string
result = ApiResponse(responseStatus, data)
return result
except Exception as e:
import LcdStuff as lcd
# lcd.setText(e.args[0])
lcd.setText("There was an error sending the weight")
import LedConfig as leds
leds.blinkNoGoLeds()
finally:
pass
class ApiResponse():
""" an object to encapsulate a response from the api """
def __init__(self, responseStatus, responseData):
self.status = responseStatus
self.data = responseData
@property
def status(self):
return self.__status
@status.setter
def status(self, status):
self.__status = status
@property
def data(self):
return self.__data
@data.setter
def data(self, data):
self.__data = data