コード例 #1
0
    def updateCampaign(afterUpdatepayload,
                       campaignType=['LIVE', 'ORG'],
                       campaignId=None,
                       process='update'):
        beforeUpdateResponse, beforeUpdatePayload = {}, {}
        if campaignId == None:
            beforeUpdateResponse, beforeUpdatePayload = campaigns.createCampaign(
                {'name': 'IRIS_UPDATE_CAMPAIGN' + str(int(time.time()))},
                campaignTypeParams=campaignType)
            campaignId = beforeUpdateResponse['json']['entity']['campaignId']
            Logger.log('CampaignId Recieved : {} for campaignType : {}'.format(
                campaignId, campaignType))

        updateCampaignConstructedEndPoint = construct.constructUrl(
            'updateCampaign').replace('{campaignId}', str(campaignId))
        afterUpdateresponse = Utils.makeRequest(
            url=updateCampaignConstructedEndPoint,
            data=afterUpdatepayload,
            auth=construct.constructAuthenticate(),
            headers=construct.constructHeaders(),
            method='PUT')
        if afterUpdateresponse.status_code == 200:
            beforeUpdatePayload.update(afterUpdatepayload)
            constant.campaignDefaultValues[campaignType[0]][
                campaignType[1]]['Value'].update(
                    {'payload': beforeUpdatePayload})

        return construct.constructResponse(
            afterUpdateresponse
        ), beforeUpdateResponse, afterUpdatepayload, beforeUpdatePayload
コード例 #2
0
ファイル: list.py プロジェクト: anupsl/pyApps
    def addRecipient(payloadData,
                     campaignId,
                     listId,
                     userType='mobile',
                     numberOfUsers=1,
                     numberOfCustomTags=0,
                     process='update',
                     newUser=True):
        campaignList.updateRechabilityBeforeEachRun()
        addRecipientConstructedEndPoint = construct.constructUrl(
            'addrecipient').replace('{campaignId}', str(campaignId)).replace(
                '{listId}', str(listId))

        payload = {}
        if len(payloadData) == 0:
            Logger.log(
                'Constructing Payload for userType {}, for numberOfusers {} and customCount {}'
                .format(userType, numberOfUsers, numberOfCustomTags))
            if newUser == True:
                payload = construct.constructAddRecipientPayload(
                    userType, numberOfUsers, numberOfCustomTags)
            else:
                payload = construct.constructAddRecipientPayloadForOldUsers(
                    userType, numberOfUsers, numberOfCustomTags)
        else:
            Logger.log('Constructing Payload as a Generic Way :', payloadData)
            payload = construct.constructBody(payloadData, process,
                                              'addrecipient')

        response = Utils.makeRequest(url=addRecipientConstructedEndPoint,
                                     data=payload,
                                     auth=construct.constructAuthenticate(),
                                     headers=construct.constructHeaders(),
                                     method='POST')
        return construct.constructResponse(response), payload
コード例 #3
0
ファイル: authorize.py プロジェクト: anupsl/pyApps
 def makeAuthorizeRequest(campaignId, messageId):
     authorizeConstructedEndPoint = construct.constructUrl(
         'authorize').replace('{campaignId}', str(campaignId)).replace(
             '{messageId}', str(messageId))
     response = Utils.makeRequest(url=authorizeConstructedEndPoint,
                                  data='',
                                  auth=construct.constructAuthenticate(),
                                  headers=construct.constructHeaders(),
                                  method='POST')
     return construct.constructResponse(response)
