Пример #1
0
 private static ProDataResponse Create(ProDataRequest request)
 {
     using (HttpClient client = new HttpClient())
     {
         client.Timeout = TimeSpan.FromMinutes(1);
         client.DefaultRequestHeaders.Add("X-ProDataFeed-Auth", _prodataAuth);
         var httpContent = new StringContent(request.ToJson(), Encoding.UTF8, "application/json");
         using (HttpResponseMessage response = client.PostAsync(_urlCreateOrder, httpContent).Result)
             using (HttpContent content = response.Content)
             {
                 string          responseContent = content.ReadAsStringAsync().Result;
                 ProDataResponse proDataResponse;
                 try
                 {
                     proDataResponse = JsonConvert.DeserializeObject <ProDataResponse>(responseContent);
                     proDataResponse.RequestMessage = request.ToString();
                 }
                 catch (Exception ex)
                 {
                     throw new AdsException("There is error in parsing data from ProData. Problem in ProData API.");
                 }
                 return(proDataResponse);
             }
     }
 }
Пример #2
0
        public static ProDataResponse Create(Campaign campaign, CampaignSegment segment, string whiteLabelDomain)
        {
            string orderNumber = segment != null ? $"ADS{segment.SegmentNumber}" :
                                 (campaign.ReBroadcasted ? $"ADS{campaign.ReBroadcastedOrderNumber}" : $"ADS{campaign.OrderNumber}");

            double ctrPercent = campaign.Approved.OpenGoals == 0 ? 0 :
                                (double)campaign.Approved.ClickGoals / campaign.Approved.OpenGoals;

            if (ctrPercent > 1.0)
            {
                ctrPercent = ctrPercent / 100.0;
            }

            ProDataRequest request = new ProDataRequest()
            {
                io             = orderNumber,
                campaign_name  = campaign.Approved.CampaignName,
                is_rebroadcast = campaign.Approved.ReBroadCast ? "Y" : "N",
                white_label    = whiteLabelDomain,
                creative_url   = campaign.Assets.CreativeUrl,
                quantity       = campaign.Approved.Quantity,
                geo_type       = "POSTALCODE",
                geo_url        = campaign.Assets.ZipCodeUrl,
                open_percent   = (double)campaign.Approved.OpenGoals / campaign.Approved.Quantity,
                ctr_percent    = ctrPercent,
                subject        = campaign.Approved.SubjectLine,
                from_name      = campaign.Approved.FromLine,
                from_email     = campaign.RepresentativeEmail,
                deploy_date    = campaign.Approved.DeployDate?.ToString(StringConstants.DateTimeFormatDashes),
            };

            if (campaign.Approved.IsOpenPixel)
            {
                request.is_open_pixel = "Y";
                request.open_pixel    = campaign.Approved.OpenPixelUrl;
            }
            else
            {
                request.is_open_pixel = "N";
            }


            if (!string.IsNullOrEmpty(segment?.SegmentDataFileUrl))
            {
                request.is_data_file  = "Y";
                request.data_file_url = segment.SegmentDataFileUrl;
                request.data_file_replacement_param  = segment.SegmentNumber;
                request.data_file_replacement_column = "0";
                request.data_file_unique_ip          = "Y";
            }
            else
            {
                request.is_data_file = "N";
            }

            return(Create(request));
        }