/// <summary>
 /// Gets a list of all profiles the user has access to.
 /// </summary>
 /// <param name="maxResults">The maximum number of views (profiles) to include in this response.</param>
 /// <param name="startIndex">An index of the first entity to retrieve. Use this parameter as a pagination mechanism along with the max-results parameter.</param>
 public AnalyticsProfilesResponse GetProfiles(int maxResults = 0, int startIndex = 0)
 {
     return(AnalyticsProfilesResponse.ParseJson(Service.Client.Analytics.GetProfiles("~all", "~all", maxResults, startIndex)));
 }
 /// <summary>
 /// Gets a list of profiles for the specified web property.
 /// </summary>
 /// <param name="property">The parent web propaerty.</param>
 /// <param name="maxResults">The maximum number of views (profiles) to include in this response.</param>
 /// <param name="startIndex">An index of the first entity to retrieve. Use this parameter as a pagination mechanism along with the max-results parameter.</param>
 public AnalyticsProfilesResponse GetProfiles(AnalyticsWebProperty property, int maxResults = 0, int startIndex = 0)
 {
     return(AnalyticsProfilesResponse.ParseJson(Service.Client.Analytics.GetProfiles(property.AccountId, property.Id, maxResults, startIndex)));
 }
 /// <summary>
 /// Gets a list of profiles for the specified account and web property.
 /// </summary>
 /// <param name="accountId">Account ID for the view (profiles) to retrieve. Can either be a specific account ID or '~all', which refers to all the accounts to which the user has access.</param>
 /// <param name="webPropertyId">Web property ID for the views (profiles) to retrieve. Can either be a specific web property ID or '~all', which refers to all the web properties to which the user has access.</param>
 /// <param name="maxResults">The maximum number of views (profiles) to include in this response.</param>
 /// <param name="startIndex">An index of the first entity to retrieve. Use this parameter as a pagination mechanism along with the max-results parameter.</param>
 public AnalyticsProfilesResponse GetProfiles(string accountId, string webPropertyId, int maxResults = 0, int startIndex = 0)
 {
     return(AnalyticsProfilesResponse.ParseJson(Service.Client.Analytics.GetProfiles(accountId, webPropertyId, maxResults, startIndex)));
 }
Example #4
0
        public static AnalyticsCachedUser GetFromResponses(AnalyticsUserConfiguration user, AnalyticsAccountsResponse response1, AnalyticsWebPropertiesResponse response2, AnalyticsProfilesResponse response3)
        {
            Dictionary <string, List <AnalyticsWebProperty> > webProperties = new Dictionary <string, List <AnalyticsWebProperty> >();
            Dictionary <string, List <AnalyticsProfile> >     profiles      = new Dictionary <string, List <AnalyticsProfile> >();

            // Add the web properties to a dictionary for faster lookups
            foreach (AnalyticsWebProperty webProperty in response2.Body.Items)
            {
                List <AnalyticsWebProperty> list;
                if (!webProperties.TryGetValue(webProperty.AccountId, out list))
                {
                    webProperties.Add(webProperty.AccountId, list = new List <AnalyticsWebProperty>());
                }
                list.Add(webProperty);
            }

            // Add the profiles to a dictionary for faster lookups
            foreach (AnalyticsProfile profile in response3.Body.Items)
            {
                List <AnalyticsProfile> list;
                if (!profiles.TryGetValue(profile.WebPropertyId, out list))
                {
                    profiles.Add(profile.WebPropertyId, list = new List <AnalyticsProfile>());
                }
                list.Add(profile);
            }



            AnalyticsCachedUser cachedUser = new AnalyticsCachedUser {
                Id = user.Id
            };


            List <AnalyticsCachedAccount> cachedAccounts = new List <AnalyticsCachedAccount>();

            foreach (AnalyticsAccount account in response1.Body.Items)
            {
                List <AnalyticsCachedWebProperty> list11 = new List <AnalyticsCachedWebProperty>();

                List <AnalyticsWebProperty> list1;
                if (!webProperties.TryGetValue(account.Id, out list1))
                {
                    list1 = new List <AnalyticsWebProperty>();
                }

                AnalyticsCachedAccount ca = new AnalyticsCachedAccount {
                    User    = null,
                    Id      = account.Id,
                    Name    = account.Name,
                    Created = account.JsonObject.GetString("created"),
                    Updated = account.JsonObject.GetString("updated")
                };

                foreach (AnalyticsWebProperty webProperty in list1)
                {
                    List <AnalyticsProfile> list2;
                    if (!profiles.TryGetValue(webProperty.Id, out list2))
                    {
                        list2 = new List <AnalyticsProfile>();
                    }

                    AnalyticsCachedWebProperty cwp = new AnalyticsCachedWebProperty {
                        Id         = webProperty.Id,
                        Name       = webProperty.Name,
                        WebsiteUrl = webProperty.WebsiteUrl,
                        Created    = webProperty.Created.ToString("r"),
                        Updated    = webProperty.Updated.ToString("r")
                    };

                    cwp.Profiles = list2.Select(profile => new AnalyticsCachedProfile {
                        WebProperty = cwp,
                        Id          = profile.Id,
                        Name        = profile.Name,
                        Currency    = profile.Currency,
                        Timezone    = profile.Timezone,
                        WebsiteUrl  = profile.WebsiteUrl,
                        Type        = profile.Type,
                        Created     = profile.JsonObject.GetString("created"),
                        Updated     = profile.JsonObject.GetString("updated")
                    }).ToArray();

                    list11.Add(cwp);
                }

                ca.WebProperties = list11.ToArray();

                cachedAccounts.Add(ca);
            }

            cachedUser.Accounts = cachedAccounts.ToArray();

            return(cachedUser);
        }