Ejemplo n.º 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
Ejemplo n.º 2
0
	def subscribeToDeliveryNotifications(self,senderAddress,clientCorrelator,notifyURL,callbackData):
		"""
		subscribeToDeliveryNotifications : subscribe to MMS delivery notifications
		Parameters:
		senderAddress : MSISDN or allocated code of the sender
		clientCorrelator : (string) uniquely identifies this create subscription request. If there is a communication failure during the request, using the same clientCorrelator when retrying the request allows the operator to avoid creating a duplicate subscription.
		notifyURL : (URL) This will be used by the server to POST the notifications to you, so include the URL of your own listener application.
		callbackData : (string) is a function name or other data that you would like included when the POST is received.
		"""
		baseurl=self.endpoints.getMMSDeliverySubscriptionsEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('senderAddress',senderAddress)
		if '{senderAddress}' in baseurl: baseurl=baseurl.replace('{senderAddress}',str(senderAddress))
		formparameters.put('clientCorrelator',clientCorrelator)
		formparameters.put('notifyURL',notifyURL)
		formparameters.put('callbackData',callbackData)
		postdata=formparameters.encodeParameters()
		rawresponse=requestProcessor.post(baseurl,postdata,'application/json', self.username, self.password)
		response=MMSDeliveryReceiptSubscriptionResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['deliveryReceiptSubscription'] is not None:
				response.setDeliveryReceiptSubscriptionJSON(jsondata['deliveryReceiptSubscription'])
		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
Ejemplo n.º 3
0
	def subscribeToReceiptNotifications(self,destinationAddress,notifyURL,criteria,notificationFormat,clientCorrelator,callbackData):
		"""
		subscribeToReceiptNotifications : subscribe to notifications of MMS messages sent to your application
		Parameters:
		destinationAddress : the MSISDN, or code agreed with the operator, to which people may send an MMS to your application
		notifyURL : (URL) is your address to which notifications will be sent
		criteria : (string) is case-insensitve text to match against the first word of the message, ignoring any leading whitespace. This allows you to reuse a short code among various applications, each of which can register their own subscription with different criteria.
		notificationFormat : is the content type that notifications will be sent in - for OneAPI v1.0 only JSON is supported.
		clientCorrelator : (string) uniquely identifies this create subscription request. If there is a communication failure during the request, using the same clientCorrelator when retrying the request allows the operator to avoid creating a duplicate subscription.
		callbackData : (string) is a function name or other data that you would like included when the POST is received.
		"""
		baseurl=self.endpoints.getMMSReceiptSubscriptionsEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('destinationAddress',destinationAddress)
		formparameters.put('notifyURL',notifyURL)
		formparameters.put('criteria',criteria)
		formparameters.put('notificationFormat',notificationFormat)
		formparameters.put('clientCorrelator',clientCorrelator)
		formparameters.put('callbackData',callbackData)
		postdata=formparameters.encodeParameters()
		rawresponse=requestProcessor.post(baseurl,postdata,'application/json', self.username, self.password)
		response=MMSMessageReceiptSubscriptionResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['resourceReference'] is not None:
				response.setResourceReferenceJSON(jsondata['resourceReference'])
		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
Ejemplo n.º 4
0
	def subscribeToDeliveryNotifications(self,senderAddress,clientCorrelator,notifyURL,callbackData):
		"""
		subscribeToDeliveryNotifications : subscribe to SMS delivery notifications
		Parameters:
		senderAddress : MSISDN or allocated code of the sender
		clientCorrelator : string) uniquely identifies this create subscription request. If there is a communication failure during the request, using the same clientCorrelator when retrying the request allows the operator to avoid creating a duplicate subscription.
		notifyURL : (URL) This will be used by the server to POST the notifications to you, so include the URL of your own listener application.
		callbackData : (string) is a function name or other data that you would like included when the POST is received.
		"""
		baseurl=self.endpoints.getSMSDeliverySubscriptionsEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('senderAddress',senderAddress)
		if '{senderAddress}' in baseurl: baseurl=baseurl.replace('{senderAddress}',str(senderAddress))
		formparameters.put('clientCorrelator',clientCorrelator)
		formparameters.put('notifyURL',notifyURL)
		formparameters.put('callbackData',callbackData)
		postdata=formparameters.encodeParameters()
		rawresponse=requestProcessor.post(baseurl,postdata,'application/json', self.username, self.password)
		response=SMSDeliveryReceiptSubscriptionResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['deliveryReceiptSubscription'] is not None:
				response.setDeliveryReceiptSubscriptionJSON(jsondata['deliveryReceiptSubscription'])
		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
