/// <summary>
        /// Maps object model to dictionary of parameters in cloudinary notation
        /// </summary>
        /// <returns>Sorted dictionary of parameters</returns>
        public override SortedDictionary <string, object> ToParamsDictionary()
        {
            SortedDictionary <string, object> dict = new SortedDictionary <string, object>();

            if (MaxResults > 0)
            {
                AddParam(dict, "max_results", MaxResults.ToString());
            }

            AddParam(dict, "next_cursor", NextCursor);
            AddParam(dict, "type", Type);
            AddParam(dict, "prefix", Prefix);

            return(dict);
        }
Example #2
0
        /// <summary>
        /// builds parameters common to timeline queries
        /// </summary>
        /// <param name="parameters">parameters to process</param>
        /// <param name="req"><see cref="Request"/> object</param>
        void BuildTimelineParameters(Dictionary <string, string> parameters, Request req)
        {
            var urlParams = req.RequestParameters;

            if (parameters.ContainsKey(nameof(EndTime)))
            {
                EndTime = DateTime.Parse(parameters[nameof(EndTime)]);
                urlParams.Add(new QueryParameter("end_time", EndTime.ToString(L2TKeys.ISO8601, CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(Exclude)))
            {
                Exclude = parameters[nameof(Exclude)];
                urlParams.Add(new QueryParameter("exclude", Exclude.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(MaxResults)))
            {
                MaxResults = int.Parse(parameters[nameof(MaxResults)]);
                urlParams.Add(new QueryParameter("max_results", MaxResults.ToString()));
            }

            if (parameters.ContainsKey(nameof(PaginationToken)))
            {
                PaginationToken = parameters[nameof(PaginationToken)];
                urlParams.Add(new QueryParameter("pagination_token", PaginationToken));
            }

            if (parameters.ContainsKey(nameof(SinceID)))
            {
                SinceID = parameters[nameof(SinceID)];
                urlParams.Add(new QueryParameter("since_id", SinceID));
            }

            if (parameters.ContainsKey(nameof(StartTime)))
            {
                StartTime = DateTime.Parse(parameters[nameof(StartTime)]);
                urlParams.Add(new QueryParameter("start_time", StartTime.ToString(L2TKeys.ISO8601, CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(UntilID)))
            {
                UntilID = parameters[nameof(UntilID)];
                urlParams.Add(new QueryParameter("until_id", UntilID));
            }

            BuildUrlFieldParameters(parameters, req);
        }
        public List <(string, string)> GetParameters(bool isPremier)
        {
            var headers = new List <(string, string)>();

            headers.Add(("method", _method));
            headers.Add(("search_expression", SearchExpression));
            headers.Add(("page_number", PageNumber.ToString()));
            headers.Add(("max_results", MaxResults.ToString()));
            if (!isPremier)
            {
                return(headers);
            }

            headers.Add(("generic_description", GenericDescription.ToString()));
            return(headers);
        }
Example #4
0
        public override SortedDictionary <string, object> ToParamsDictionary()
        {
            var paramsDictionary = base.ToParamsDictionary();

            if (MaxResults > 0)
            {
                AddParam(paramsDictionary, "max_results", MaxResults.ToString());
            }
            AddParam(paramsDictionary, "exif", Exif);
            AddParam(paramsDictionary, "colors", Colors);
            AddParam(paramsDictionary, "faces", Faces);
            AddParam(paramsDictionary, "image_metadata", Metadata);
            AddParam(paramsDictionary, "phash", Phash);
            AddParam(paramsDictionary, "coordinates", Coordinates);
            return(paramsDictionary);
        }
        public override SortedDictionary <string, object> ToParamsDictionary()
        {
            var paramsDictionary = base.ToParamsDictionary();

            if (MaxResults > 0)
            {
                AddParam(paramsDictionary, "max_results", MaxResults.ToString());
            }
            AddParam(paramsDictionary, "start_at", StartAt);
            AddParam(paramsDictionary, "next_cursor", NextCursor);
            AddParam(paramsDictionary, "tags", Tags);
            AddParam(paramsDictionary, "moderations", Moderations);
            AddParam(paramsDictionary, "context", Context);
            AddParam(paramsDictionary, "direction", Direction);
            AddParam(paramsDictionary, "type", Type);
            return(paramsDictionary);
        }
Example #6
0
        /// <summary>
        /// Maps object model to dictionary of parameters in cloudinary notation
        /// </summary>
        /// <returns>Sorted dictionary of parameters</returns>
        public override SortedDictionary <string, object> ToParamsDictionary()
        {
            SortedDictionary <string, object> dict = base.ToParamsDictionary();

            if (MaxResults > 0)
            {
                AddParam(dict, "max_results", MaxResults.ToString());
            }
            if (Named.HasValue)
            {
                AddParam(dict, "named", Named.Value.ToString());
            }
            if (!string.IsNullOrWhiteSpace(NextCursor))
            {
                AddParam(dict, "next_cursor", NextCursor);
            }

            return(dict);
        }
        Request BuildReverseUrl(Dictionary <string, string> parameters)
        {
            if (!parameters.ContainsKey("Latitude") || !parameters.ContainsKey("Longitude"))
            {
                const string LatLongParam = "LatLong";
                throw new ArgumentException("Latitude and Longitude parameters are required.", LatLongParam);
            }

            var req       = new Request(BaseUrl + "geo/reverse_geocode.json");
            var urlParams = req.RequestParameters;

            if (parameters.ContainsKey("Latitude"))
            {
                Latitude = double.Parse(parameters["Latitude"], CultureInfo.InvariantCulture);
                urlParams.Add(new QueryParameter("lat", double.Parse(parameters["Latitude"]).ToString(Culture.US)));
            }

            if (parameters.ContainsKey("Longitude"))
            {
                Longitude = double.Parse(parameters["Longitude"], CultureInfo.InvariantCulture);
                urlParams.Add(new QueryParameter("long", double.Parse(parameters["Longitude"]).ToString(Culture.US)));
            }

            if (parameters.ContainsKey("Accuracy"))
            {
                Accuracy = parameters["Accuracy"];
                urlParams.Add(new QueryParameter("accuracy", Accuracy));
            }

            if (parameters.ContainsKey("Granularity"))
            {
                Granularity = parameters["Granularity"];
                urlParams.Add(new QueryParameter("granularity", Granularity));
            }

            if (parameters.ContainsKey("MaxResults"))
            {
                MaxResults = int.Parse(parameters["MaxResults"]);
                urlParams.Add(new QueryParameter("max_results", MaxResults.ToString(CultureInfo.InvariantCulture)));
            }

            return(req);
        }
Example #8
0
        /// <summary>
        /// Maps object model to dictionary of parameters in cloudinary notation
        /// </summary>
        /// <returns>Sorted dictionary of parameters</returns>
        public override SortedDictionary <string, object> ToParamsDictionary()
        {
            SortedDictionary <string, object> dict = base.ToParamsDictionary();

            if (MaxResults > 0)
            {
                AddParam(dict, "max_results", MaxResults.ToString());
            }

            AddParam(dict, "exif", Exif);
            AddParam(dict, "colors", Colors);
            AddParam(dict, "faces", Faces);
            AddParam(dict, "quality_analysis", QualityAnalysis);
            AddParam(dict, "image_metadata", Metadata);
            AddParam(dict, "phash", Phash);
            AddParam(dict, "coordinates", Coordinates);

            return(dict);
        }
Example #9
0
        /// <summary>
        /// Convert to specification in server format
        /// </summary>
        /// <returns>The specification for the group</returns>
        override public String ToString()
        {
            String subgroupsView = String.Empty;

            if (SubGroups != null)
            {
                for (int idx = 0; idx < SubGroups.Count; idx++)
                {
                    subgroupsView += String.Format("\t{0}\r\n", SubGroups[idx]);
                }
            }
            String ownersView = String.Empty;

            if (OwnerNames != null)
            {
                for (int idx = 0; idx < OwnerNames.Count; idx++)
                {
                    ownersView += String.Format("\t{0}\r\n", OwnerNames[idx]);
                }
            }
            String usersView = String.Empty;

            if (UserNames != null)
            {
                for (int idx = 0; idx < UserNames.Count; idx++)
                {
                    usersView += String.Format("\t{0}\r\n", UserNames[idx]);
                }
            }
            String value = String.Format(GroupSpecFormat, Id,
                                         (MaxResults > 0) ? MaxResults.ToString() : string.Empty,
                                         (MaxScanRows > 0) ? MaxScanRows.ToString() : string.Empty,
                                         (MaxLockTime > 0) ? MaxLockTime.ToString() : string.Empty,
                                         (MaxOpenFiles > 0) ? MaxOpenFiles.ToString() : string.Empty,
                                         (TimeOut > 0) ? TimeOut.ToString() : string.Empty,
                                         (PasswordTimeout > 0) ? "PasswordTimeout:\t" + PasswordTimeout.ToString() + "\r\n" + "\r\n" : string.Empty,
                                         subgroupsView, ownersView, usersView);

            return(value);
        }
        Request BuildSearchUrl(Dictionary <string, string> parameters)
        {
            if (!parameters.ContainsKey("IP") &&
                !parameters.ContainsKey("Query") &&
                !(parameters.ContainsKey("Latitude") &&
                  parameters.ContainsKey("Longitude")))
            {
                throw new ArgumentException("Either Latitude and Longitude, Query, or IP address is required.");
            }

            var req       = new Request(BaseUrl + "geo/search.json");
            var urlParams = req.RequestParameters;

            if (parameters.ContainsKey("Latitude"))
            {
                Latitude = double.Parse(parameters["Latitude"]);
                urlParams.Add(new QueryParameter("lat", Latitude.ToString(Culture.US)));
            }

            if (parameters.ContainsKey("Longitude"))
            {
                Longitude = double.Parse(parameters["Longitude"]);
                urlParams.Add(new QueryParameter("long", Longitude.ToString(Culture.US)));
            }

            if (parameters.ContainsKey("Query"))
            {
                Query = parameters["Query"];
                urlParams.Add(new QueryParameter("query", Query));
            }

            if (parameters.ContainsKey("IP"))
            {
                IP = parameters["IP"];
                urlParams.Add(new QueryParameter("ip", IP));
            }

            if (parameters.ContainsKey("Accuracy"))
            {
                Accuracy = parameters["Accuracy"];
                urlParams.Add(new QueryParameter("accuracy", Accuracy));
            }

            if (parameters.ContainsKey("Granularity"))
            {
                Granularity = parameters["Granularity"];
                urlParams.Add(new QueryParameter("granularity", Granularity));
            }

            if (parameters.ContainsKey("MaxResults"))
            {
                MaxResults = int.Parse(parameters["MaxResults"]);
                urlParams.Add(new QueryParameter("max_results", MaxResults.ToString(CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey("ContainedWithin"))
            {
                ContainedWithin = parameters["ContainedWithin"];
                urlParams.Add(new QueryParameter("contained_within", ContainedWithin));
            }

            HandleAttributeParams(parameters, urlParams);

            return(req);
        }
        /// <summary>
        /// appends parameters for Search request
        /// </summary>
        /// <param name="parameters">list of parameters from expression tree</param>
        /// <param name="url">base url</param>
        /// <returns>base url + parameters</returns>
        private Request BuildSearchUrlParameters(Dictionary <string, string> parameters, string url)
        {
            var req       = new Request(BaseUrl + url);
            var urlParams = req.RequestParameters;


            if (parameters.ContainsKey(nameof(Query)) && !string.IsNullOrWhiteSpace(parameters[nameof(Query)]))
            {
                Query = parameters[nameof(Query)];
                urlParams.Add(new QueryParameter("query", Query));
            }
            else
            {
                throw new ArgumentNullException(nameof(Query), "Query filter in where clause is required.");
            }

            if (parameters.ContainsKey(nameof(EndTime)))
            {
                EndTime = DateTime.Parse(parameters[nameof(EndTime)]);
                urlParams.Add(new QueryParameter("end_time", EndTime.ToString(L2TKeys.ISO8601, CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(Expansions)))
            {
                Expansions = parameters[nameof(Expansions)];
                urlParams.Add(new QueryParameter("expansions", Expansions.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(MaxResults)))
            {
                MaxResults = int.Parse(parameters[nameof(MaxResults)]);
                urlParams.Add(new QueryParameter("max_results", MaxResults.ToString(CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(MediaFields)))
            {
                MediaFields = parameters[nameof(MediaFields)];
                urlParams.Add(new QueryParameter("media.fields", MediaFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(NextToken)))
            {
                NextToken = parameters[nameof(NextToken)];
                urlParams.Add(new QueryParameter("next_token", NextToken));
            }

            if (parameters.ContainsKey(nameof(PlaceFields)))
            {
                PlaceFields = parameters[nameof(PlaceFields)];
                urlParams.Add(new QueryParameter("place.fields", PlaceFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(PollFields)))
            {
                PollFields = parameters[nameof(PollFields)];
                urlParams.Add(new QueryParameter("poll.fields", PollFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(SinceID)))
            {
                SinceID = parameters[nameof(SinceID)];
                urlParams.Add(new QueryParameter("since_id", SinceID));
            }

            if (parameters.ContainsKey(nameof(StartTime)))
            {
                StartTime = DateTime.Parse(parameters[nameof(StartTime)]);
                urlParams.Add(new QueryParameter("start_time", StartTime.ToString(L2TKeys.ISO8601, CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(TweetFields)))
            {
                TweetFields = parameters[nameof(TweetFields)];
                urlParams.Add(new QueryParameter("tweet.fields", TweetFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(UntilID)))
            {
                UntilID = parameters[nameof(UntilID)];
                urlParams.Add(new QueryParameter("until_id", UntilID));
            }

            if (parameters.ContainsKey(nameof(UserFields)))
            {
                UserFields = parameters[nameof(UserFields)];
                urlParams.Add(new QueryParameter("user.fields", UserFields.Replace(" ", "")));
            }

            return(req);
        }
Example #12
0
        /// <summary>
        /// builds url based on input parameters
        /// </summary>
        /// <param name="parameters">criteria for url segments and parameters</param>
        /// <returns>URL conforming to Twitter API</returns>
        public Request BuildUrl(Dictionary <string, string> parameters)
        {
            if (parameters.ContainsKey(nameof(Type)))
            {
                Type = RequestProcessorHelper.ParseEnum <SearchType>(parameters[nameof(Type)]);
            }
            else
            {
                throw new ArgumentException($"{nameof(Type)} is required", nameof(Type));
            }

            string urlSegment = Type switch
            {
                SearchType.FullSearch => "tweets/search/all",
                SearchType.RecentSearch => "tweets/search/recent",
                _ => throw new ArgumentException($"Unknown SearchType: '{Type}'")
            };

            return(BuildSearchUrlParameters(parameters, urlSegment));
        }

        /// <summary>
        /// appends parameters for Search request
        /// </summary>
        /// <param name="parameters">list of parameters from expression tree</param>
        /// <param name="url">base url</param>
        /// <returns>base url + parameters</returns>
        Request BuildSearchUrlParameters(Dictionary <string, string> parameters, string url)
        {
            var req       = new Request(BaseUrl + url);
            var urlParams = req.RequestParameters;


            if (parameters.ContainsKey(nameof(Query)) && !string.IsNullOrWhiteSpace(parameters[nameof(Query)]))
            {
                Query = parameters[nameof(Query)];
                urlParams.Add(new QueryParameter("query", Query));
            }
            else
            {
                throw new ArgumentNullException(nameof(Query), "Query filter in where clause is required.");
            }

            if (parameters.ContainsKey(nameof(EndTime)))
            {
                EndTime = DateTime.Parse(parameters[nameof(EndTime)]);
                urlParams.Add(new QueryParameter("end_time", EndTime.ToString(L2TKeys.ISO8601, CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(Expansions)))
            {
                Expansions = parameters[nameof(Expansions)];
                urlParams.Add(new QueryParameter("expansions", Expansions.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(MaxResults)))
            {
                MaxResults = int.Parse(parameters[nameof(MaxResults)]);
                urlParams.Add(new QueryParameter("max_results", MaxResults.ToString(CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(MediaFields)))
            {
                MediaFields = parameters[nameof(MediaFields)];
                urlParams.Add(new QueryParameter("media.fields", MediaFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(NextToken)))
            {
                NextToken = parameters[nameof(NextToken)];
                urlParams.Add(new QueryParameter("next_token", NextToken));
            }

            if (parameters.ContainsKey(nameof(PlaceFields)))
            {
                PlaceFields = parameters[nameof(PlaceFields)];
                urlParams.Add(new QueryParameter("place.fields", PlaceFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(PollFields)))
            {
                PollFields = parameters[nameof(PollFields)];
                urlParams.Add(new QueryParameter("poll.fields", PollFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(SinceID)))
            {
                SinceID = parameters[nameof(SinceID)];
                urlParams.Add(new QueryParameter("since_id", SinceID));
            }

            if (parameters.ContainsKey(nameof(StartTime)))
            {
                StartTime = DateTime.Parse(parameters[nameof(StartTime)]);
                urlParams.Add(new QueryParameter("start_time", StartTime.ToString(L2TKeys.ISO8601, CultureInfo.InvariantCulture)));
            }

            if (parameters.ContainsKey(nameof(TweetFields)))
            {
                TweetFields = parameters[nameof(TweetFields)];
                urlParams.Add(new QueryParameter("tweet.fields", TweetFields.Replace(" ", "")));
            }

            if (parameters.ContainsKey(nameof(UntilID)))
            {
                UntilID = parameters[nameof(UntilID)];
                urlParams.Add(new QueryParameter("until_id", UntilID));
            }

            if (parameters.ContainsKey(nameof(UserFields)))
            {
                UserFields = parameters[nameof(UserFields)];
                urlParams.Add(new QueryParameter("user.fields", UserFields.Replace(" ", "")));
            }

            return(req);
        }