Example #1
0
        protected async Task <IEnumerable <TItem> > GetAllPagesFromApi <TItem>(AdobeQueryBuilder query, int pageSize = 1000)
        {
            var items = new List <TItem>();

            var page = 0;
            ApiResponse <AdobeRowResponse <TItem> > response;

            do
            {
                var uri = query
                          .WithParam("limit", pageSize.ToString())
                          .WithParam("page", page.ToString())
                          .Build();

                response = await HttpClient.GetApiResponse <AdobeRowResponse <TItem> >(uri);

                if (response == null || !response.HasValue)
                {
                    throw new ApiException(response?.Error);
                }

                items.AddRange(response.Value.Content);
                page++;
            } while (response.Value.TotalElements > 0 && !response.Value.LastPage);


            return(items);
        }
        /// <summary>
        /// Returns a list of metrics for the given report suite.
        /// </summary>
        /// <param name="reportSuiteId">ID of desired report suite ie. sistr2.</param>
        /// <param name="fields">A list of fields to return.</param>
        /// <param name="locale">Locale that system named metrics should be returned in</param>
        /// <param name="segmentable">Filter the metrics by if they are valid in a segment.</param>
        /// <returns>A list of metrics for the given report suite.</returns>
        public virtual async Task <IEnumerable <AnalyticsMetric> > GetMetrics(
            string reportSuiteId,
            IEnumerable <Field> fields,
            string locale    = "en_US",
            bool segmentable = false)
        {
            await AuthorizeClient(AuthValues);

            var uri = new AdobeQueryBuilder("metrics")
                      .WithCompanyId(AuthValues.CompanyId)
                      .WithReportSuiteId(reportSuiteId)
                      .WithFields(fields)
                      .WithParam("locale", locale)
                      .WithParamIf(segmentable, "segmentable", "true")
                      .Build();

            var response = await HttpClient.GetApiResponse <IEnumerable <AnalyticsMetric> >(uri);

            if (response != null && response.HasValue)
            {
                return(response.Value);
            }

            throw new ApiException(response?.Error);
        }
        /// <summary>
        /// Returns a metric for the given report suite.
        /// </summary>
        /// <param name="id">The id of the metric for which to retrieve info. Note ids are values like pageviews, not metrics/pageviews.</param>
        /// <param name="reportSuiteId">ID of desired report suite ie. sistr2.</param>
        /// <param name="fields">A list of fields to return.</param>
        /// <param name="locale">Locale that system named metrics should be returned in.</param>
        /// <returns>The metric with the given ID.</returns>
        public async Task <AnalyticsMetric> GetMetricById(
            string id,
            string reportSuiteId,
            IEnumerable <Field> fields,
            string locale = "en_US")
        {
            await AuthorizeClient(AuthValues);

            var sanitizedId = id.Replace("metrics/", string.Empty);

            var uri = new AdobeQueryBuilder($"metrics/{sanitizedId}")
                      .WithCompanyId(AuthValues.CompanyId)
                      .WithReportSuiteId(reportSuiteId)
                      .WithFields(fields)
                      .WithParam("locale", locale)
                      .Build();

            var response = await HttpClient.GetApiResponse <AnalyticsMetric>(uri);

            if (response != null && response.HasValue)
            {
                return(response.Value);
            }

            throw new ApiException(response?.Error);
        }
        /// <summary>
        /// Retrieves all segments.
        /// </summary>
        /// <param name="reportSuiteId">Filter list to only include segments tied to specified RSID list (comma-delimited).</param>
        /// <param name="rsids">Filter list to only include suites in this RSID list.</param>
        /// <param name="segmentFilter">Filter list to only include segments in the specified list.</param>
        /// <param name="name">Filter list to only include segments that contains the Name.</param>
        /// <param name="locale">Locale.</param>
        /// <param name="tagNames">Filter list to only include segments that contains one of the tags.</param>
        /// <param name="filterByPublishedSegments">Filter list to only include segments where the published field is set to one of the allowable values (all, true, false).</param>
        /// <param name="sortDirection">Sort direction (ASC or DESC).</param>
        /// <param name="sortProperty">Property to sort by (name, modified_date, id is currently allowed).</param>
        /// <returns></returns>
        public async Task <IEnumerable <AnalyticsSegmentResponseItem> > GetSegments(
            string reportSuiteId,
            IEnumerable <Field> fields,
            IEnumerable <string> segmentFilter = null,
            string name   = "",
            string locale = "en_US",
            IEnumerable <string> tagNames    = null,
            string filterByPublishedSegments = "all",
            string sortDirection             = "ASC",
            string sortProperty = "id")
        {
            await AuthorizeClient(AuthValues);

            segmentFilter = segmentFilter ?? Array.Empty <string>();
            tagNames      = tagNames ?? Array.Empty <string>();

            var query = new AdobeQueryBuilder("segments")
                        .WithCompanyId(AuthValues.CompanyId)
                        .WithFields(fields)
                        .WithParam("locale", locale)
                        .WithParam("name", name)
                        .WithParam("includeType", "all")
                        .WithParam("sortDirection", sortDirection)
                        .WithParam("sortProperty", sortProperty)
                        .WithParam("filterByPublishedSegments", filterByPublishedSegments)
                        .WithParamIf(segmentFilter != null, "segmentFilter", string.Join(",", segmentFilter))
                        .WithParamIf(tagNames != null, "tagNames", string.Join(",", tagNames));

            var segments = await GetAllPagesFromApi <AnalyticsSegmentResponseItem>(query);

            return(segments);
        }
        public void SetUp()
        {
            const string relativePath = "test";
            const string companyId    = "company";

            _queryBuilder = new AdobeQueryBuilder(relativePath)
                            .WithCompanyId(companyId);
        }
        /// <summary>
        /// Returns a list of users for the current user's login company.
        /// </summary>
        /// <returns>A list of users.</returns>
        public async Task <IEnumerable <AnalyticsUser> > GetUsers()
        {
            await AuthorizeClient(AuthValues);

            var query = new AdobeQueryBuilder("users");
            var users = await GetAllPagesFromApi <AnalyticsUser>(query);

            return(users);
        }