コード例 #4
0
ファイル: list.py プロジェクト: anupsl/pyApps
    def mergeList(payloadData={},
                  campaignId=None,
                  campaignType=['LIVE', 'ORG', 'List', 'TAGS', 0],
                  userType='mobile',
                  numberOfUsers=1,
                  numberOfCustomTags=0,
                  newUser=True,
                  process='update'):
        campaignList.updateRechabilityBeforeEachRun()
        campaignDefault = constant.campaignDefaultValues
        if campaignId == None:
            campaignIdValue = constant.campaignDefaultValues[campaignType[0]][
                campaignType[1]]['Value']
            if len(campaignIdValue['response']) == 0 and len(
                    campaignIdValue['payload']) == 0:
                response, payload = campaigns.createCampaign(
                    {}, campaignTypeParams=[campaignType[0], campaignType[1]])
                if response['statusCode'] == 200:
                    campaignId = response['json']['entity']['campaignId']
                else:
                    Assertion.constructAssertion(
                        False,
                        'Error : While Creating Campaign , Status Code : {}'.
                        format(response['statusCode']))
            else:
                campaignId = campaignIdValue['response']['json']['entity'][
                    'campaignId']

        Logger.log('CamapaignId getting used to create list :', campaignId)

        createListConstructedEndPoint = construct.constructUrl(
            'mergelist').replace('{campaignId}', str(campaignId))
        payload = {}
        if len(payloadData) == 0:
            payload = construct.constructMergeListBody(userType, numberOfUsers,
                                                       numberOfCustomTags,
                                                       newUser)
        else:
            payload = construct.constructBody(payloadData, process,
                                              'mergelist')

        response = Utils.makeRequest(url=createListConstructedEndPoint,
                                     data=payload,
                                     auth=construct.constructAuthenticate(),
                                     headers=construct.constructHeaders(),
                                     method='POST')
        return construct.constructResponse(response), payload, campaignId
コード例 #5
0
 def getCampaignById(campaignId=None, queryParam=[]):
     getCampaignConstructedEndPoint = None
     if len(queryParam) > 0:
         getCampaignConstructedEndPoint = construct.constructUrl(
             'getCampaign',
             queryParam=queryParam).replace('{campaignId}', '')
     else:
         Assertion.constructAssertion(
             campaignId != None, 'CampaignId and Query param both are None')
         getCampaignConstructedEndPoint = construct.constructUrl(
             'getCampaign').replace('{campaignId}', str(campaignId))
     response = Utils.makeRequest(url=getCampaignConstructedEndPoint,
                                  data='',
                                  auth=construct.constructAuthenticate(),
                                  headers=construct.constructHeaders(),
                                  method='GET')
     return construct.constructResponse(response)
コード例 #6
0
    def createCampaign(payloadData={},
                       process='update',
                       campaignTypeParams=[]):
        if len(campaignTypeParams) != 0:
            campaign = constant.campaignDefaultValues
            response, Payload = {}, {}
            for eachType in campaignTypeParams:
                campaign = campaign[eachType]

            if len(campaign['Value']['response']) == 0 or len(
                    campaign['Value']['payload']) == 0:
                if campaignTypeParams[0] == 'LIVE':
                    response, Payload = campaigns.createCampaign({
                        'name':
                        'IRIS_' + str(int(time.time() * 1000000)),
                        'testControl': {
                            'type': campaignTypeParams[1],
                            'test': 90
                        },
                        'goalId':
                        str(constant.irisGenericValues['goalId']),
                        'objectiveId':
                        str(constant.irisGenericValues['objectiveId'])
                    })
                elif campaignTypeParams[0] == 'UPCOMING':
                    response, Payload = campaigns.createCampaign({
                        'name':
                        'IRIS_' + str(int(time.time() * 1000000)),
                        'testControl': {
                            'type': campaignTypeParams[1],
                            'test': 90
                        },
                        'goalId':
                        str(constant.irisGenericValues['goalId']),
                        'objectiveId':
                        str(constant.irisGenericValues['objectiveId']),
                        'startDate':
                        int(time.time() * 1000 + 24 * 60 * 60 * 1000),
                        'endDate':
                        int(time.time() * 1000 + 24 * 60 * 60 * 2000)
                    })
                elif campaignTypeParams[0] == 'LAPSED':
                    response, Payload = campaigns.createCampaign({
                        'name':
                        'IRIS_' + str(int(time.time() * 1000000)),
                        'testControl': {
                            'type': campaignTypeParams[1],
                            'test': 90
                        },
                        'goalId':
                        str(constant.irisGenericValues['goalId']),
                        'objectiveId':
                        str(constant.irisGenericValues['objectiveId']),
                        'startDate':
                        int(time.time() * 1000),
                        'endDate':
                        int(time.time() * 1000 + 5 * 1000)
                    })
                    time.sleep(6)  # Campaign Created will lapsed in 6 seconds
                Logger.log(
                    'Default Value Found -1 and CampaignCreated of type :{} with response :{}'
                    .format(campaignTypeParams, response))
                constant.campaignDefaultValues[campaignTypeParams[0]][
                    campaignTypeParams[1]]['Value'].update({
                        'response': response,
                        'payload': Payload
                    })
                return response, Payload
            else:
                Logger.log(
                    'Returning Campaign Id Directly From Saved Json as :',
                    campaign['Value'])
                return campaign['Value']['response'], campaign['Value'][
                    'payload']
        else:
            createCampaignConstructedEndPoint = construct.constructUrl(
                'createcampaign')
            payload = construct.constructBody(payloadData, process,
                                              'createcampaign')
            response = Utils.makeRequest(
                url=createCampaignConstructedEndPoint,
                data=payload,
                auth=construct.constructAuthenticate(),
                headers=construct.constructHeaders(),
                method='POST')
            return construct.constructResponse(response), payload
