Beispiel #1
0
 public HttpResponseMessage UpdateGeoTargets(string campaignId, UpdateGeoTargetsRequest updateGeoTargetsRequest)
 {
     try
     {
         CampaignControllerPut    put            = new CampaignControllerPut();
         UpdateGeoTargetsResponse updatedTargets = put.UpdateCampaignGeoTargets(campaignId, updateGeoTargetsRequest);
         return(ResponseHelper.CreateResponse(Request, HttpStatusCode.OK, updatedTargets, PublicApiCommonErrorCode.SUCCESS));
     }
     catch (Exception e)
     {
         return(ResponseHelper.CreateResponse(Request, HttpStatusCode.NotFound, e.Message + " " + e.InnerException + " " + e.StackTrace, PublicApiCommonErrorCode.NOT_FOUND));
     }
 }
Beispiel #2
0
        public UpdateGeoTargetsResponse UpdateCampaignGeoTargets(string campaignId, UpdateGeoTargetsRequest updateGeoTargetsRequest)
        {
            UpdateGeoTargetsResponse updateResponse = new UpdateGeoTargetsResponse()
            {
                Success = true
            };

            Operator action = Operator.ADD;

            if (updateGeoTargetsRequest.UpdateMode == UpdateMode.Remove)
            {
                action = Operator.REMOVE;
            }

            List <KeyValuePair <string, string> > pairs = ExtractCityStatePairsFromRequets(updateGeoTargetsRequest);

            CampaignCriterionService campaignCriterionService = (CampaignCriterionService)_adwordsUser.GetService(AdWordsService.v201708.CampaignCriterionService);

            List <GeoTarget> targets = _locationNameHelper.GetTargetIdsByLocationNames(pairs);

            List <CampaignCriterionOperation> operations = new List <CampaignCriterionOperation>();

            foreach (GeoTarget target in targets)
            {
                Location location = new Location()
                {
                    id = Convert.ToInt64(target.Id)
                };
                CampaignCriterionOperation operation         = new CampaignCriterionOperation();
                CampaignCriterion          campaignCriterion = new CampaignCriterion();
                campaignCriterion.campaignId            = Convert.ToInt64(campaignId);
                campaignCriterion.criterion             = location;
                campaignCriterion.CampaignCriterionType = "Location";
                operation.operand   = campaignCriterion;
                operation.@operator = action;
                operations.Add(operation);
            }

            try
            {
                CampaignCriterionReturnValue result = campaignCriterionService.mutate(operations.ToArray());
            }
            catch (Exception ex)
            {
                var exception = ex.Message;
                updateResponse.Success = false;
            }

            return(updateResponse);
        }
Beispiel #3
0
        public void UpdateGeoTargetsPut_RemoveTarget()
        {
            CampaignControllerPut controller = new CampaignControllerPut();
            List <GeoLocation>    list       = new List <GeoLocation>();

            list.Add(new GeoLocation()
            {
                City = "Miami", State = "Florida"
            });
            UpdateGeoTargetsRequest request = new UpdateGeoTargetsRequest()
            {
                GeoLocation = list,
                UpdateMode  = UpdateMode.Remove
            };

            UpdateGeoTargetsResponse response = controller.UpdateCampaignGeoTargets("927060915", request);

            Assert.That(response.Success, Is.True);
        }
Beispiel #4
0
        public void UpdateGeoTargetsPut_EmptyGeoLocationList()
        {
            CampaignControllerPut   controller = new CampaignControllerPut();
            List <GeoLocation>      list       = new List <GeoLocation>();
            UpdateGeoTargetsRequest request    = new UpdateGeoTargetsRequest()
            {
                GeoLocation = list,
                UpdateMode  = UpdateMode.Remove
            };

            try
            {
                UpdateGeoTargetsResponse response = controller.UpdateCampaignGeoTargets("927060915", request);
                Assert.That(false);
            }
            catch (Exception e)
            {
                Assert.That(e.Message, Is.Not.Empty);
            }
        }