/// <summary> /// appends parameters for <see cref="Tweet"/> request /// </summary> /// <param name="parameters">list of parameters from expression tree</param> /// <param name="url">base url</param> /// <returns>base url + parameters</returns> Request BuildUrlParameters(Dictionary <string, string> parameters, string url) { var req = new Request(BaseUrl + url); var urlParams = req.RequestParameters; if (parameters.ContainsKey(nameof(Ids))) { Ids = parameters[nameof(Ids)]; urlParams.Add(new QueryParameter("ids", Ids.Replace(" ", ""))); } else { throw new ArgumentException($"{nameof(Ids)} is required", nameof(Ids)); } if (parameters.ContainsKey(nameof(Expansions))) { Expansions = parameters[nameof(Expansions)]; urlParams.Add(new QueryParameter("expansions", Expansions.Replace(" ", ""))); } if (parameters.ContainsKey(nameof(MediaFields))) { MediaFields = parameters[nameof(MediaFields)]; urlParams.Add(new QueryParameter("media.fields", MediaFields.Replace(" ", ""))); } 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(TweetFields))) { TweetFields = parameters[nameof(TweetFields)]; urlParams.Add(new QueryParameter("tweet.fields", TweetFields.Replace(" ", ""))); } if (parameters.ContainsKey(nameof(UserFields))) { UserFields = parameters[nameof(UserFields)]; urlParams.Add(new QueryParameter("user.fields", UserFields.Replace(" ", ""))); } return(req); }
/// <summary> /// appends parameters for Tweet request /// </summary> /// <param name="parameters">list of parameters from expression tree</param> /// <param name="url">base url</param> /// <returns>base url + parameters</returns> void BuildUrlParameters(Dictionary <string, string> parameters, IList <QueryParameter> urlParams) { if (parameters.ContainsKey(nameof(Expansions))) { Expansions = parameters[nameof(Expansions)]; urlParams.Add(new QueryParameter("expansions", Expansions.Replace(" ", ""))); } if (parameters.ContainsKey(nameof(MediaFields))) { MediaFields = parameters[nameof(MediaFields)]; urlParams.Add(new QueryParameter("media.fields", MediaFields.Replace(" ", ""))); } 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(TweetFields))) { TweetFields = parameters[nameof(TweetFields)]; urlParams.Add(new QueryParameter("tweet.fields", TweetFields.Replace(" ", ""))); } if (parameters.ContainsKey(nameof(UserFields))) { UserFields = parameters[nameof(UserFields)]; urlParams.Add(new QueryParameter("user.fields", UserFields.Replace(" ", ""))); } if (parameters.ContainsKey(nameof(Ids))) { Ids = parameters[nameof(Ids)]; urlParams.Add(new QueryParameter("ids", Ids.Replace(" ", ""))); } }
/// <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); }
/// <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); }