Ejemplo n.º 5
0
 def action_sendSMS(self,cr,uid,ids,number,sms, context=None):
     if not number and ids:
         self.write(cr,uid,ids,{'state':'notsend'})
         return False
     num='tel:' + number
     message=sms
     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()
     if '{registration_id}' in baseurl: baseurl=baseurl.replace('{registration_id}',str(registration_id))
     formdata = { 'message' : str(message.encode('utf-8')) , 'address': num, 'senderAddress' : registration_id}
     data_encoded = urllib.urlencode(formdata)
     rawresponse=requestProcessor.post(baseurl,data_encoded,'application/json',username, password)
     print rawresponse
     if rawresponse is not None and rawresponse.getContent() is not None:
         jsondata=json.loads(rawresponse.getContent())
         if jsondata is not None and jsondata['resourceReference'] is not None:
             mondict=jsondata['resourceReference']
             monEndpoint = str(mondict['resourceURL'])
             datas=monEndpoint.split('/')
             lgt=len(datas)
             mess_id=datas[lgt-1]
             if ids:
                 self.write(cr,uid,ids,{'mess_id':mess_id})
     return True
Ejemplo n.º 6
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
Ejemplo n.º 7
0
	def releaseReservation(self,endUserId,transactionId,referenceCode,referenceSequence):
		"""
		releaseReservation : release the reservation
		Parameters:
		endUserId : is end user ID; either MSISDN including the 'tel:' protocol identifier. OneAPI also supports the Anonymous Customer Reference (ACR) if provided by the operator.
		transactionId : uniquely identifies the reservation transaction - used in maintaining the sequence of transactions
		referenceCode : (string, unique per charge event) is your reference for reconciliation purposes. The operator should include it in reports so that you can match their view of what has been sold with yours by matching the referenceCodes.
		referenceSequence : (integer) - this allows the server to distinguish easily between new and repeated requests in the case of a communication failure. For each transaction within a reservation sequence, iterate the referenceSequence by 1
		"""
		baseurl=self.endpoints.getAmountReservationReleaseEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('endUserId',endUserId)
		if '{endUserId}' in baseurl: baseurl=baseurl.replace('{endUserId}',str(endUserId))
		formparameters.put('transactionId',transactionId)
		if '{transactionId}' in baseurl: baseurl=baseurl.replace('{transactionId}',str(transactionId))
		formparameters.put('referenceCode',referenceCode)
		formparameters.put('referenceSequence',referenceSequence)
		postdata=formparameters.encodeParameters()
		rawresponse=requestProcessor.post(baseurl,postdata,'application/json', self.username, self.password)
		response=AmountReservationResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['amountReservationTransaction'] is not None:
				response.setAmountReservationTransactionJSON(jsondata['amountReservationTransaction'])
		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
