예제 #1
0
        /// <summary>
        /// Generate an Ad Exchange report based on the saved report ID sent in the query parameters.
        /// Documentation https://developers.google.com/adexchangeseller/v1/reference/saved/generate
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AdExchangeSeller service.</param>
        /// <param name="savedReportId">The saved report to retrieve.</param>
        /// <param name="optional">Optional paramaters.</param>        /// <returns>ReportResponse</returns>
        public static Report Generate(AdExchangeSellerService service, string savedReportId, SavedGenerateOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (savedReportId == null)
                {
                    throw new ArgumentNullException(savedReportId);
                }

                // Building the initial request.
                var request = service.Saved.Generate(savedReportId);

                // Applying optional parameters to the request.
                request = (SavedResource.GenerateRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Saved.Generate failed.", ex);
            }
        }
예제 #2
0
        /// <summary>
        /// List the alerts for this Ad Exchange account.
        /// Documentation https://developers.google.com/adexchangeseller/v2.0/reference/alerts/list
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AdExchangeSeller service.</param>
        /// <param name="accountId">Account owning the alerts.</param>
        /// <param name="optional">Optional paramaters.</param>        /// <returns>AlertsResponse</returns>
        public static Alerts List(AdExchangeSellerService service, string accountId, AlertsListOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (accountId == null)
                {
                    throw new ArgumentNullException(accountId);
                }

                // Building the initial request.
                var request = service.Alerts.List(accountId);

                // Applying optional parameters to the request.
                request = (AlertsResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Alerts.List failed.", ex);
            }
        }
        /// <summary>
        /// Get information about the selected Ad Exchange Preferred Deal.
        /// Documentation https://developers.google.com/adexchangeseller/v2.0/reference/preferreddeals/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AdExchangeSeller service.</param>
        /// <param name="accountId">Account owning the deal.</param>
        /// <param name="dealId">Preferred deal to get information about.</param>
        /// <returns>PreferredDealResponse</returns>
        public static PreferredDeal Get(AdExchangeSellerService service, string accountId, string dealId)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (accountId == null)
                {
                    throw new ArgumentNullException(accountId);
                }
                if (dealId == null)
                {
                    throw new ArgumentNullException(dealId);
                }

                // Make the request.
                return(service.Preferreddeals.Get(accountId, dealId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Preferreddeals.Get failed.", ex);
            }
        }
예제 #4
0
        /// <summary>
        /// Get the specified custom channel from the specified ad client.
        /// Documentation https://developers.google.com/adexchangeseller/v2.0/reference/customchannels/get
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AdExchangeSeller service.</param>
        /// <param name="accountId">Account to which the ad client belongs.</param>
        /// <param name="adClientId">Ad client which contains the custom channel.</param>
        /// <param name="customChannelId">Custom channel to retrieve.</param>
        /// <returns>CustomChannelResponse</returns>
        public static CustomChannel Get(AdExchangeSellerService service, string accountId, string adClientId, string customChannelId)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (accountId == null)
                {
                    throw new ArgumentNullException(accountId);
                }
                if (adClientId == null)
                {
                    throw new ArgumentNullException(adClientId);
                }
                if (customChannelId == null)
                {
                    throw new ArgumentNullException(customChannelId);
                }

                // Make the request.
                return(service.Customchannels.Get(accountId, adClientId, customChannelId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Customchannels.Get failed.", ex);
            }
        }
예제 #5
0
        /// <summary>
        /// List the preferred deals for this Ad Exchange account.
        /// Documentation https://developers.google.com/adexchangeseller/v1.1/reference/preferreddeals/list
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AdExchangeSeller service.</param>
        /// <returns>PreferredDealsResponse</returns>
        public static PreferredDeals List(AdExchangeSellerService service)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }

                // Make the request.
                return(service.Preferreddeals.List().Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Preferreddeals.List failed.", ex);
            }
        }
        /// <summary>
        /// List the metadata for the dimensions available to this AdExchange account.
        /// Documentation https://developers.google.com/adexchangeseller/v2.0/reference/dimensions/list
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AdExchangeSeller service.</param>
        /// <param name="accountId">Account with visibility to the dimensions.</param>
        /// <returns>MetadataResponse</returns>
        public static Metadata List(AdExchangeSellerService service, string accountId)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (accountId == null)
                {
                    throw new ArgumentNullException(accountId);
                }

                // Make the request.
                return(service.Dimensions.List(accountId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Dimensions.List failed.", ex);
            }
        }
예제 #7
0
        public List<AdExGoogleStats> GetAdxData()
        {
            List<AdExGoogleStats> stats = new List<AdExGoogleStats>();
            try
            {
                AdExchangeSellerService service_adex = new AdExchangeSellerService(new AdExchangeSellerService.Initializer()
                {
                    HttpClientInitializer = OauthCredentials,
                    ApplicationName = "Admixer Exchange",
                });
                ReportsResource.GenerateRequest gr = new ReportsResource.GenerateRequest(service_adex, StarDate, EndDate);
                gr.Metric = Metrics;
                gr.Dimension = Dimensions;
                gr.Sort = "DATE";
                gr.Locale = "en_US";
                Report report = gr.Execute();
                //stat = report.Rows.Cast<AdExGoogleStat>().ToList();
                foreach (var item in report.Rows)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(item.ElementAt(1))) continue;
                        AdExGoogleStats statobject = new AdExGoogleStats()
                        {
                            Date = DateTime.Parse(item.ElementAt(0)),
                            Id = Int64.Parse(item.ElementAt(1)),
                            TagName = item.ElementAt(2),
                            MatchedRequests = Int64.Parse(item.ElementAt(4)),
                            Clicks = Int32.Parse(item.ElementAt(5)),
                            CTR = decimal.Parse(item.ElementAt(6)),
                            eCPM = decimal.Parse(item.ElementAt(7)),
                            Revenue = decimal.Parse(item.ElementAt(8)),
                            Size = item.ElementAt(3),
                            Width = Int32.Parse(item.ElementAt(3).Substring(0, item.ElementAt(3).IndexOf('x'))),
                            Height = Int32.Parse(item.ElementAt(3).Substring(item.ElementAt(3).IndexOf('x') + 1, item.ElementAt(3).Length - (item.ElementAt(3).IndexOf('x') + 1))),
                            Requests = Int32.Parse(item.ElementAt(9))
                        };
                        stats.Add(statobject);
                    }
                    catch (Exception ex)
                    {
                        Logger.Write("ex_GetAdxData", ex.Message);
                    }
                }


            }

            catch (Exception ex)
            {
                Logger.Write("ex_GetAdxData", ex.Message);
                stats = null;
            }
            Logger.Write("GetAdxData", "Adx Data received");
            return stats;
        }