Example #1
0
 def upload_attachment(self, file_path, upload_file=True):
     try:
         self.authenticate_request()
         if upload_file:
             files = {'file': open(file_path, 'rb')}
         else:
             files = self.request_body
         connector = HTTPConnector.get_instance(self.url,
                                                self.request_params,
                                                self.request_headers,
                                                self.request_body,
                                                self.request_method,
                                                self.request_api_key, True)
         connector.set_file(files)
         response = connector.trigger_request()
         return APIResponse(response, response.status_code, self.url,
                            self.request_api_key)
     except ZCRMException as ex:
         raise ex
     except Exception as ex:
         try:
             from .Utility import CommonUtil
         except ImportError:
             from Utility import CommonUtil
         import traceback
         CommonUtil.raise_exception(self.url, ex.message,
                                    traceback.format_stack())
 def download_attachment(self):
     try:
         self.authenticate_request()
         connector=HTTPConnector.get_instance(self.url, self.request_params, self.request_headers, self.request_body, self.request_method, self.request_api_key, True)
         response=connector.trigger_request()
         if response.status_code==APIConstants.RESPONSECODE_OK:
             file_res= FileAPIResponse(response,response.status_code,self.url)
             file_res.status=APIConstants.STATUS_SUCCESS
             content_disp=response.headers['Content-Disposition']
             start_index=content_disp.rindex("'")
             file_res.file_name=content_disp[start_index+1:]
             file_res.response_headers=response.headers
             return file_res
         elif(response.status_code==APIConstants.RESPONSECODE_NO_CONTENT):
             errorMsg=APIConstants.INVALID_DATA+"-"+APIConstants.INVALID_ID_MSG
             exception=ZCRMException(self.url,response.status_code,errorMsg,APIConstants.NO_CONTENT,None,errorMsg)
             exception.message = exception.__str__()
             raise exception
         else:
             responseJSON=response.json()
             exception=ZCRMException(self.url,response.status_code,responseJSON[APIConstants.MESSAGE],responseJSON[APIConstants.CODE],responseJSON[APIConstants.DETAILS],responseJSON[APIConstants.MESSAGE])
             exception.message = exception.__str__()
             raise exception
     except ZCRMException as ex:
         raise ex
     except Exception as ex:
         try:
             from .Utility import CommonUtil
         except ImportError:
             from Utility import CommonUtil
         import traceback
         CommonUtil.raise_exception(self.url,ex.message,traceback.format_stack())  
Example #3
0
    def upload_link_as_attachment(self):
        try:
            self.authenticate_request()
            files = {'file': ''}
            connector = HTTPConnector.get_instance(self.url,
                                                   self.request_params,
                                                   self.request_headers,
                                                   self.request_body,
                                                   self.request_method,
                                                   self.request_api_key, True)
            connector.set_file(files)
            response = connector.trigger_request()

            return APIResponse(response, response.status_code, self.url,
                               self.request_api_key)
        except ZCRMException as ex:
            raise ex
        except Exception as ex:
            try:
                from .Utility import CommonUtil
            except ImportError:
                from Utility import CommonUtil
            import traceback
            CommonUtil.raise_exception(self.url, str(ex),
                                       traceback.format_stack())
 def get_bulk_api_response(self):
     try:
         self.authenticate_request()
         connector=HTTPConnector.get_instance(self.url, self.request_params, self.request_headers, self.request_body, self.request_method, self.request_api_key, True)
         response=connector.trigger_request()
         return BulkAPIResponse(response,response.status_code,self.url,self.request_api_key,self.request_method)
     except ZCRMException as ex:
         raise ex
     except Exception as ex:
         try:
             from .Utility import CommonUtil
         except ImportError:
             from Utility import CommonUtil
         import traceback
         CommonUtil.raise_exception(self.url,ex.message,traceback.format_stack())