Ejemplo n.º 8
0
    def chargeWithCallback(self, endUserId, referenceCode, description,
                           currency, amount, code, callbackURL,
                           clientCorrelator, onBehalfOf, purchaseCategoryCode,
                           channel, taxAmount, serviceId, productId):
        """
		chargeWithCallback : charge an amount to the end user's bill. Note all parameters are URL encoded by the API functions so this is not needed by the application
		Parameters:
		endUserId : is end user ID; either MSISDN including the 'tel:' protocol identifier. OneAPI also supports the Anonymous Customer Reference (ACR) if provided by the operator.
		referenceCode : (string, unique per charge event) is your reference for reconciliation purposes. The operator should include it in reports so that you can match their view of what has been sold with yours by matching the referenceCodes.
		description : is the human-readable text to appear on the bill, so the user can easily see what they bought
		currency : is the 3-figure code as per ISO 4217
		amount : (decimal) can be a whole number or decimal
		code : (string) a code provided by the OneAPI implementation that is used to reference an operator price point.
		callbackURL : specifies a URL which will receive a notification when the charge request has completed (as part of an Oauth based flow)
		clientCorrelator : (string) uniquely identifies this create charge request. If there is a communication failure during the charge request, using the same clientCorrelator when retrying the request allows the operator to avoid applying the same charge twice.
		onBehalfOf : (string) allows aggregators/partners to specify the actual payee.
		purchaseCategoryCode : (string) an indication of the content type. Values meaningful to the billing system would be published by a OneAPI implementation.
		channel : (string) can be 'Wap', 'Web', 'SMS', depending on the source of user interaction
		taxAmount : decimal) tax already charged by the merchant.
		serviceId : (string) The ID of the partner/merchant service
		productId : (string) combines with the serviceID to uniquely identify the product being purchased.
		"""
        baseurl = self.endpoints.getAmountChargeEndpoint()
        requestProcessor = JSONRequest()
        formparameters = FormParameters()
        formparameters.put('endUserId', endUserId)
        if '{endUserId}' in baseurl:
            baseurl = baseurl.replace('{endUserId}', str(endUserId))
        formparameters.put('referenceCode', referenceCode)
        formparameters.put('description', description)
        formparameters.put('currency', currency)
        formparameters.put('amount', amount)
        formparameters.put('code', code)
        formparameters.put('callbackURL', callbackURL)
        formparameters.put('clientCorrelator', clientCorrelator)
        formparameters.put('onBehalfOf', onBehalfOf)
        formparameters.put('purchaseCategoryCode', purchaseCategoryCode)
        formparameters.put('channel', channel)
        formparameters.put('taxAmount', taxAmount)
        formparameters.put('serviceId', serviceId)
        formparameters.put('productId', productId)
        postdata = formparameters.encodeParameters()
        rawresponse = requestProcessor.post(baseurl, postdata,
                                            'application/json', self.username,
                                            self.password)
        response = AmountResponse()
        if rawresponse is not None and rawresponse.getContent() is not None:
            jsondata = json.loads(rawresponse.getContent())
            if jsondata is not None and jsondata[
                    'amountTransaction'] is not None:
                response.setAmountTransactionJSON(
                    jsondata['amountTransaction'])
        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
Ejemplo n.º 9
0
	def chargeAmountWithCallback(self,endUserId,transactionId,referenceCode,description,currency,amount,referenceSequence,code,callbackURL,clientCorrelator,onBehalfOf,purchaseCategoryCode,channel,taxAmount,serviceId,productId):
		"""
		chargeAmountWithCallback : charge against the reservation - function variant using Oauth based flow
		Parameters:
		endUserId : is end user ID; either MSISDN including the 'tel:' protocol identifier. OneAPI also supports the Anonymous Customer Reference (ACR) if provided by the operator.
		transactionId : uniquely identifies the reservation transaction - used in maintaining the sequence of transactions
		referenceCode : (string, unique per charge event) is your reference for reconciliation purposes. The operator should include it in reports so that you can match their view of what has been sold with yours by matching the referenceCodes.
		description : is the human-readable text to appear on the bill, so the user can easily see what they bought
		currency : is the 3-figure code as per ISO 4217
		amount : (decimal) can be a whole number or decimal
		referenceSequence : (integer) - this allows the server to distinguish easily between new and repeated requests in the case of a communication failure. For each transaction within a reservation sequence, iterate the referenceSequence by 1
		code : (string) a code provided by the OneAPI implementation that is used to reference an operator price point.
		callbackURL : specifies a URL which will receive a notification when the charge request has completed (as part of an Oauth based flow)
		clientCorrelator : (string) uniquely identifies this create charge request. If there is a communication failure during the charge request, using the same clientCorrelator when retrying the request allows the operator to avoid applying the same charge twice.
		onBehalfOf : (string) allows aggregators/partners to specify the actual payee.
		purchaseCategoryCode : (string) an indication of the content type. Values meaningful to the billing system would be published by a OneAPI implementation.
		channel : (string) can be 'Wap', 'Web', 'SMS', depending on the source of user interaction
		taxAmount : decimal) tax already charged by the merchant.
		serviceId : (string) The ID of the partner/merchant service
		productId : (string) combines with the serviceID to uniquely identify the product being purchased.
		"""
		baseurl=self.endpoints.getAmountReservationChargeEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('endUserId',endUserId)
		if '{endUserId}' in baseurl: baseurl=baseurl.replace('{endUserId}',str(endUserId))
		formparameters.put('transactionId',transactionId)
		if '{transactionId}' in baseurl: baseurl=baseurl.replace('{transactionId}',str(transactionId))
		formparameters.put('referenceCode',referenceCode)
		formparameters.put('description',description)
		formparameters.put('currency',currency)
		formparameters.put('amount',amount)
		formparameters.put('referenceSequence',referenceSequence)
		formparameters.put('code',code)
		formparameters.put('callbackURL',callbackURL)
		formparameters.put('clientCorrelator',clientCorrelator)
		formparameters.put('onBehalfOf',onBehalfOf)
		formparameters.put('purchaseCategoryCode',purchaseCategoryCode)
		formparameters.put('channel',channel)
		formparameters.put('taxAmount',taxAmount)
		formparameters.put('serviceId',serviceId)
		formparameters.put('productId',productId)
		postdata=formparameters.encodeParameters()
		rawresponse=requestProcessor.post(baseurl,postdata,'application/json', self.username, self.password)
		response=AmountReservationResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['amountReservationTransaction'] is not None:
				response.setAmountReservationTransactionJSON(jsondata['amountReservationTransaction'])
		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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
	def cancelDeliveryNotifications(self,subscriptionId):
		"""
		cancelDeliveryNotifications : stop the subscription to delivery notifications
		Parameters:
		subscriptionId : a previously created subscriptionId from the subscribeToDeliveryNotification function
		"""
		baseurl=self.endpoints.getCancelMMSDeliverySubscriptionEndpoint()
		requestProcessor=JSONRequest()
		if '{subscriptionId}' in baseurl: baseurl=baseurl.replace('{subscriptionId}',str(subscriptionId))
		rawresponse=requestProcessor.delete(baseurl,self.username,self.password)
		response=HTTPResponse()
		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
