public void TestResourceFullyQualifiedPublicId()
        {
            // should return correct FullyQualifiedPublicId

            var uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = GetUniquePublicId(),
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            var listParams = new ListResourcesParams()
            {
                ResourceType = ResourceType.Image,
                MaxResults   = 1
            };

            var result = m_cloudinary.ListResources(listParams);

            Assert.IsNotNull(result.Resources);
            Assert.AreEqual(1, result.Resources.Length);

            var res = result.Resources[0];
            var expectedFullQualifiedPublicId = $"{res.ResourceType}/{res.Type}/{res.PublicId}";

            Assert.AreEqual(expectedFullQualifiedPublicId, res.FullyQualifiedPublicId);
        }
示例#2
0
        public async Task <ListResourcesResult> ListResourcesAsync(ListResourcesParams parameters)
        {
            var url = Api.ApiUrlV.ResourceType("resources").Add(Api.GetCloudinaryParam(parameters.ResourceType));

            if (parameters is ListResourcesByTagParams)
            {
                var resourcesByTagParams = (ListResourcesByTagParams)parameters;
                if (!string.IsNullOrEmpty(resourcesByTagParams.Tag))
                {
                    url.Add("tags").Add(resourcesByTagParams.Tag);
                }
            }
            if (parameters is ListResourcesByModerationParams)
            {
                var moderationParams = (ListResourcesByModerationParams)parameters;
                if (!string.IsNullOrEmpty(moderationParams.ModerationKind))
                {
                    url.Add("moderations").Add(moderationParams.ModerationKind).Add(Api.GetCloudinaryParam(moderationParams.ModerationStatus));
                }
            }
            using (var response = await Api.CallAsync(HttpMethod.Get, new UrlBuilder(url.BuildUrl(), parameters.ToParamsDictionary()).ToString(), null, null, null))
            {
                return(await ListResourcesResult.Parse(response));
            }
        }
示例#3
0
        public void DeleteAllInLoop()
        {
            string nextCursor = String.Empty;

            do
            {
                var response = m_cloudinary.ListUploadPresets(nextCursor);
                nextCursor = response.NextCursor;

                foreach (var preset in response.Presets)
                {
                    m_cloudinary.DeleteUploadPreset(preset.Name);
                }
            } while (!String.IsNullOrEmpty(nextCursor));

            HashSet <string> types = new HashSet <string>();

            do
            {
                var listParams = new ListResourcesParams()
                {
                    NextCursor = nextCursor,
                    MaxResults = MAX_RESULTS
                };

                var existingResources = m_cloudinary.ListResources(listParams);
                nextCursor = existingResources.NextCursor;

                foreach (var res in existingResources.Resources)
                {
                    types.Add(res.Type);
                }
            } while (!String.IsNullOrEmpty(nextCursor));

            foreach (var type in types)
            {
                var deleteParams = new DelResParams()
                {
                    Type = type, All = true
                };

                m_cloudinary.DeleteResources(deleteParams);
            }
        }
        public void TestResourcesCursor()
        {
            // should allow listing resources with cursor

            var uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = GetUniquePublicId(),
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            uploadParams = new ImageUploadParams()
            {
                File     = new FileDescription(m_testImagePath),
                PublicId = GetUniquePublicId(),
                Tags     = m_apiTag
            };

            m_cloudinary.Upload(uploadParams);

            var listParams = new ListResourcesParams()
            {
                ResourceType = ResourceType.Image,
                MaxResults   = 1
            };

            var result1 = m_cloudinary.ListResources(listParams);

            Assert.IsNotNull(result1.Resources);
            Assert.AreEqual(1, result1.Resources.Length);
            Assert.IsFalse(String.IsNullOrEmpty(result1.NextCursor));

            listParams.NextCursor = result1.NextCursor;
            var result2 = m_cloudinary.ListResources(listParams);

            Assert.IsNotNull(result2.Resources);
            Assert.AreEqual(1, result2.Resources.Length);
            Assert.AreNotEqual(result1.Resources[0].PublicId, result2.Resources[0].PublicId);
        }
示例#5
0
        public ListResourcesResult ListResources(ListResourcesParams parameters)
        {
            UrlBuilder urlBuilder = new UrlBuilder(
                m_api.ApiUrlV.
                ResourceType("resources").
                Add(Api.GetCloudinaryParam <ResourceType>(parameters.ResourceType)).
                Add(!String.IsNullOrEmpty(parameters.Tag) ? String.Format("tags/{0}", parameters.Tag) : String.Empty).
                BuildUrl());

            foreach (var param in parameters.ToParamsDictionary())
            {
                urlBuilder.QueryString[param.Key] = param.Value.ToString();
            }

            using (HttpWebResponse response = m_api.Call(
                       HttpMethod.GET, urlBuilder.ToString(), null, null))
            {
                ListResourcesResult result = ListResourcesResult.Parse(response);
                return(result);
            }
        }
示例#6
0
        /// <summary>
        /// Lists resources.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        public ListResourcesResult ListResources(ListResourcesParams parameters)
        {
            var url = m_api.ApiUrlV.
                      ResourceType("resources").
                      Add(Api.GetCloudinaryParam <ResourceType>(parameters.ResourceType));

            if (parameters is ListResourcesByTagParams)
            {
                var tagParams = (ListResourcesByTagParams)parameters;
                if (!String.IsNullOrEmpty(tagParams.Tag))
                {
                    url.Add("tags").Add(tagParams.Tag);
                }
            }

            if (parameters is ListResourcesByModerationParams)
            {
                var modParams = (ListResourcesByModerationParams)parameters;

                if (!String.IsNullOrEmpty(modParams.ModerationKind))
                {
                    url
                    .Add("moderations")
                    .Add(modParams.ModerationKind)
                    .Add(Api.GetCloudinaryParam <ModerationStatus>(modParams.ModerationStatus));
                }
            }

            UrlBuilder urlBuilder = new UrlBuilder(
                url.BuildUrl(),
                parameters.ToParamsDictionary());

            using (HttpWebResponse response = m_api.Call(
                       HttpMethod.GET, urlBuilder.ToString(), null, null))
            {
                ListResourcesResult result = ListResourcesResult.Parse(response);
                return(result);
            }
        }
 /// <summary>
 /// Lists resources.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 public Task <ListResourcesResult> ListResourcesAsync(ListResourcesParams parameters)
 {
     return(CallAsync(ListResources, parameters));
 }
 public static ListResourcesResult ListResources(this Cloudinary cloudinary, ListResourcesParams parameters)
 {
     return(cloudinary.ListResourcesAsync(parameters).ExecSync());
 }