コード例 #7
0
ファイル: coupons.py プロジェクト: anupsl/pyApps
    def createCoupons(payloadData={},
                      campaignId=None,
                      campaignType=[],
                      process='update',
                      key=True,
                      timeout=5.0):
        updateDefault = False
        if campaignId == None:
            if len(campaignType) == 0:
                response, payload = campaigns.createCampaign({
                    'name':
                    'IRIS_COUPON' + randValues.randomString(5) +
                    str(int(time.time() * 100000)),
                    'goalId':
                    constant.irisGenericValues['goalId'],
                    'objectiveId':
                    constant.irisGenericValues['objectiveId']
                })
            else:
                response, payload = campaigns.createCampaign(
                    {}, campaignTypeParams=[campaignType[0], campaignType[1]])
                updateDefault = True

            if response['statusCode'] == 200:
                campaignId = response['json']['entity']['campaignId']
            else:
                Assertion.constructAssertion(
                    False,
                    'Error : While Creating Campaign , Status Code : {}'.
                    format(response['statusCode']))

        Logger.log('CampaignId getting used to create list :', campaignId)

        if key:
            createCouponConstructedEndPoint = construct.constructUrl(
                'createcoupon')
            payload = construct.constructBody(payloadData, process,
                                              'createcoupon')
            payload.update({'campaignId': campaignId})
            try:
                response = Utils.makeRequest(
                    url=createCouponConstructedEndPoint,
                    data=payload,
                    auth=construct.constructAuthenticate(),
                    headers=construct.constructHeaders(),
                    method='POST')
                if updateDefault:
                    constant.campaignDefaultValues[campaignType[0]][
                        campaignType[1]]['Coupon'].update({
                            'response': response,
                            'payload': payload
                        })
            except:
                return {}, payload, campaignId

            return construct.constructResponse(response), payload, campaignId
        else:
            couponResponse = constant.campaignDefaultValues[campaignType[0]][
                campaignType[1]]['Coupon']['response']
            couponPayload = constant.campaignDefaultValues[campaignType[0]][
                campaignType[1]]['Coupon']['payload']

            if len(couponResponse) == 0 or len(couponPayload) == 0:
                coupons.createCoupons(payloadData,
                                      campaignId,
                                      campaignType,
                                      process,
                                      key=True)
            else:
                return couponResponse, couponPayload, campaignId
コード例 #8
0
ファイル: message.py プロジェクト: anupsl/pyApps
    def replyMessage(self):
        getReplyMessasgeListConstructedEndPoint = construct.constructUrl('getreplymessagelist').format(str(self.campaignId))
        skippedErrorIds = []
        response = Utils.makeRequest(url=getReplyMessasgeListConstructedEndPoint, data='', auth=construct.constructAuthenticate(), headers=construct.constructHeaders(), method='GET')
        responseEntity = construct.constructResponse(response)['json']['entity']
        for error in responseEntity:
            messageId = error['messageId']
            if self.commDetailsId == messageId:
                for errorDetails in error['errorDetails']:
                    skippedErrorIds.append(errorDetails['errorId'])
                    Logger.log('Error Details Id: {}, Description: {}, Count: {}: '.format(errorDetails['errorId'],errorDetails['errorDescription'],errorDetails['errorCount']))

                replyMessasgeConstructedEndPoint = construct.constructUrl('replymessage').format(str(self.campaignId), str(messageId))
                payloadData = {'skippedErrors' : skippedErrorIds}
                response = Utils.makeRequest(url=replyMessasgeConstructedEndPoint, data=payloadData, auth=construct.constructAuthenticate(), headers=construct.constructHeaders(), method='POST')
                Logger.log('Response of MessageId {} Replied and Response : {}'.format(messageId, construct.constructResponse(response)))
        return construct.constructResponse(response)