Ejemplo n.º 12
0
	def cancelReceiptNotifications(self,subscriptionId):
		"""
		cancelReceiptNotifications : stop the subscription to MMS message notifications
		Parameters:
		subscriptionId : subscriptionId of a previously created deliveryNotification subscription
		"""
		baseurl=self.endpoints.getCancelMMSReceiptSubscriptionEndpoint()
		requestProcessor=JSONRequest()
		if '{subscriptionId}' in baseurl: baseurl=baseurl.replace('{subscriptionId}',str(subscriptionId))
		rawresponse=requestProcessor.delete(baseurl,self.username,self.password)
		response=HTTPResponse()
		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
Ejemplo n.º 13
0
    def reserveAdditionalAmountSimple(self, endUserId, transactionId,
                                      referenceCode, description, currency,
                                      amount, referenceSequence, code):
        """
		reserveAdditionalAmountSimple : reserve an additional amount
		Parameters:
		endUserId : is end user ID; either MSISDN including the 'tel:' protocol identifier. OneAPI also supports the Anonymous Customer Reference (ACR) if provided by the operator.
		transactionId : uniquely identifies the reservation transaction - used in maintaining the sequence of transactions
		referenceCode : (string, unique per charge event) is your reference for reconciliation purposes. The operator should include it in reports so that you can match their view of what has been sold with yours by matching the referenceCodes.
		description : is the human-readable text to appear on the bill, so the user can easily see what they bought
		currency : is the 3-figure code as per ISO 4217
		amount : (decimal) can be a whole number or decimal
		referenceSequence : (integer) - this allows the server to distinguish easily between new and repeated requests in the case of a communication failure. For each transaction within a reservation sequence, iterate the referenceSequence by 1
		code : (string) a code provided by the OneAPI implementation that is used to reference an operator price point.
		"""
        baseurl = self.endpoints.getAmountReserveAdditionalEndpoint()
        requestProcessor = JSONRequest()
        formparameters = FormParameters()
        formparameters.put('endUserId', endUserId)
        if '{endUserId}' in baseurl:
            baseurl = baseurl.replace('{endUserId}', str(endUserId))
        formparameters.put('transactionId', transactionId)
        if '{transactionId}' in baseurl:
            baseurl = baseurl.replace('{transactionId}', str(transactionId))
        formparameters.put('referenceCode', referenceCode)
        formparameters.put('description', description)
        formparameters.put('currency', currency)
        formparameters.put('amount', amount)
        formparameters.put('referenceSequence', referenceSequence)
        formparameters.put('code', code)
        postdata = formparameters.encodeParameters()
        rawresponse = requestProcessor.post(baseurl, postdata,
                                            'application/json', self.username,
                                            self.password)
        response = AmountReservationResponse()
        if rawresponse is not None and rawresponse.getContent() is not None:
            jsondata = json.loads(rawresponse.getContent())
            if jsondata is not None and jsondata[
                    'amountReservationTransaction'] is not None:
                response.setAmountReservationTransactionJSON(
                    jsondata['amountReservationTransaction'])
        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
