Exemplo n.º 1
0
 def returnContainer(self, id, storeId):
     '''
     Description   - Mark a container as taken back from an user
     Parameters    - id: containerId
                     storeId: the id of the store you belong
     Return values - status code(number)
                     previous host(string)
                     container id(string)
                     container type(string)
     '''
     headers = {
         'Authorization': Jwt.addDate(self.secretKey),
         'apiKey': self.apiKey,
         'Content-Type': 'application/json'
     }
     r = requests.post(baseUrl + self.ver + Uri.returnContainer + str(id),
                       headers=headers)
     if r.status_code == 200:
         if (r.json()['message'] == 'Already Return'):
             return (r.status_code, r.json()['message'])
         container = r.json()['containerList'][0]
         user = r.json()['oriUser']
         return (r.status_code, user, str(container['id']),
                 container['typeName'])
     else:
         return (r.status_code, r.json()['message'])
Exemplo n.º 2
0
 def rentContainer(self, id, userApiKey):
     '''
     Description   - Rent a container to an user
     Parameters    - id: container id
                     userApiKey: the apiKey of the user, you can get it by calling `fetchUserToken(self, user)`
     Return values - status code(number)
     '''
     headers = {
         'Authorization': Jwt.addDate(self.secretKey),
         'apiKey': self.apiKey,
         'userApiKey': userApiKey
     }
     r = requests.post(baseUrl + self.ver + Uri.lendContainer + str(id),
                       headers=headers)
     return (r.status_code)
Exemplo n.º 3
0
 def fetchSocketNamespaceAndToken(self):
     '''
     Description   - Fetch crucial information used for connecting to server websocket
     Parameters    - N/A
     Retrun values - status code(number),
                     token(string)
                     real uri(string)
     '''
     headers = {
         'Authorization': Jwt.standard(self.secretKey),
         'apiKey': self.apiKey
     }
     r = requests.get(baseUrl + self.ver + Uri.socketToken, headers=headers)
     json = r.json()
     (token, uri) = (json['token'], json['uri'])
     return (r.status_code, token, uri)
Exemplo n.º 4
0
 def reloadContainer(self, id, storeId):
     '''
     Discription   - Mark a container as clean after used
     Parameters    - id: containerId
                     storeId: the id of the store where the container used to belong
                     date: timestamps of the action
     Return values - status code(number)
     '''
     headers = {
         'Authorization': Jwt.addDate(self.secretKey),
         'apiKey': self.apiKey,
         'Content-Type': 'application/json'
     }
     r = requests.post(baseUrl + self.ver + Uri.reloadContainer + str(id),
                       headers=headers,
                       json={'storeId': storeId})
     return r.status_code
Exemplo n.º 5
0
 def modifyDeliveryBoxInfo(self, boxId, body):
     '''
     Description    - modify info of the box
     Parameters     - boxId: the id of the target box
                      body: new info
     Return values  - status code(number)
     '''
     headers = {
         'Authorization': Jwt.standard(self.secretKey),
         'apiKey': self.apiKey,
         'Content-Type': 'application/json'
     }
     r = requests.post(baseUrl + self.ver + Uri.modifyDeliveryBoxInfo +
                       str(boxId),
                       headers=headers,
                       json=body)
     return (r.status_code)
Exemplo n.º 6
0
 def fetchUserToken(self, user):
     '''
     Description   - fetch the apiKey of a specific user
     Parameters    - user: phone number of the user
     Return values - status code(number)
                     api key(string)
     '''
     headers = {
         'Authorization': Jwt.standard(self.secretKey),
         'apiKey': self.apiKey
     }
     r = requests.get(baseUrl + self.ver + Uri.userToken + user,
                      headers=headers)
     if r.status_code == 200:
         json = r.json()
         return (r.status_code, json['apiKey'])
     else:
         return (r.status_code, '')
Exemplo n.º 7
0
 def signDeliveryBox(self, boxId):
     '''
     Description   - sign the =box
     Parameters    - boxId: target box
     Return values - status code(number)
     '''
     headers = {
         'Authorization': Jwt.standard(self.secretKey),
         'apiKey': self.apiKey,
         'Content-Type': 'application/json'
     }
     r = requests.post(baseUrl + self.ver + Uri.signDeliveryBox,
                       headers=headers,
                       json={
                           'phone': "",
                           'boxList': [{
                               "ID": str(boxId)
                           }]
                       })
     return (r.status_code)
Exemplo n.º 8
0
 def createDeliveryStockBox(self, ids):
     '''
     Descriptions    - Create a stocked delivery box
     Parameters      - ids: id of containers for stocking
     Return values   - status code(number)
     '''
     headers = {
         'Authorization': Jwt.standard(self.secretKey),
         'apiKey': self.apiKey,
         'Content-Type': 'application/json'
     }
     r = requests.post(baseUrl + self.ver + Uri.createStockBox,
                       headers=headers,
                       json={
                           'phone': '',
                           'boxList': [{
                               'boxName': '',
                               'containerList': ids
                           }]
                       })
     return (r.status_code)
Exemplo n.º 9
0
 def modiftDeliveryBoxState(self, boxId, newState):
     '''
     Description     - modify state of the box
     Parameters      - boxId: the id of the box
                       newState: the new state of the box
     Return values   - status code(number)
     '''
     headers = {
         'Authorization': Jwt.standard(self.secretKey),
         'apiKey': self.apiKey,
         'Content-Type': 'application/json'
     }
     r = requests.post(baseUrl + self.ver + Uri.modifyDeliveryBoxState,
                       headers=headers,
                       json={
                           'phone': "",
                           'boxList': [{
                               'id': str(boxId),
                               'newState': newState
                           }]
                       })
     return (r.status_code)
Exemplo n.º 10
0
    def usedAmount(self):
        '''
        Description   - get used amount of this bot
        Parameters    - N/A
        Return values - status code(number)
                        total amount of used containers(number)
        '''
        headers = {
            'Authorization': Jwt.standard(self.secretKey),
            'apiKey': self.apiKey
        }
        r = requests.get(baseUrl + self.ver + Uri.usedAmount, headers=headers)
        json = r.json()
        print(json)
        storeRecords = json['store']

        total = 0

        if r.status_code == 200:
            for record in storeRecords:
                total += record['amount']
            return (r.status_code, total)
        else:
            return (r.status_code, 0)