Exemple #1
0
    def locateMultipleTerminals(self, address, requestedAccuracy):
        """
		locateMultipleTerminals : Get the location of multiple mobile terminals listed in the address parameter
		Parameters:
		address : MSISDN or ACR of the mobile terminal to locate
		requestedAccuracy : requested positional accuracy
		"""
        baseurl = self.endpoints.getLocationEndpoint()
        requestProcessor = JSONRequest()
        if address is not None:
            for item in address:
                baseurl = requestProcessor.addQueryParameter(
                    baseurl, 'address', item)
        baseurl = requestProcessor.addQueryParameter(baseurl,
                                                     'requestedAccuracy',
                                                     requestedAccuracy)
        rawresponse = requestProcessor.get(baseurl, 'application/json',
                                           self.username, self.password)
        response = LocationResponse()
        if rawresponse is not None and rawresponse.getContent() is not None:
            jsondata = json.loads(rawresponse.getContent())
            if jsondata is not None and jsondata[
                    'terminalLocationList'] is not None:
                response.setTerminalLocationListJSON(
                    jsondata['terminalLocationList'])
        if rawresponse.getCode() is not None:
            response.setHTTPResponseCode(rawresponse.getCode())
        if rawresponse.getLocation() is not None:
            response.setLocation(rawresponse.getLocation())
        if rawresponse.getContentType() is not None:
            response.setContentType(rawresponse.getContentType())
        return response
Exemple #2
0
    def retrieveMessages(self, registrationId, maxBatchSize):
        """
		retrieveMessages : retrieve a list of messages sent to your Web application
		Parameters:
		registrationId : the registration ID agreed with the OneAPI operator.
		maxBatchSize : the maximum number of messages to retrieve in this request
		"""
        baseurl = self.endpoints.getRetrieveMMSEndpoint()
        requestProcessor = JSONRequest()
        if '{registrationId}' in baseurl:
            baseurl = baseurl.replace('{registrationId}', str(registrationId))
        if '{maxBatchSize}' in baseurl:
            baseurl = baseurl.replace('{maxBatchSize}', str(maxBatchSize))
        rawresponse = requestProcessor.get(baseurl, 'application/json',
                                           self.username, self.password)
        response = RetrieveMMSResponse()
        if rawresponse is not None and rawresponse.getContent() is not None:
            jsondata = json.loads(rawresponse.getContent())
            if jsondata is not None and jsondata[
                    'inboundMessageList'] is not None:
                response.setInboundMessageListJSON(
                    jsondata['inboundMessageList'])
        if rawresponse.getCode() is not None:
            response.setHTTPResponseCode(rawresponse.getCode())
        if rawresponse.getLocation() is not None:
            response.setLocation(rawresponse.getLocation())
        if rawresponse.getContentType() is not None:
            response.setContentType(rawresponse.getContentType())
        return response
Exemple #3
0
    def retrieveMessageContent(self, registrationId, messageId, resFormat):
        """
		retrieveMessageContent : retrieve the full MMS including attachments
		Parameters:
		registrationId : the registration ID agreed with the OneAPI operator
		messageId : is a server-generated message identifier (which can be obtained from the retrieveMessages response)
		resFormat : resFormat=JSON ensures a JSON response content-type
		"""
        baseurl = self.endpoints.getRetrieveMMSMessageEndpoint()
        requestProcessor = JSONRequest()
        if '{registrationId}' in baseurl:
            baseurl = baseurl.replace('{registrationId}', str(registrationId))
        if '{messageId}' in baseurl:
            baseurl = baseurl.replace('{messageId}', str(messageId))
        if '{resFormat}' in baseurl:
            baseurl = baseurl.replace('{resFormat}', str(resFormat))
        rawresponse = requestProcessor.get(baseurl, 'application/json',
                                           self.username, self.password)
        response = RetrieveMMSMessageResponse()
        if rawresponse is not None and rawresponse.getContent() is not None:
            mimecontent = 'Content-Type: ' + rawresponse.getContentType(
            ) + '\r\n' + rawresponse.getContent()
            response = RetrieveMMSMessageResponse()
            response.setAttachment(None)
            mimemsg = email.message_from_string(mimecontent)
            for part in mimemsg.walk():
                contentType = part.get_content_type()
                if 'multipart/mixed' not in contentType:
                    filename = part.get_filename()
                    payload = part.get_payload()
                    if contentType is not None and contentType == 'application/json' and filename is not None and filename == 'root-fields' and payload is not None:
                        jsondata = json.loads(payload)
                        if jsondata is not None and jsondata[
                                'inboundMessage'] is not None:
                            response.setInboundMessage(
                                jsondata['inboundMessage'])
                    else:
                        attachment = Attachment(None)
                        attachment.setContentType(contentType)
                        attachment.setName(filename)
                        attachment.setData(payload)
                        if response.getAttachment() == None:
                            response.setAttachment([])
                        response.getAttachment().append(attachment)
        if rawresponse.getCode() is not None:
            response.setHTTPResponseCode(rawresponse.getCode())
        if rawresponse.getLocation() is not None:
            response.setLocation(rawresponse.getLocation())
        if rawresponse.getContentType() is not None:
            response.setContentType(rawresponse.getContentType())
        return response