Ejemplo n.º 14
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    
Ejemplo n.º 15
0
 def action_sendSMS(self, cr, uid, ids, number, sms, context=None):
     if not number and ids:
         self.write(cr, uid, ids, {'state': 'notsend'})
         return False
     num = 'tel:' + number
     message = sms
     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()
     if '{registration_id}' in baseurl:
         baseurl = baseurl.replace('{registration_id}',
                                   str(registration_id))
     formdata = {
         'message': str(message.encode('utf-8')),
         'address': num,
         'senderAddress': registration_id
     }
     data_encoded = urllib.urlencode(formdata)
     rawresponse = requestProcessor.post(baseurl, data_encoded,
                                         'application/json', username,
                                         password)
     print rawresponse
     if rawresponse is not None and rawresponse.getContent() is not None:
         jsondata = json.loads(rawresponse.getContent())
         if jsondata is not None and jsondata[
                 'resourceReference'] is not None:
             mondict = jsondata['resourceReference']
             monEndpoint = str(mondict['resourceURL'])
             datas = monEndpoint.split('/')
             lgt = len(datas)
             mess_id = datas[lgt - 1]
             if ids:
                 self.write(cr, uid, ids, {'mess_id': mess_id})
     return True
Ejemplo n.º 16
0
    def cancelReceiptNotifications(self, subscriptionId):
        """
		cancelReceiptNotifications : stop the subscription to message notifications
		Parameters:
		subscriptionId : subscriptionId of a previously created receiptNotification subscription
		"""
        baseurl = self.endpoints.getCancelSMSReceiptSubscriptionEndpoint()
        requestProcessor = JSONRequest()
        if '{subscriptionId}' in baseurl:
            baseurl = baseurl.replace('{subscriptionId}', str(subscriptionId))
        rawresponse = requestProcessor.delete(baseurl, self.username,
                                              self.password)
        response = HTTPResponse()
        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
Ejemplo n.º 17
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
Ejemplo n.º 18
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
Ejemplo n.º 19
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
Ejemplo n.º 20
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
Ejemplo n.º 21
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
Ejemplo n.º 22
0
    def subscribeToReceiptNotifications(self, destinationAddress, notifyURL,
                                        criteria, notificationFormat,
                                        clientCorrelator, callbackData):
        """
		subscribeToReceiptNotifications : subscribe to notifications of MMS messages sent to your application
		Parameters:
		destinationAddress : the MSISDN, or code agreed with the operator, to which people may send an MMS to your application
		notifyURL : (URL) is your address to which notifications will be sent
		criteria : (string) is case-insensitve text to match against the first word of the message, ignoring any leading whitespace. This allows you to reuse a short code among various applications, each of which can register their own subscription with different criteria.
		notificationFormat : is the content type that notifications will be sent in - for OneAPI v1.0 only JSON is supported.
		clientCorrelator : (string) uniquely identifies this create subscription request. If there is a communication failure during the request, using the same clientCorrelator when retrying the request allows the operator to avoid creating a duplicate subscription.
		callbackData : (string) is a function name or other data that you would like included when the POST is received.
		"""
        baseurl = self.endpoints.getMMSReceiptSubscriptionsEndpoint()
        requestProcessor = JSONRequest()
        formparameters = FormParameters()
        formparameters.put('destinationAddress', destinationAddress)
        formparameters.put('notifyURL', notifyURL)
        formparameters.put('criteria', criteria)
        formparameters.put('notificationFormat', notificationFormat)
        formparameters.put('clientCorrelator', clientCorrelator)
        formparameters.put('callbackData', callbackData)
        postdata = formparameters.encodeParameters()
        rawresponse = requestProcessor.post(baseurl, postdata,
                                            'application/json', self.username,
                                            self.password)
        response = MMSMessageReceiptSubscriptionResponse()
        if rawresponse is not None and rawresponse.getContent() is not None:
            jsondata = json.loads(rawresponse.getContent())
            if jsondata is not None and jsondata[
                    'resourceReference'] is not None:
                response.setResourceReferenceJSON(
                    jsondata['resourceReference'])
        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
