Esempio n. 1
0
        /// <summary>
        /// <see cref="ITableauUserService.GetUsersAsync"/>
        /// </summary>
        public async Task <IEnumerable <TableauUser> > GetUsersAsync(string groupId = null)
        {
            _logger?.Debug($"Getting users{(!String.IsNullOrWhiteSpace(groupId) ? $" in group {groupId}" : "")}");

            var pageSize       = 1000;
            var pageNumber     = 1;
            var totalRetrieved = 0;
            var totalAvailable = 0;
            var users          = new List <TableauUser>();

            do
            {
                var url = String.IsNullOrWhiteSpace(groupId)
                    ? _tableauApiService.SiteUrl.AppendUri("users")
                    : _tableauApiService.SiteUrl.AppendUri($"groups/{groupId}/users");
                url += $"?pageSize={pageSize}&pageNumber={pageNumber}";

                var responseString = await _tableauApiService.SendGetAsync(url).ConfigureAwait(false);

                var responseJson = JToken.Parse(responseString);
                if (!responseJson.Value <JObject>("users").ContainsKey("user"))
                {
                    break;
                }

                var pagination = JsonConvert.DeserializeObject <TableauPagination>(
                    responseJson.Value <JObject>("pagination").ToString()
                    );

                var pageUsers = JsonConvert.DeserializeObject <List <TableauUser> >(
                    responseJson.Value <JObject>("users").Value <JArray>("user").ToString(),
                    new StringEnumConverter()
                    );
                users.AddRange(pageUsers);

                pageNumber++;
                totalAvailable  = pagination.TotalAvailable;
                totalRetrieved += pagination.PageSize;
            }while (totalRetrieved < totalAvailable);

            users.ForEach(
                u =>
            {
                u.SiteId     = _tableauApiService.SiteId;
                u.ApiVersion = _tableauApiService.ApiVersion;
            }
                );

            _logger?.Debug($"{users.Count} users returned");

            return(users);
        }
Esempio n. 2
0
        /// <summary>
        /// <see cref="ITableauWorkbookService.GetWorkbooksAsync"/>
        /// </summary>
        public async Task <IEnumerable <TableauWorkbook> > GetWorkbooksAsync()
        {
            _logger?.Debug("Getting workbooks");

            var pageSize       = 1000;
            var pageNumber     = 1;
            var totalRetrieved = 0;
            var totalAvailable = 0;
            var workbooks      = new List <TableauWorkbook>();

            do
            {
                var url = _tableauApiService.SiteUrl.AppendUri(
                    $"workbooks?pageSize={pageSize}&pageNumber={pageNumber}"
                    );
                var responseString = await _tableauApiService.SendGetAsync(url).ConfigureAwait(false);

                var responseJson = JToken.Parse(responseString);
                if (!responseJson.Value <JObject>("workbooks").ContainsKey("workbook"))
                {
                    break;
                }

                var pagination = JsonConvert.DeserializeObject <TableauPagination>(
                    responseJson.Value <JObject>("pagination").ToString()
                    );

                var pageWorkbooks = JsonConvert.DeserializeObject <List <TableauWorkbook> >(
                    responseJson.Value <JObject>("workbooks").Value <JArray>("workbook").ToString()
                    );
                workbooks.AddRange(pageWorkbooks);

                pageNumber++;
                totalAvailable  = pagination.TotalAvailable;
                totalRetrieved += pagination.PageSize;
            }while (totalRetrieved < totalAvailable);

            workbooks.ForEach(
                w =>
            {
                w.SiteId     = _tableauApiService.SiteId;
                w.ApiVersion = _tableauApiService.ApiVersion;
            }
                );

            _logger?.Debug($"{workbooks.Count} workbooks returned");

            return(workbooks);
        }
Esempio n. 3
0
        /// <summary>
        /// <see cref="ITableauDatasourceService.GetDatasourcesAsync"/>
        /// </summary>
        public async Task <IEnumerable <TableauDatasource> > GetDatasourcesAsync()
        {
            _logger?.Debug("Getting datasources");

            var pageSize       = 1000;
            var pageNumber     = 1;
            var totalRetrieved = 0;
            var totalAvailable = 0;
            var datasources    = new List <TableauDatasource>();

            do
            {
                var url = _tableauApiService.SiteUrl.AppendUri($"datasources");
                url += $"?pageSize={pageSize}&pageNumber={pageNumber}";
                var responseString = await _tableauApiService.SendGetAsync(url).ConfigureAwait(false);

                var responseJson = JToken.Parse(responseString);
                if (!responseJson.Value <JObject>("datasources").ContainsKey("datasource"))
                {
                    break;
                }

                var pagination = JsonConvert.DeserializeObject <TableauPagination>(
                    responseJson.Value <JObject>("pagination").ToString()
                    );

                var pageDatasources = JsonConvert.DeserializeObject <List <TableauDatasource> >(
                    responseJson.Value <JObject>("datasources").Value <JArray>("datasource").ToString()
                    );
                datasources.AddRange(pageDatasources);

                pageNumber++;
                totalAvailable  = pagination.TotalAvailable;
                totalRetrieved += pagination.PageSize;
            }while (totalRetrieved < totalAvailable);

            datasources.ForEach(
                d =>
            {
                d.SiteId     = _tableauApiService.SiteId;
                d.ApiVersion = _tableauApiService.ApiVersion;
            }
                );

            _logger?.Debug($"{datasources.Count} datasources returned");

            return(datasources);
        }
        /// <summary>
        /// <see cref="ITableauPermissionService.GetPermissionsAsync"/>
        /// </summary>
        public async Task <TableauPermission> GetPermissionsAsync(
            ResourceType resourceType,
            string resourceId
            )
        {
            _logger?.Debug($"Getting permissions for {resourceType.ToString().ToLower()} {resourceId}");
            var url = _tableauApiService.SiteUrl.AppendUri(
                $"{resourceType.ToString().ToLower()}s/{resourceId}/permissions"
                );
            var responseString = await _tableauApiService.SendGetAsync(url).ConfigureAwait(false);

            var responseJson = JToken.Parse(responseString);

            var permissions = JsonConvert.DeserializeObject <TableauPermission>(
                responseJson.Value <JObject>("permissions").ToString(),
                new StringEnumConverter()
                );

            _logger?.Debug($"{permissions?.GranteeCapabilities?.Count().ToString() ?? "0"} capabilities found");

            return(permissions);
        }