Exemple #4
0
    def check_state(self,cr,uid,ids,context=None):
        time.sleep(2)
        connect_obj = self.pool.get('connect.connect')
        connect_ids = connect_obj.search(cr,uid,[('type','=',"sending")])
        connect_rec = connect_obj.browse(cr, uid, connect_ids)
        password=str(connect_rec[0].password)
        username=str(connect_rec[0].username)
        url=str(connect_rec[0].url)
        endpoints=url
        registration_id = connect_rec[0].registration_id
        baseurl=endpoints
        ''' instantiantion de la classe JSONRequest() '''
        requestProcessor=JSONRequest()
        for i in ids:
            mess_id=self.browse(cr,uid,i).mess_id
            if '{registration_id}' in baseurl: baseurl=baseurl.replace('{registration_id}',str(registration_id))
            url=baseurl+'/'+str(mess_id)
            time.sleep(0.05)
            sentRessource= url + "/deliveryInfos"
            rawresponse=requestProcessor.get(sentRessource,'application/json', username, password)
            print rawresponse.getContent()
            if rawresponse is not None and rawresponse.getContent() is not None:
                jsondata=json.loads(rawresponse.getContent())
                if jsondata is not None and jsondata['deliveryInfoList'] is not None:
                    self.write(cr,uid,i,{'deliverystatus':jsondata['deliveryInfoList']['deliveryInfo'][0]['deliveryStatus'],'state':'send'})
                else:
                    self.write(cr,uid,i,{'deliverystatus':rawresponse.getCode()})
            else:
                if rawresponse.getCode() == 400:
                    self.write(cr,uid,i,{'deliverystatus':"Error 400 : Bad Request" })
                if rawresponse.getCode() == 401:
                    self.write(cr,uid,i,{'deliverystatus':"Error 401 : Authentification Failure" })
                if rawresponse.getCode() == 403:
                    self.write(cr,uid,i,{'deliverystatus':"Error 403 : Forbidden Authentification Credentials" })
                if rawresponse.getCode() == 404:
                    self.write(cr,uid,i,{'deliverystatus':"Error 404 : Not Found" })
                if rawresponse.getCode() == 405:
                    self.write(cr,uid,i,{'deliverystatus':"Error 405 : Method Not Supported" })
                if rawresponse.getCode() == 500:
                    self.write(cr,uid,i,{'deliverystatus':"Error 500 : Internal Error" })
                if rawresponse.getCode() == 503:
                    self.write(cr,uid,i,{'deliverystatus':"Error 503 : Server Busy And Service Unavailable" })

        return True    