Example #7
0
        /// <summary>
        /// Retrieves report suite by id.
        /// </summary>
        /// <param name="id">The rsid of the suite to return.</param>
        /// <param name="fields">A list of fields to return.</param>
        /// <returns>The report suite with the given ID.</returns>
        public async Task <SuiteCollectionItem> GetReportSuiteById(string id, IEnumerable <Field> fields)
        {
            await AuthorizeClient(AuthValues);

            var uri = new AdobeQueryBuilder($"collections/suites/{id}")
                      .WithCompanyId(AuthValues.CompanyId)
                      .WithFields(fields)
                      .Build();

            var response = await HttpClient.GetApiResponse <SuiteCollectionItem>(uri);

            if (response != null && response.HasValue)
            {
                return(response.Value);
            }

            throw new ApiException(response?.Error);
        }
Example #8
0
        /// <summary>
        /// Retrieves report suites that match the given filters.
        /// </summary>
        /// <param name="fields">A list of fields to return.</param>
        /// <param name="rsids">Filter list to only include suites in this RSID list.</param>
        /// <param name="rsidContains">Filter list to only include suites whose rsid contains rsidContains.</param>
        /// <returns>A list of report suites.</returns>
        public async Task <IEnumerable <SuiteCollectionItem> > GetReportSuites(
            IEnumerable <Field> fields,
            IEnumerable <string> rsids = null,
            string rsidContains        = null)
        {
            await AuthorizeClient(AuthValues);

            rsids = rsids ?? Array.Empty <string>();

            var query = new AdobeQueryBuilder("collections/suites")
                        .WithCompanyId(AuthValues.CompanyId)
                        .WithFields(fields)
                        .WithParamIf(rsids.Any(), "rsids", string.Join(",", rsids))
                        .WithParamIf(!string.IsNullOrEmpty(rsidContains), "rsidContains", rsidContains);

            var reportSuites = await GetAllPagesFromApi <SuiteCollectionItem>(query);

            return(reportSuites);
        }
        /// <summary>
        /// Delete a segment.
        /// </summary>
        /// <param name="segmentId">The ID of the segment to delete.</param>
        /// <param name="locale">Locale.</param>
        /// <returns>The result of the delete action.</returns>
        public virtual async Task <AnalyticsSegmentDeleteResponse> DeleteSegment(
            string segmentId,
            string locale = "en_US")
        {
            await AuthorizeClient(AuthValues);

            var uri = new AdobeQueryBuilder($"segments/{segmentId}")
                      .WithCompanyId(AuthValues.CompanyId)
                      .WithParam("locale", locale)
                      .Build();

            var response = await HttpClient.DeleteApiResponse <AnalyticsSegmentDeleteResponse>(uri);

            if (response != null && response.HasValue)
            {
                return(response.Value);
            }

            throw new ApiException(response?.Error);
        }
        /// <summary>
        /// Creates segment.
        /// </summary>
        /// <param name="segment">The segment to create</param>
        /// <param name="fields">The fields to include from response.</param>
        /// <param name="locale">Locale.</param>
        /// <returns>The created segment.</returns>
        public virtual async Task <AnalyticsSegmentResponseItem> CreateSegment(
            AnalyticsSegmentResponseItem segment,
            IEnumerable <Field> fields,
            string locale = "en_US")
        {
            await AuthorizeClient(AuthValues);

            var uri = new AdobeQueryBuilder("segments")
                      .WithCompanyId(AuthValues.CompanyId)
                      .WithFields(fields)
                      .WithParam("locale", locale)
                      .Build();

            var response = await HttpClient.PostApiResponse <AnalyticsSegmentResponseItem>(uri, segment);

            if (response != null && response.HasValue)
            {
                return(response.Value);
            }

            throw new ApiException(response?.Error);
        }