Beispiel #1
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);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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));
            }
        }