Exemple #5
0
	def locateTerminal(self,address,requestedAccuracy):
		"""
		locateTerminal : get the location of a single mobile terminal
		Parameters:
		address : MSISDN or ACR of the mobile terminal to locate
		requestedAccuracy : requested positional accuracy
		"""
		baseurl=self.endpoints.getLocationEndpoint()
		requestProcessor=JSONRequest()
		baseurl=requestProcessor.addQueryParameter(baseurl,'address', address)
		baseurl=requestProcessor.addQueryParameter(baseurl,'requestedAccuracy', requestedAccuracy)
		rawresponse=requestProcessor.get(baseurl,'application/json', self.username, self.password)
		response=LocationResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['terminalLocationList'] is not None:
				response.setTerminalLocationListJSON(jsondata['terminalLocationList'])
		if rawresponse.getCode() is not None: response.setHTTPResponseCode(rawresponse.getCode())
		if rawresponse.getLocation() is not None: response.setLocation(rawresponse.getLocation())
		if rawresponse.getContentType() is not None: response.setContentType(rawresponse.getContentType())
		return response
	def retrieveMessages(self,registrationId,maxBatchSize):
		"""
		retrieveMessages : retrieve a list of messages sent to your Web application
		Parameters:
		registrationId : the registration ID agreed with the OneAPI operator.
		maxBatchSize : the maximum number of messages to retrieve in this request
		"""
		baseurl=self.endpoints.getRetrieveMMSEndpoint()
		requestProcessor=JSONRequest()
		if '{registrationId}' in baseurl: baseurl=baseurl.replace('{registrationId}',str(registrationId))
		if '{maxBatchSize}' in baseurl: baseurl=baseurl.replace('{maxBatchSize}',str(maxBatchSize))
		rawresponse=requestProcessor.get(baseurl,'application/json', self.username, self.password)
		response=RetrieveMMSResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['inboundMessageList'] is not None:
				response.setInboundMessageListJSON(jsondata['inboundMessageList'])
		if rawresponse.getCode() is not None: response.setHTTPResponseCode(rawresponse.getCode())
		if rawresponse.getLocation() is not None: response.setLocation(rawresponse.getLocation())
		if rawresponse.getContentType() is not None: response.setContentType(rawresponse.getContentType())
		return response
Exemple #7
0
	def queryDeliveryStatus(self,senderAddress,requestId):
		"""
		queryDeliveryStatus : query the delivery status of an SMS send request
		Parameters:
		senderAddress : MSISDN or allocated code of the sender
		requestId : the requestID which was returned in the sendSMS response
		"""
		baseurl=self.endpoints.getQuerySMSDeliveryEndpoint()
		requestProcessor=JSONRequest()
		if '{senderAddress}' in baseurl: baseurl=baseurl.replace('{senderAddress}',str(senderAddress))
		if '{requestId}' in baseurl: baseurl=baseurl.replace('{requestId}',str(requestId))
		rawresponse=requestProcessor.get(baseurl,'application/json', self.username, self.password)
		response=SMSSendDeliveryStatusResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['deliveryInfoList'] is not None:
				response.setDeliveryInfoListJSON(jsondata['deliveryInfoList'])
		if rawresponse.getCode() is not None: response.setHTTPResponseCode(rawresponse.getCode())
		if rawresponse.getLocation() is not None: response.setLocation(rawresponse.getLocation())
		if rawresponse.getContentType() is not None: response.setContentType(rawresponse.getContentType())
		return response
Exemple #8
0
	def queryDeliveryStatus(self,senderAddress,requestId):
		"""
		queryDeliveryStatus : query the delivery status of an MMS
		Parameters:
		senderAddress : MSISDN or allocated code of the sender
		requestId : the requestID which was  returned in sendMMS function
		"""
		baseurl=self.endpoints.getQueryMMSDeliveryEndpoint()
		requestProcessor=JSONRequest()
		if '{senderAddress}' in baseurl: baseurl=baseurl.replace('{senderAddress}',str(senderAddress))
		if '{requestId}' in baseurl: baseurl=baseurl.replace('{requestId}',str(requestId))
		rawresponse=requestProcessor.get(baseurl,'application/json', self.username, self.password)
		response=MMSSendDeliveryStatusResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['deliveryInfoList'] is not None:
				response.setDeliveryInfoListJSON(jsondata['deliveryInfoList'])
		if rawresponse.getCode() is not None: response.setHTTPResponseCode(rawresponse.getCode())
		if rawresponse.getLocation() is not None: response.setLocation(rawresponse.getLocation())
		if rawresponse.getContentType() is not None: response.setContentType(rawresponse.getContentType())
		return response
	def retrieveMessageContent(self,registrationId,messageId,resFormat):
		"""
		retrieveMessageContent : retrieve the full MMS including attachments
		Parameters:
		registrationId : the registration ID agreed with the OneAPI operator
		messageId : is a server-generated message identifier (which can be obtained from the retrieveMessages response)
		resFormat : resFormat=JSON ensures a JSON response content-type
		"""
		baseurl=self.endpoints.getRetrieveMMSMessageEndpoint()
		requestProcessor=JSONRequest()
		if '{registrationId}' in baseurl: baseurl=baseurl.replace('{registrationId}',str(registrationId))
		if '{messageId}' in baseurl: baseurl=baseurl.replace('{messageId}',str(messageId))
		if '{resFormat}' in baseurl: baseurl=baseurl.replace('{resFormat}',str(resFormat))
		rawresponse=requestProcessor.get(baseurl,'application/json', self.username, self.password)
		response=RetrieveMMSMessageResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			mimecontent='Content-Type: '+rawresponse.getContentType()+'\r\n'+rawresponse.getContent()
			response=RetrieveMMSMessageResponse()
			response.setAttachment(None)
			mimemsg=email.message_from_string(mimecontent)
			for part in mimemsg.walk():
				contentType=part.get_content_type()
				if 'multipart/mixed' not in contentType:
					filename=part.get_filename()
					payload=part.get_payload()
					if contentType is not None and contentType=='application/json' and filename is not None and filename=='root-fields' and payload is not None:
						jsondata=json.loads(payload)
						if jsondata is not None and jsondata['inboundMessage'] is not None:
							response.setInboundMessage(jsondata['inboundMessage'])
					else:
						attachment=Attachment(None)
						attachment.setContentType(contentType)
						attachment.setName(filename)
						attachment.setData(payload)
						if response.getAttachment()==None: response.setAttachment([])
						response.getAttachment().append(attachment)
		if rawresponse.getCode() is not None: response.setHTTPResponseCode(rawresponse.getCode())
		if rawresponse.getLocation() is not None: response.setLocation(rawresponse.getLocation())
		if rawresponse.getContentType() is not None: response.setContentType(rawresponse.getContentType())
		return response
