Ejemplo n.º 1
0
        /// <summary>
        /// Retreives a given Domo User by User Id
        /// </summary>
        /// <param name="userId">Id of user to retreive</param>
        /// <returns>Returns a Domo User. <see cref="BuildIntelligence.Domo.Sdk.Users.DomoUser"/></returns>
        public async Task <DomoUser> RetrieveUserAsync(long userId)
        {
            string userUri = $"v1/users/{userId}";

            _domoHttpClient.SetAcceptRequestHeaders("application/json");

            var response = await _domoHttpClient.Client.GetAsync(userUri);

            string stringResponse = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <DomoUser>(stringResponse));
        }
        /// <summary>
        /// Create a stream dataset
        /// </summary>
        /// <param name="datasetSchema">Schema and metadata for the dataset to create</param>
        /// <param name="updateMethod">Update method type for stream dataset. Options are Append or Replace</param>
        /// <returns></returns>
        public async Task <StreamDataset> CreateAsync(IDatasetSchema datasetSchema, UpdateMethod updateMethod)
        {
            string streamUri = "v1/streams";

            //_domoHttpClient.SetContentType("application/json");
            _domoHttpClient.SetAcceptRequestHeaders("application/json");
            string dsUpdateMethod = "";

            if (updateMethod == UpdateMethod.APPEND)
            {
                dsUpdateMethod = "APPEND";
            }
            else if (updateMethod == UpdateMethod.REPLACE)
            {
                dsUpdateMethod = "REPLACE";
            }
            var streamSchema = new StreamDatasetSchema()
            {
                DataSet = datasetSchema, UpdateMethod = dsUpdateMethod
            };
            string schemaJson = JsonConvert.SerializeObject(streamSchema, new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });
            StringContent content = new StringContent(schemaJson, Encoding.UTF8, "application/json");

            var response = await _domoHttpClient.Client.PostAsync(streamUri, content);

            string responseMessage = await response.Content.ReadAsStringAsync();

            var newStreamDataset = JsonConvert.DeserializeObject <StreamDataset>(responseMessage);

            return(newStreamDataset);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves information about a page
        /// </summary>
        /// <param name="pageId"></param>
        /// <returns>Page information</returns>
        public async Task <Page> RetrievePageAsync(string pageId)
        {
            string pageUri = $"v1/pages/{pageId}";

            _domoHttpClient.SetAcceptRequestHeaders("application/json");

            var response = await _domoHttpClient.Client.GetAsync(pageUri);

            string stringResponse = await response.Content.ReadAsStringAsync();

            Page pageResponse = JsonConvert.DeserializeObject <Page>(stringResponse);

            return(pageResponse);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves information about a group
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns>Group requested</returns>
        public async Task <Group> RetrieveGroupAsync(string groupId)
        {
            string groupUri = $"v1/groups/{groupId}";

            _domoHttpClient.SetAcceptRequestHeaders("application/json");

            var response = await _domoHttpClient.Client.GetAsync(groupUri);

            string stringResponse = await response.Content.ReadAsStringAsync();

            var objectResponse = JsonConvert.DeserializeObject <Group>(stringResponse);

            return(objectResponse);
        }
        /// <summary>
        /// Returns a list of datasets in Domo. Max list size is 50
        /// </summary>
        /// <param name="limit">Number of datasets to return. Max is 50</param>
        /// <param name="offset">Offset number of datasets to start return from</param>
        /// <returns></returns>
        public async Task <IEnumerable <Dataset> > ListDatasetsAsync(int limit, int offset /*Sorting as optional param or overload*/)
        {
            if (limit > 50)
            {
                throw new LimitNotWithinBoundsException($"The list limit of {limit} used is above the max limit. The maximum limit is 50");
            }
            if (limit < 0)
            {
                throw new LimitNotWithinBoundsException($"List limit {limit} cannot be used. Use a limit value between 1 and 50");
            }

            _domoHttpClient.SetAcceptRequestHeaders("application/json");

            var response = await _domoHttpClient.Client.GetAsync($"v1/datasets?limit={limit}&offset={offset}");

            string responseAsString = await response.Content.ReadAsStringAsync();

            var desResponse = JsonConvert.DeserializeObject <IEnumerable <Dataset> >(responseAsString);

            return(desResponse);
        }