def getOrdersByUpdatedAfter(self, user, offset, updatedAfter): parameters = { 'Action': 'GetOrders', 'Format': 'JSON', 'Timestamp': LazadaApiHelper.getCurrentUTCTime(), 'UserID': user['lazada_user_id'], 'Version': LazadaAPI.VERSION, 'Limit': LazadaAPI.LIMIT, 'Offset': offset, 'UpdatedAfter': LazadaApiHelper.formatToLazadaTimestamp(updatedAfter), 'SortBy': 'updated_at', 'SortDirection': 'ASC' } parameters['Signature'] = LazadaApiHelper.generateSignature( parameters, user['lazada_api_key']) url = "{}/?Action={}&Format={}&Timestamp={}&UserID={}&Version={}&Limit={}&Offset={}&UpdatedAfter={}&SortBy={}&SortDirection={}&Signature={}".format( LazadaAPI.ENDPOINT, parameters["Action"], parameters["Format"], LazadaApiHelper.formatTimestamp(parameters["Timestamp"]), parameters["UserID"], parameters["Version"], parameters["Limit"], parameters["Offset"], LazadaApiHelper.formatTimestamp(parameters["UpdatedAfter"]), parameters["SortBy"], parameters["SortDirection"], parameters["Signature"]) try: resp = requests.get(url) if resp.status_code == 200: response = json.loads(resp.text) # Request API error if ('ErrorResponse' in response): errorMessage = ExceptionUtils.getBodyMessage(response) return None, '''User: {}-{}, Get-Orders: {}'''.format( user['username'], user['id'], errorMessage) # Request API Success return response['SuccessResponse']['Body']['Orders'], None # Request error return None, '''User: {}-{}, Get-Orders: {}'''.format( user['username'], user['id'], resp.status_code) except Exception as ex: return None, '''User: {}-{}, Get-Orders: {}'''.format( user['username'], user['id'], str(ex))
def getProductByUpdatedAfter(self, user, offset, updatedAfter): parameters = { 'Action': 'GetProducts', 'Format': 'JSON', 'Timestamp': LazadaApiHelper.getCurrentUTCTime(), 'UserID': user['lazada_user_id'], 'Version': '1.0', 'UpdatedAfter': LazadaApiHelper.formatToLazadaTimestamp(updatedAfter), 'Filter': 'all', 'Limit': LazadaAPI.LIMIT, 'Offset': offset } parameters['Signature'] = LazadaApiHelper.generateSignature( parameters, user['lazada_api_key']) url = "{}/?Action={}&Format={}&Timestamp={}&UserID={}&Version={}&Signature={}&UpdatedAfter={}&Filter={}&Offset={}&Limit={}".format( LazadaAPI.ENDPOINT, parameters["Action"], parameters["Format"], LazadaApiHelper.formatTimestamp(parameters["Timestamp"]), parameters["UserID"], parameters["Version"], parameters["Signature"], LazadaApiHelper.formatTimestamp(parameters["UpdatedAfter"]), parameters["Filter"], parameters["Offset"], parameters["Limit"]) try: resp = requests.get(url) if resp.status_code == 200: response = json.loads(resp.text) if ('ErrorResponse' in response): return None, ExceptionUtils.returnError( '''Get Products is error: ''', response) data = response['SuccessResponse']['Body'] return data['Products'], None return None, '''Get Products is error: {}'''.format( resp.status_code) except Exception as ex: return None, '''Get Products is error: {}'''.format(str(ex))