Exemple #10
0
    def check_state(self, cr, uid, ids, context=None):
        time.sleep(2)
        connect_obj = self.pool.get('connect.connect')
        connect_ids = connect_obj.search(cr, uid, [('type', '=', "sending")])
        connect_rec = connect_obj.browse(cr, uid, connect_ids)
        password = str(connect_rec[0].password)
        username = str(connect_rec[0].username)
        url = str(connect_rec[0].url)
        endpoints = url
        registration_id = connect_rec[0].registration_id
        baseurl = endpoints
        ''' instantiantion de la classe JSONRequest() '''
        requestProcessor = JSONRequest()
        for i in ids:
            mess_id = self.browse(cr, uid, i).mess_id
            if '{registration_id}' in baseurl:
                baseurl = baseurl.replace('{registration_id}',
                                          str(registration_id))
            url = baseurl + '/' + str(mess_id)
            time.sleep(0.05)
            sentRessource = url + "/deliveryInfos"
            rawresponse = requestProcessor.get(sentRessource,
                                               'application/json', username,
                                               password)
            print rawresponse.getContent()
            if rawresponse is not None and rawresponse.getContent(
            ) is not None:
                jsondata = json.loads(rawresponse.getContent())
                if jsondata is not None and jsondata[
                        'deliveryInfoList'] is not None:
                    self.write(
                        cr, uid, i, {
                            'deliverystatus':
                            jsondata['deliveryInfoList']['deliveryInfo'][0]
                            ['deliveryStatus'],
                            'state':
                            'send'
                        })
                else:
                    self.write(cr, uid, i,
                               {'deliverystatus': rawresponse.getCode()})
            else:
                if rawresponse.getCode() == 400:
                    self.write(cr, uid, i,
                               {'deliverystatus': "Error 400 : Bad Request"})
                if rawresponse.getCode() == 401:
                    self.write(cr, uid, i, {
                        'deliverystatus':
                        "Error 401 : Authentification Failure"
                    })
                if rawresponse.getCode() == 403:
                    self.write(
                        cr, uid, i, {
                            'deliverystatus':
                            "Error 403 : Forbidden Authentification Credentials"
                        })
                if rawresponse.getCode() == 404:
                    self.write(cr, uid, i,
                               {'deliverystatus': "Error 404 : Not Found"})
                if rawresponse.getCode() == 405:
                    self.write(
                        cr, uid, i,
                        {'deliverystatus': "Error 405 : Method Not Supported"})
                if rawresponse.getCode() == 500:
                    self.write(
                        cr, uid, i,
                        {'deliverystatus': "Error 500 : Internal Error"})
                if rawresponse.getCode() == 503:
                    self.write(
                        cr, uid, i, {
                            'deliverystatus':
                            "Error 503 : Server Busy And Service Unavailable"
                        })

        return True