예제 #1
0
        public static async Task<List<TrackAnalysisData>> GetTrackAnalysisData(string requestType, string campaignId, string dimensions, string metrics, string startDate, string endDate, string maxResults)
        {
            TrackAnalysisRequest.Singleton.InitialRequest(TrackAnalysisReportResource.TrackAnalysisDataServer, User.UserToken.Access_Token);
            var requiredStartDate = startDate.Split(' ')[0];
            var requiredEndDate = endDate.Split(' ')[0];
            var trackAnalysisInfo = new TrackAnalysisInfo
            {
                StartDate = requiredStartDate,
                EndDate = requiredEndDate,
                Dimensions = dimensions,
                Metrics = metrics,
                MaxResults = maxResults
            };

            var data = await TrackAnalysisRequest.Singleton.GetTrackAnalysisData(requestType, campaignId, trackAnalysisInfo);
            if (dimensions.IndexOf("CampaignsName", StringComparison.OrdinalIgnoreCase) == -1)
            {
                return data;
            }

            TrackAnalysisCompaignRequest.Singleton.InitialRequest(TrackAnalysisReportResource.TrackAnalysisDataClient, User.UserToken.Access_Token);
            var campaigns = await TrackAnalysisCompaignRequest.Singleton.GetCampaigns();

            var campaignName = campaigns[campaignId];
            foreach (var item in data)
            {
                item.Campaigns = campaignId;
                item.CampaignsName = campaignName;
            }

            
            return data;
        }
        public async Task<List<TrackAnalysisData>> GetTrackAnalysisData(string requestType, string campaignId, TrackAnalysisInfo info)
        {
            string requestUri = string.Format(TrackAnalysisReportResource.TrackAnalysisDataRequest, campaignId, requestType);
            var request = this.SetRequest(requestUri, info);

            var response = await this.client.ExecuteGetTaskAsync(request);
            if (!this.IsStatusCodeOK(response.StatusCode))
            {
                return new List<TrackAnalysisData>();
            }

            var data = JsonConvert.DeserializeObject<List<TrackAnalysisData>>(response.Content);

            return data;
        }
        private RestRequest SetRequest(string requestUri, TrackAnalysisInfo info)
        {
            var request = new RestRequest(requestUri, Method.GET);
            if (this.accessToken != null)
            {
                request.AddParameter("access_token", this.accessToken);
            }

            if (info == null)
            {
                return null;
            }

            var dimensions = this.FormatDimensions(info.Dimensions);

            var metrics = info.Metrics;
            if (requestUri.Contains("freqs"))
            {
                metrics = this.FormatFreqsMetrics(info.Metrics);
            }

            request.AddParameter("startDate", info.StartDate);
            request.AddParameter("endDate", info.EndDate);
            request.AddParameter("dimensions", dimensions);
            request.AddParameter("metrics", metrics);
            request.AddParameter("maxResults", info.MaxResults);
            request.AddParameter("startIndex", "0");

            if (info.GeoId != null)
            {
                //for igrp
                request.AddParameter("geo", info.GeoId);
            }

            if (info.SiteId != null)
            {
                //for integrate
                request.AddParameter("siteId", info.SiteId);
            }
            
            return request;
        }