Ejemplo n.º 23
0
    def releaseReservation(self, endUserId, transactionId, referenceCode,
                           referenceSequence):
        """
		releaseReservation : release the reservation
		Parameters:
		endUserId : is end user ID; either MSISDN including the 'tel:' protocol identifier. OneAPI also supports the Anonymous Customer Reference (ACR) if provided by the operator.
		transactionId : uniquely identifies the reservation transaction - used in maintaining the sequence of transactions
		referenceCode : (string, unique per charge event) is your reference for reconciliation purposes. The operator should include it in reports so that you can match their view of what has been sold with yours by matching the referenceCodes.
		referenceSequence : (integer) - this allows the server to distinguish easily between new and repeated requests in the case of a communication failure. For each transaction within a reservation sequence, iterate the referenceSequence by 1
		"""
        baseurl = self.endpoints.getAmountReservationReleaseEndpoint()
        requestProcessor = JSONRequest()
        formparameters = FormParameters()
        formparameters.put('endUserId', endUserId)
        if '{endUserId}' in baseurl:
            baseurl = baseurl.replace('{endUserId}', str(endUserId))
        formparameters.put('transactionId', transactionId)
        if '{transactionId}' in baseurl:
            baseurl = baseurl.replace('{transactionId}', str(transactionId))
        formparameters.put('referenceCode', referenceCode)
        formparameters.put('referenceSequence', referenceSequence)
        postdata = formparameters.encodeParameters()
        rawresponse = requestProcessor.post(baseurl, postdata,
                                            'application/json', self.username,
                                            self.password)
        response = AmountReservationResponse()
        if rawresponse is not None and rawresponse.getContent() is not None:
            jsondata = json.loads(rawresponse.getContent())
            if jsondata is not None and jsondata[
                    'amountReservationTransaction'] is not None:
                response.setAmountReservationTransactionJSON(
                    jsondata['amountReservationTransaction'])
        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
Ejemplo n.º 24
0
	def reserveAdditionalAmountSimple(self,endUserId,transactionId,referenceCode,description,currency,amount,referenceSequence,code):
		"""
		reserveAdditionalAmountSimple : reserve an additional amount
		Parameters:
		endUserId : is end user ID; either MSISDN including the 'tel:' protocol identifier. OneAPI also supports the Anonymous Customer Reference (ACR) if provided by the operator.
		transactionId : uniquely identifies the reservation transaction - used in maintaining the sequence of transactions
		referenceCode : (string, unique per charge event) is your reference for reconciliation purposes. The operator should include it in reports so that you can match their view of what has been sold with yours by matching the referenceCodes.
		description : is the human-readable text to appear on the bill, so the user can easily see what they bought
		currency : is the 3-figure code as per ISO 4217
		amount : (decimal) can be a whole number or decimal
		referenceSequence : (integer) - this allows the server to distinguish easily between new and repeated requests in the case of a communication failure. For each transaction within a reservation sequence, iterate the referenceSequence by 1
		code : (string) a code provided by the OneAPI implementation that is used to reference an operator price point.
		"""
		baseurl=self.endpoints.getAmountReserveAdditionalEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('endUserId',endUserId)
		if '{endUserId}' in baseurl: baseurl=baseurl.replace('{endUserId}',str(endUserId))
		formparameters.put('transactionId',transactionId)
		if '{transactionId}' in baseurl: baseurl=baseurl.replace('{transactionId}',str(transactionId))
		formparameters.put('referenceCode',referenceCode)
		formparameters.put('description',description)
		formparameters.put('currency',currency)
		formparameters.put('amount',amount)
		formparameters.put('referenceSequence',referenceSequence)
		formparameters.put('code',code)
		postdata=formparameters.encodeParameters()
		rawresponse=requestProcessor.post(baseurl,postdata,'application/json', self.username, self.password)
		response=AmountReservationResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['amountReservationTransaction'] is not None:
				response.setAmountReservationTransactionJSON(jsondata['amountReservationTransaction'])
		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
