def _getList (self, methodKey, pagination, responseClassName = None, entityId = None, filter = None, sorting = None): """Get list with entities object from API. param string methodKey Key with request data param pagination Pagination object param object responseClassName Name of entity class from response param int entityId Entity identifier param object filter Object to filter data param object sorting Object to sort data return object Response data """ urlMethod = self._buildUrl(methodKey, entityId) if pagination == None: pagination = Pagination() rest = RestTool(self._root, True) additionalUrlParams = {} if (filter != None): additionalUrlParams['filter'] = filter if (sorting != None): additionalUrlParams['sort'] = sorting.GetSortParameter() response = rest.Request(urlMethod, self._getRequestType(methodKey), None, pagination, additionalUrlParams) if responseClassName != None: return self._castResponseToEntity(response, responseClassName) return response
def _createObject(self, methodKey, entity, responseClassName=None, entityId=None, secondEntityId=None): """Create object in API. param string methodKey Key with request data param object entity Entity object param object responseClassName Name of entity class from response param int entityId Entity identifier param int secondEntityId Releated entity identifier return dictionary Response data """ urlMethod = self._buildUrl(methodKey, entityId, secondEntityId) if entity != None: requestData = self._buildRequestData(entity) log.info("The request data is:") log.info(requestData) log.info("-------------") rest = RestTool(self._root, True) response = rest.Request(urlMethod, self._getRequestType(methodKey), requestData) if responseClassName != None: return self._castResponseToEntity(response, responseClassName) return response
def CreateToken(self): """Get token information for OAuth Authentication. return MangoPay OAuthToken object with token information """ urlMethod = self._getRequestUrl('authentication_oauth') requestType = self._getRequestType('authentication_oauth') requestData = {'grant_type': 'client_credentials'} rest = RestTool(self._root, False) response = rest.Request(urlMethod, requestType, requestData) token = self._castAuthResponseToEntity(response) return token
def _getObject (self, methodKey, entityId, responseClassName = None, secondEntityId = None): """Get entity object from API. param string methodKey Key with request data param int entityId Entity identifier param object responseClassName Name of entity class from response param int secondEntityId Entity identifier for second entity return object Response data """ urlMethod = self._buildUrl(methodKey, entityId, secondEntityId) rest = RestTool(self._root, True) response = rest.Request(urlMethod, self._getRequestType(methodKey)) if responseClassName != None: return self._castResponseToEntity(response, responseClassName) return response
def _saveObject (self, methodKey, entity, responseClassName = None, entityId = None, secondEntityId = None): """Save object in API. param string methodKey Key with request data param object entity Entity object to save param object responseClassName Name of entity class from response return object Response data """ if (entityId == None): entityId = entity.Id urlMethod = self._buildUrl(methodKey, entityId, secondEntityId) requestData = self._buildRequestData(entity) rest = RestTool(self._root, True) response = rest.Request(urlMethod, self._getRequestType(methodKey), requestData) if responseClassName != None: return self._castResponseToEntity(response, responseClassName) return response
def Create(self, clientId, clientName, clientEmail): """Get client data for Basic Access Authentication. param string clientId Client identifier param string clientName Beautiful name for presentation param string clientEmail Client's email return Client object """ urlMethod = self._getRequestUrl('authentication_base') requestType = self._getRequestType('authentication_base') requestData = { 'ClientId': clientId, 'Name': clientName, 'Email': clientEmail, } rest = RestTool(self._root, False) response = rest.Request(urlMethod, requestType, requestData) return self._castResponseToEntity(response, 'Client')