Exemple #1
0
        public async Task <List <ListAPIResponse> > ListFilesAsync()
        {
            string[] arr   = { "limit", "skip", "name", "includeFolder", "tags", "fileType", "path" };
            var      param = new List <string>();

            foreach (var item in options)
            {
                if (arr.Any(item.Key.Contains))
                {
                    param.Add(item.Key + "=" + item.Value);
                }
            }
            options.Remove("tags");
            Uri apiEndpoint = new Uri(Utils.GetFileApi() + "?" + string.Join("&", param));
            var response    = await Utils.GetAsync(apiEndpoint, (string)options["privateKey"]).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            try
            {
                return(JsonConvert.DeserializeObject <List <ListAPIResponse> >(responseContent));
            } catch
            {
                ListAPIResponse resp = JsonConvert.DeserializeObject <ListAPIResponse>(responseContent);
                resp.StatusCode   = (int)response.StatusCode;
                resp.XIkRequestId = response.Headers.FirstOrDefault(x => x.Key == "x-ik-requestid").Value?.First();
                List <ListAPIResponse> respList = new List <ListAPIResponse>();
                respList.Add(resp);
                return(respList);
            }
        }
Exemple #2
0
        public async Task <ListAPIResponse> UpdateFileDetailsAsync(string fileId)
        {
            if (string.IsNullOrEmpty(fileId))
            {
                throw new ArgumentException(errorMessages.FILE_ID_MISSING);
            }
            // If one of these is not provided, this request does nothing
            if (!options.ContainsKey("tags") && !options.ContainsKey("tagsList") && !options.ContainsKey("customCoordinates"))
            {
                throw new ArgumentException(errorMessages.UPDATE_DATA_MISSING);
            }

            Dictionary <string, object> postData = new Dictionary <string, object>();

            if (options.ContainsKey("tags"))
            {
                var tags = (string)options["tags"];
                if (tags != null && tags != "null")
                {
                    var tagsArray = tags.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    postData.Add("tags", tagsArray);
                }
                options.Remove("tags");
            }
            else if (options.ContainsKey("tagsList"))
            {
                string[] tags = (string[])options["tagsList"];
                if (tags == null || !tags.Any())
                {
                    throw new ArgumentException(errorMessages.UPDATE_DATA_TAGS_INVALID);
                }
                postData.Add("tags", tags);
                options.Remove("tagsList");
            }

            if (options.ContainsKey("customCoordinates"))
            {
                if (string.IsNullOrEmpty((string)options["customCoordinates"]))
                {
                    throw new ArgumentException(errorMessages.UPDATE_DATA_COORDS_INVALID);
                }
                postData.Add("customCoordinates", (string)options["customCoordinates"]);
            }

            Uri    apiEndpoint = new Uri(Utils.GetFileApi() + "/" + fileId + "/details");
            string contentType = "application/json; charset=utf-8";

            HttpResponseMessage response = await Utils.PostAsync(apiEndpoint, postData, contentType, (string)options["privateKey"], "PATCH").ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            ListAPIResponse resp = JsonConvert.DeserializeObject <ListAPIResponse>(responseContent);

            resp.StatusCode   = (int)response.StatusCode;
            resp.XIkRequestId = response.Headers.FirstOrDefault(x => x.Key == "x-ik-requestid").Value?.First();
            return(resp);
        }
Exemple #3
0
        public async Task <ListAPIResponse> GetFileDetailsAsync(string fileId)
        {
            if (string.IsNullOrEmpty(fileId))
            {
                throw new ArgumentException(errorMessages.FILE_ID_MISSING);
            }
            Uri apiEndpoint = new Uri(Utils.GetFileApi() + "/" + fileId + "/details");
            var response    = await Utils.GetAsync(apiEndpoint, (string)options["privateKey"]).ConfigureAwait(false);

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            ListAPIResponse resp = JsonConvert.DeserializeObject <ListAPIResponse>(responseContent);

            resp.StatusCode   = (int)response.StatusCode;
            resp.XIkRequestId = response.Headers.FirstOrDefault(x => x.Key == "x-ik-requestid").Value?.First();
            return(resp);
        }