Ejemplo n.º 25
0
	def sendSMS(self,senderAddress,address,message,clientCorrelator,notifyURL,senderName,callbackData):
		"""
		sendSMS : Send an SMS from your Web application
		Parameters:
		senderAddress : MSISDN or allocated code of the sender
		address : MSISDN or ACR of the mobile terminal to send to
		message : text part of the message to send to the recipient(s) - long messages may be split by the OneAPI server
		clientCorrelator : (string) uniquely identifies this create SMS request. If there is a communication failure during the request, using the same clientCorrelator when retrying the request allows the operator to avoid sending the same SMS twice.
		notifyURL : (anyURI) is the URL-escaped URL to which you would like a notification of delivery sent.
		senderName : (string) is the URL-escaped name of the sender to appear on the terminal is the address to  whom a responding SMS may be sent
		callbackData : (string) will be passed back in this notification, so you can use it to identify the message the receipt relates to (or any other useful data, such as a function name)
		"""
		baseurl=self.endpoints.getSendSMSEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('senderAddress',senderAddress)
		if '{senderAddress}' in baseurl: baseurl=baseurl.replace('{senderAddress}',str(senderAddress))
		if address is not None:
			for item in address:
				formparameters.put('address',item)
		formparameters.put('message',message)
		formparameters.put('clientCorrelator',clientCorrelator)
		formparameters.put('notifyURL',notifyURL)
		formparameters.put('senderName',senderName)
		formparameters.put('callbackData',callbackData)
		postdata=formparameters.encodeParameters()
		rawresponse=requestProcessor.post(baseurl,postdata,'application/json', self.username, self.password)
		response=SendSMSResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['resourceReference'] is not None:
				response.setResourceReferenceJSON(jsondata['resourceReference'])
		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
Ejemplo n.º 26
0
	def sendMMS(self,senderAddress,address,message,attachments,clientCorrelator,notifyURL,senderName,callbackData):
		"""
		sendMMS : Send an SMS from your Web application
		Parameters:
		senderAddress : MSISDN or allocated code of the sender
		address : MSISDN or ACR of the mobile terminal to send to
		message : text part of the message to send to the recipient(s)
		attachments : file attachments (see the Attachments class) to send as part of the MMS
		clientCorrelator : (string) uniquely identifies this create MMS request. If there is a communication failure during the request, using the same clientCorrelator when retrying the request allows the operator to avoid sending the same MMS twice.
		notifyURL : (anyURI) is the URL-escaped URL to which you would like a notification of delivery sent. The format of this notification is shown below.
		senderName : (string) is the name to appear on the user's terminal as the sender of the message.
		callbackData : (string) is any meaningful data you woul like send back in the notification, for example to identify the message or pass a function name, etc.
		"""
		baseurl=self.endpoints.getSendMMSEndpoint()
		requestProcessor=JSONRequest()
		formparameters=FormParameters()
		formparameters.put('senderAddress',senderAddress)
		if '{senderAddress}' in baseurl: baseurl=baseurl.replace('{senderAddress}',str(senderAddress))
		if address is not None:
			for item in address:
				formparameters.put('address',item)
		formparameters.put('message',message)
		formparameters.put('clientCorrelator',clientCorrelator)
		formparameters.put('notifyURL',notifyURL)
		formparameters.put('senderName',senderName)
		formparameters.put('callbackData',callbackData)
		postdata=formparameters.encodeParameters()
		outer=MIMEMultipart()
		jsonpart=MIMEBase('application', 'x-www-form-urlencoded')
		jsonpart.set_payload(postdata)
		jsonpart.add_header('Content-Disposition', 'form-data; name="root-fields"')
		outer.attach(jsonpart)
		if attachments is not None:
			for item in attachments:
				if item is not None:
					attachmentName=item.getName()
					attachmentContentType=item.getContentType()
					attachmentData=item.getData()
					if attachmentData is not None:
						if attachmentContentType is not None:
							maintype, subtype = attachmentContentType.split('/', 1)
							msga = MIMEBase(maintype, subtype)
						else:
							msga = MIMEBase('application','octet-stream')
						msga.set_payload(base64.b64encode(attachmentData))
						msga.add_header('Content-Disposition', 'form-data', name='attachments', filename=attachmentName)
						msga.add_header('Content-Transfer-Encoding', 'base64')
						outer.attach(msga)
		payload=outer.as_string(False)
		boundary=outer.get_boundary()
		trimmed=re.sub('Content-Type: multipart/mixed\\; [A-Za-z0-9\\=\\"]*','',payload)
		reformatted=trimmed.replace('\r\n','\n').replace('\n','\r\n')
		rawresponse=requestProcessor.postMultipart(baseurl,reformatted,'application/json', self.username, self.password, boundary)
		response=SendMMSResponse()
		if rawresponse is not None and rawresponse.getContent() is not None:
			jsondata=json.loads(rawresponse.getContent())
			if jsondata is not None and jsondata['resourceReference'] is not None:
				response.setResourceReferenceJSON(jsondata['resourceReference'])
		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
Ejemplo n.º 27
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