Exemplo n.º 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())
Exemplo n.º 2
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_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, False)
         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())