コード例 #9
0
ファイル: message.py プロジェクト: anupsl/pyApps
    def createMessage(self, payloadData={}, messageInfo=['SMS', ['IMMEDIATE'], ['PLAIN'], True], process='update'):
        Logger.log('Create Message Call with payloadDate :{} , messageInfo :{} and process :{}'.format(payloadData, messageInfo, process))
        createMessasgeConstructedEndPoint = construct.constructUrl('createmessage').replace('{campaignId}', str(self.campaignId))
        if 'COUPONS' in messageInfo[2]: 
            Logger.log('Incentive is Coupons so Updating VoucherId in Incentive List as', self.voucherId)
            messageInfo[2].append(self.voucherId)
        
        if len(payloadData) == 0:
            Logger.log('Creating Body for Type :{} and Schedulle Type :{} with Incentive Type :{} taking sender Details as :{}'.format(messageInfo[0], messageInfo[1], messageInfo[2], messageInfo[3]))
            payloadData = construct.constructCreateMessageBody(self.listId, messageInfo[0], messageInfo[1], messageInfo[2], messageInfo[3])
        else:
            payloadData.update({'listId':self.listId})
            Logger.log('payloadData updating is :', payloadData)
            payloadData = construct.constructBody(payloadData, process, 'createmessage')
            if payloadData['channel'].lower() == 'wechat':
                if 'senderDetails' in payloadData :payloadData.pop('senderDetails')
                if 'additionalInfo' in payloadData :payloadData.pop('additionalInfo')
                if not isinstance(payloadData['message'], dict):payloadData.pop('message')

        response = Utils.makeRequest(url=createMessasgeConstructedEndPoint, data=payloadData, auth=construct.constructAuthenticate(), headers=construct.constructHeaders(), method='POST')
        return construct.constructResponse(response), payloadData    
コード例 #10
0
ファイル: list.py プロジェクト: anupsl/pyApps
    def createList(payloadData={},
                   campaignId=None,
                   campaignType=['LIVE', 'ORG', 'List', 'TAGS', 0],
                   process='update',
                   key=True):
        campaignDefault = constant.campaignDefaultValues
        if campaignId == None:
            campaignIdValue = constant.campaignDefaultValues[campaignType[0]][
                campaignType[1]]['Value']
            if len(campaignIdValue['response']) == 0 and len(
                    campaignIdValue['payload']) == 0:
                response, payload = campaigns.createCampaign(
                    {}, campaignTypeParams=[campaignType[0], campaignType[1]])
                if response['statusCode'] == 200:
                    campaignId = response['json']['entity']['campaignId']
                else:
                    Assertion.constructAssertion(
                        False,
                        'Error : While Creating Campaign , Status Code : {}'.
                        format(response['statusCode']))
            else:
                campaignId = campaignIdValue['response']['json']['entity'][
                    'campaignId']

        Logger.log('CamapaignId getting used to create list :', campaignId)
        if key:
            createListConstructedEndPoint = construct.constructUrl(
                'createlist').replace('{campaignId}', str(campaignId))
            payload = construct.constructBody(payloadData, process,
                                              'createlist')
            response = Utils.makeRequest(
                url=createListConstructedEndPoint,
                data=payload,
                auth=construct.constructAuthenticate(),
                headers=construct.constructHeaders(),
                method='POST')
            if response.status_code == 200:
                Logger.log(
                    'Updating campaignDefaultValues as Status Code is 200')
                constant.campaignDefaultValues[campaignType[0]][
                    campaignType[1]][campaignType[2]][campaignType[3]][
                        campaignType[4]].update({
                            'response':
                            construct.constructResponse(response),
                            'payload':
                            payload,
                            'campaignId':
                            campaignId
                        })
            return construct.constructResponse(response), payload, campaignId
        else:
            listIdValue = constant.campaignDefaultValues[campaignType[0]][
                campaignType[1]][campaignType[2]][campaignType[3]]

            if len(listIdValue['response']) == 0 or len(
                    listIdValue['payload']) == 0:
                response, payload, campaignId = campaignList.createList(
                    payloadData, campaignId, campaignType, process, key=True)
                listIdValue['response'].update({'response': response})
                listIdValue['payload'].update({'payload': response})
                listIdValue.update({'campaignId': campaignId})
                return response, payload, campaignId
            else:
                return listIdValue['response'], listIdValue[
                    'payload'], listIdValue['campaignId']