/// <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 <StreamingType>(parameters["Type"]);
            }
            else
            {
                throw new ArgumentException($"{nameof(Type)} is required", nameof(Type));
            }

            string segment = Type == StreamingType.Filter ? "tweets/search/stream" : "tweets/sample/stream";

            bool isStreaming = true;

            if (Type == StreamingType.Rules)
            {
                segment     = "tweets/search/stream/rules";
                isStreaming = false;
            }

            var req = new Request(BaseUrl + segment)
            {
                IsStreaming = isStreaming
            };
            var urlParams = req.RequestParameters;

            BuildUrlParameters(parameters, urlParams);

            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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <DirectMessageType>(parameters["Type"]);

            switch (Type)
            {
            case DirectMessageType.SentBy:
                return(BuildSentByUrl(parameters));

            case DirectMessageType.SentTo:
                return(BuildSentToUrl(parameters));

            case DirectMessageType.Show:
                return(BuildShowUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
        /// <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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            if (parameters == null || !parameters.ContainsKey(nameof(Type)))
            {
                throw new ArgumentException($"You must set {nameof(Type)}.", nameof(Type));
            }

            Type = RequestProcessorHelper.ParseEnum <WelcomeMessageType>(parameters[nameof(Type)]);

            switch (Type)
            {
            case WelcomeMessageType.ListMessages:
                return(BuildListMessagesUrl(parameters));

            case WelcomeMessageType.ListRules:
                return(BuildListRulesUrl(parameters));

            case WelcomeMessageType.ShowMessage:
                return(BuildShowMessagesUrl(parameters));

            case WelcomeMessageType.ShowRule:
                return(BuildShowRuleUrl(parameters));

            default:
                throw new InvalidOperationException(
                          $"Didn't recognize '{Type}' for {nameof(Type)} parameter in WelcomeMessageRequestProcessor.BuildUrl.");
            }
        }
Example #4
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)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <StreamingType>(parameters["Type"]);

            switch (Type)
            {
            case StreamingType.Filter:
                return(BuildFilterUrl(parameters));

            case StreamingType.Firehose:
                return(BuildFirehoseUrl(parameters));

            case StreamingType.Sample:
                return(BuildSampleUrl(parameters));

            case StreamingType.Site:
                return(BuildSiteUrl(parameters));

            case StreamingType.User:
                return(BuildUserUrl(parameters));

            default:
                break;
            }

            return(null);
        }
        public Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <HelpType>(parameters["Type"]);

            switch (Type)
            {
            case HelpType.Configuration:
                return(new Request(BaseUrl + "help/configuration.json"));

            case HelpType.Languages:
                return(new Request(BaseUrl + "help/languages.json"));

            case HelpType.Privacy:
                return(new Request(BaseUrl + "help/privacy.json"));

            case HelpType.RateLimits:
                return(BuildRateLimitsUrl(parameters));

            case HelpType.Tos:
                return(new Request(BaseUrl + "help/tos.json"));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
Example #6
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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <TrendType>(parameters["Type"]);

            switch (Type)
            {
            case TrendType.Available:
                return(BuildAvailableTrendsUrl());

            case TrendType.Closest:
                return(BuildClosestTrendsUrl(parameters));

            case TrendType.Place:
                return(BuildPlaceTrendsUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
Example #7
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 <TweetType>(parameters[nameof(Type)]);
            }
            else
            {
                throw new ArgumentException($"{nameof(Type)} is required", nameof(Type));
            }

            Type = RequestProcessorHelper.ParseEnum <TweetType>(parameters[nameof(Type)]);

            switch (Type)
            {
            case TweetType.Lookup:
                return(BuildLookupUrl(parameters));

            case TweetType.MentionsTimeline:
                return(BuildMentionsTimelineUrl(parameters));

            case TweetType.TweetsTimeline:
                return(BuildUserTimelineUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
        /// <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)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <GeoType>(parameters["Type"]);

            switch (Type)
            {
            case GeoType.ID:
                return(BuildIDUrl(parameters));

            case GeoType.Reverse:
                return(BuildReverseUrl(parameters));

            case GeoType.Search:
                return(BuildSearchUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
Example #9
0
        Request BuildRetweetersUrl(Dictionary <string, string> parameters)
        {
            if (!parameters.ContainsKey("ID"))
            {
                throw new ArgumentException("ID is required.", "ID");
            }

            var url       = BaseUrl + "statuses/retweeters/ids.json";
            var req       = new Request(url);
            var urlParams = req.RequestParameters;

            ID = ulong.Parse(parameters["ID"]);
            urlParams.Add(new QueryParameter("id", parameters["ID"]));

            if (parameters.ContainsKey("Cursor"))
            {
                Cursor = long.Parse(parameters["Cursor"]);

                urlParams.Add(new QueryParameter("cursor", parameters["Cursor"]));
            }

            if (parameters.ContainsKey(nameof(TweetMode)))
            {
                TweetMode = RequestProcessorHelper.ParseEnum <TweetMode>(parameters[nameof(TweetMode)]);
                urlParams.Add(new QueryParameter("tweet_mode", TweetMode.ToString().ToLower()));
            }

            return(req);
        }
Example #10
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("Type"))
            {
                Type = RequestProcessorHelper.ParseEnum <SearchType>(parameters["Type"]);
            }
            else
            {
                throw new ArgumentException("Type is required", "Type");
            }

            return(BuildSearchUrlParameters(parameters, "search/tweets.json"));
        }
Example #11
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 <TweetType>(parameters[nameof(Type)]);
            }
            else
            {
                throw new ArgumentException($"{nameof(Type)} is required", nameof(Type));
            }

            return(BuildUrlParameters(parameters, "tweets"));
        }
Example #12
0
        /// <summary>
        /// appends parameters for Favorites request
        /// </summary>
        /// <param name="parameters">list of parameters from expression tree</param>
        /// <param name="url">base url</param>
        /// <returns>base url + parameters</returns>
        Request BuildFavoritesUrlParameters(Dictionary <string, string> parameters)
        {
            var req       = new Request(BaseUrl + "favorites/list.json");
            var urlParams = req.RequestParameters;

            if (parameters.ContainsKey("UserID"))
            {
                UserID = ulong.Parse(parameters["UserID"]);
                urlParams.Add(new QueryParameter("user_id", parameters["UserID"]));
            }

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

            if (parameters.ContainsKey("Count"))
            {
                Count = int.Parse(parameters["Count"]);
                urlParams.Add(new QueryParameter("count", parameters["Count"]));
            }

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

            if (parameters.ContainsKey("MaxID"))
            {
                MaxID = ulong.Parse(parameters["MaxID"]);
                urlParams.Add(new QueryParameter("max_id", parameters["MaxID"]));
            }

            if (parameters.ContainsKey("IncludeEntities"))
            {
                IncludeEntities = bool.Parse(parameters["IncludeEntities"]);
                urlParams.Add(new QueryParameter("include_entities", parameters["IncludeEntities"].ToLower()));
            }

            if (parameters.ContainsKey(nameof(TweetMode)))
            {
                TweetMode = RequestProcessorHelper.ParseEnum <TweetMode>(parameters[nameof(TweetMode)]);
                urlParams.Add(new QueryParameter("tweet_mode", TweetMode.ToString().ToLower()));
            }

            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 virtual Request BuildUrl(Dictionary<string, string> parameters)
        {
            const string TypeParam = "Type";
            const string ParamsParam = "parameters";

            if (parameters == null)
                throw new ArgumentException("You must pass a \"parameters\" Dictionary<string, string> parameter.", ParamsParam);

            if (!parameters.ContainsKey("Type"))
                throw new ArgumentException("You must set Type.", TypeParam);

            Type = RequestProcessorHelper.ParseEnum<FavoritesType>(parameters["Type"]);

            return BuildFavoritesUrlParameters(parameters);
        }
Example #14
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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <StatusType>(parameters["Type"]);

            switch (Type)
            {
            case StatusType.Conversation:
                return(BuildConversationUrl(parameters));

            case StatusType.Home:
                return(BuildHomeUrl(parameters));

            case StatusType.Lookup:
                return(BuildLookupUrl(parameters));

            case StatusType.Mentions:
                return(BuildMentionsUrl(parameters));

            case StatusType.Oembed:
                return(BuildOembedUrl(parameters));

            case StatusType.RetweetsOfMe:
                return(BuildRetweetsOfMeUrl(parameters));

            case StatusType.Retweets:
                return(BuildRetweets(parameters));

            case StatusType.Show:
                return(BuildShowUrl(parameters));

            case StatusType.User:
                return(BuildUserUrl(parameters));

            case StatusType.Retweeters:
                return(BuildRetweetersUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
        /// <summary>
        /// builds a url to show user info
        /// </summary>
        /// <param name="parameters">url parameters</param>
        /// <returns>new url for request</returns>
        Request BuildShowUrl(Dictionary <string, string> parameters)
        {
            if (!parameters.ContainsKey("UserID") &&
                !parameters.ContainsKey("ScreenName"))
            {
                throw new ArgumentException("Parameters must include either UserID or ScreenName.", ScreenNameOrUserID);
            }

            if (parameters.ContainsKey("UserID") && string.IsNullOrWhiteSpace(parameters["UserID"]))
            {
                throw new ArgumentNullException("UserID", "If specified, UserID can't be null or an empty string.");
            }

            if (parameters.ContainsKey("ScreenName") && string.IsNullOrWhiteSpace(parameters["ScreenName"]))
            {
                throw new ArgumentNullException("ScreenName", "If specified, ScreenName can't be null or an empty string.");
            }

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

            if (parameters.ContainsKey("UserID"))
            {
                UserID = ulong.Parse(parameters["UserID"]);
                urlParams.Add(new QueryParameter("user_id", parameters["UserID"]));
            }

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

            if (parameters.ContainsKey("IncludeEntities"))
            {
                IncludeEntities = bool.Parse(parameters["IncludeEntities"]);
                urlParams.Add(new QueryParameter("include_entities", parameters["IncludeEntities"].ToLower()));
            }

            if (parameters.ContainsKey(nameof(TweetMode)))
            {
                TweetMode = RequestProcessorHelper.ParseEnum <TweetMode>(parameters[nameof(TweetMode)]);
                urlParams.Add(new QueryParameter("tweet_mode", TweetMode.ToString().ToLower()));
            }

            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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            if (parameters == null || !parameters.ContainsKey(nameof(Type)))
            {
                throw new ArgumentException($"You must set {nameof(Type)}.", nameof(Type));
            }

            Type = RequestProcessorHelper.ParseEnum <DirectMessageEventsType>(parameters[nameof(Type)]);

            return(Type switch
            {
                DirectMessageEventsType.List => BuildListUrl(parameters),
                DirectMessageEventsType.Show => BuildShowUrl(parameters),
                _ => throw new InvalidOperationException(
                    $"Didn't recognize '{Type}' for {nameof(Type)} parameter in " +
                    $"DirectMessageEventsRequestProcessor.BuildUrl."),
            });
Example #17
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 <UserType>(parameters["Type"]);
            }
            else
            {
                throw new ArgumentException($"{nameof(Type)} is required", nameof(Type));
            }

            return(Type switch
            {
                UserType.IdLookup => BuildIdLookupUrl(parameters),
                UserType.UsernameLookup => BuildUsernameLookupUrl(parameters),
                _ => throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified."),
            });
Example #18
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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <AccountType>(parameters[TypeParam]);

            return(Type switch
            {
                AccountType.VerifyCredentials => BuildVerifyCredentialsUrl(parameters),
                AccountType.Settings => new Request(BaseUrl + "account/settings.json"),
                _ => throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified."),
            });
Example #19
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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            if (parameters == null || !parameters.ContainsKey(TypeParam))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <ListType>(parameters[TypeParam]);

            switch (Type)
            {
            case ListType.List:
                return(BuildListUrl(parameters));

            case ListType.Show:
                return(BuildShowUrl(parameters));

            case ListType.Statuses:
                return(BuildStatusesUrl(parameters));

            case ListType.Memberships:
                return(BuildMembershipsUrl(parameters));

            case ListType.Subscriptions:
                return(BuildSubscriptionsUrl(parameters));

            case ListType.Members:
                return(BuildMembersUrl(parameters));

            case ListType.IsMember:
                return(BuildIsMemberUrl(parameters));

            case ListType.Subscribers:
                return(BuildSubscribersUrl(parameters));

            case ListType.IsSubscriber:
                return(BuildIsSubcribedUrl(parameters));

            case ListType.Ownerships:
                return(BuildOwnershipsUrl(parameters));

            default:
                throw new ArgumentException("Invalid ListType", TypeParam);
            }
        }
Example #20
0
        Request BuildLookupUrl(Dictionary <string, string> parameters)
        {
            if (!parameters.ContainsKey("TweetIDs") || string.IsNullOrWhiteSpace(parameters["TweetIDs"]))
            {
                throw new ArgumentNullException("TweetIDs", "TweetIDs is required");
            }

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

            TweetIDs = parameters["TweetIDs"].Replace(" ", "");
            urlParams.Add(new QueryParameter("id", TweetIDs));

            if (parameters.ContainsKey("IncludeEntities"))
            {
                IncludeEntities = bool.Parse(parameters["IncludeEntities"]);
                urlParams.Add(new QueryParameter("include_entities", parameters["IncludeEntities"].ToLower()));
            }

            if (parameters.ContainsKey("Map"))
            {
                Map = bool.Parse(parameters["Map"]);
                urlParams.Add(new QueryParameter("map", parameters["Map"].ToLower()));
            }

            if (parameters.ContainsKey("TrimUser"))
            {
                TrimUser = bool.Parse(parameters["TrimUser"]);
                urlParams.Add(new QueryParameter("trim_user", parameters["TrimUser"].ToLower()));
            }

            if (parameters.ContainsKey(nameof(TweetMode)))
            {
                TweetMode = RequestProcessorHelper.ParseEnum <TweetMode>(parameters[nameof(TweetMode)]);
                urlParams.Add(new QueryParameter("tweet_mode", TweetMode.ToString().ToLower()));
            }

            if (parameters.ContainsKey(nameof(IncludeAltText)))
            {
                IncludeAltText = bool.Parse(parameters[nameof(IncludeAltText)]);
                urlParams.Add(new QueryParameter("include_ext_alt_text", parameters[nameof(IncludeAltText)].ToLower()));
            }

            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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            if (parameters == null || !parameters.ContainsKey(nameof(Type)))
            {
                throw new ArgumentException("You must set Type.", nameof(Type));
            }

            Type = RequestProcessorHelper.ParseEnum <MediaType>(parameters[nameof(Type)]);

            switch (Type)
            {
            case MediaType.Status:
                return(BuildStatusUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
        /// <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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <UserType>(parameters["Type"]);

            switch (Type)
            {
            case UserType.Show:
                return(BuildShowUrl(parameters));

            case UserType.Categories:
                return(BuildCategoriesUrl(parameters));

            case UserType.Category:
                return(BuildUsersInCategoryUrl(parameters));

            case UserType.CategoryStatus:
                return(BuildCategoryStatusUrl(parameters));

            case UserType.Lookup:
                return(BuildLookupUrl(parameters));

            case UserType.Search:
                return(BuildSearchUrl(parameters));

            case UserType.Contributees:
                return(BuildContributeesUrl(parameters));

            case UserType.Contributors:
                return(BuildContributorsUrl(parameters));

            case UserType.BannerSizes:
                return(BuildBannerSizesUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
Example #23
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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <FriendshipType>(parameters["Type"]);

            switch (Type)
            {
            case FriendshipType.Incoming:
                return(BuildFriendshipIncomingUrl(parameters));

            case FriendshipType.Lookup:
                return(BuildLookupUrl(parameters));

            case FriendshipType.Outgoing:
                return(BuildFriendshipOutgoingUrl(parameters));

            case FriendshipType.Show:
                return(BuildFriendshipShowUrl(parameters));

            case FriendshipType.NoRetweetIDs:
                return(BuildFriendshipNoRetweetIDsUrl());

            case FriendshipType.FollowersList:
                return(BuildFollowersListUrl(parameters));

            case FriendshipType.FriendsList:
                return(BuildFriendsListUrl(parameters));

            case FriendshipType.FollowerIDs:
                return(BuildFollowerIDsUrl(parameters));

            case FriendshipType.FriendIDs:
                return(BuildFriendIDsUrl(parameters));

            default:
                throw new ArgumentException("Invalid FriendshipType", "Type");
            }
        }
        /// <summary>
        /// Builds a URL to perform a user search
        /// </summary>
        /// <param name="parameters">Query, Page, and Count</param>
        /// <returns>URL for performing user search</returns>
        Request BuildSearchUrl(Dictionary <string, string> parameters)
        {
            const string QueryParam = "Query";

            if (!parameters.ContainsKey("Query"))
            {
                throw new ArgumentException("Query parameter is required.", QueryParam);
            }

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

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

            if (parameters.ContainsKey("Page"))
            {
                Page = int.Parse(parameters["Page"]);
                urlParams.Add(new QueryParameter("page", parameters["Page"]));
            }

            if (parameters.ContainsKey("Count"))
            {
                Count = int.Parse(parameters["Count"]);
                urlParams.Add(new QueryParameter("count", parameters["Count"]));
            }

            if (parameters.ContainsKey("IncludeEntities"))
            {
                IncludeEntities = bool.Parse(parameters["IncludeEntities"]);
                urlParams.Add(new QueryParameter("include_entities", parameters["IncludeEntities"].ToLower()));
            }

            if (parameters.ContainsKey(nameof(TweetMode)))
            {
                TweetMode = RequestProcessorHelper.ParseEnum <TweetMode>(parameters[nameof(TweetMode)]);
                urlParams.Add(new QueryParameter("tweet_mode", TweetMode.ToString().ToLower()));
            }

            return(req);
        }
Example #25
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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            const string TypeParam = "Type";

            if (parameters == null || !parameters.ContainsKey(nameof(Type)))
            {
                throw new ArgumentException("You must set Type.", TypeParam);
            }

            Type = RequestProcessorHelper.ParseEnum <UserType>(parameters["Type"]);

            return(Type switch
            {
                UserType.Search => BuildSearchUrl(parameters),
                UserType.Contributees => BuildContributeesUrl(parameters),
                UserType.Contributors => BuildContributorsUrl(parameters),
                UserType.BannerSizes => BuildBannerSizesUrl(parameters),
                _ => throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified."),
            });
        Request BuildContributeesUrl(Dictionary <string, string> parameters)
        {
            if (!(parameters.ContainsKey("ScreenName") || parameters.ContainsKey("UserID")) ||
                (parameters.ContainsKey("ScreenName") && parameters.ContainsKey("UserID")))
            {
                throw new ArgumentException("Query must contain one of either ScreenName or UserID parameters, but not both.", ScreenNameOrUserID);
            }

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

            if (parameters.ContainsKey("UserID"))
            {
                UserID = ulong.Parse(parameters["UserID"]);
                urlParams.Add(new QueryParameter("user_id", parameters["UserID"]));
            }

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

            if (parameters.ContainsKey("IncludeEntities"))
            {
                IncludeEntities = bool.Parse(parameters["IncludeEntities"]);
                urlParams.Add(new QueryParameter("include_entities", parameters["IncludeEntities"].ToLower()));
            }

            if (parameters.ContainsKey("SkipStatus"))
            {
                SkipStatus = bool.Parse(parameters["SkipStatus"]);
                urlParams.Add(new QueryParameter("skip_status", parameters["SkipStatus"].ToLower()));
            }

            if (parameters.ContainsKey(nameof(TweetMode)))
            {
                TweetMode = RequestProcessorHelper.ParseEnum <TweetMode>(parameters[nameof(TweetMode)]);
                urlParams.Add(new QueryParameter("tweet_mode", TweetMode.ToString().ToLower()));
            }

            return(req);
        }
Example #27
0
        Request BuildConversationUrl(Dictionary <string, string> parameters)
        {
            if (!parameters.ContainsKey("ID") || string.IsNullOrWhiteSpace(parameters["ID"]))
            {
                throw new ArgumentNullException("ID", "ID is required");
            }

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

            ID = ulong.Parse(parameters["ID"]);
            urlParams.Add(new QueryParameter("id", parameters["ID"]));

            if (parameters.ContainsKey(nameof(TweetMode)))
            {
                TweetMode = RequestProcessorHelper.ParseEnum <TweetMode>(parameters[nameof(TweetMode)]);
                urlParams.Add(new QueryParameter("tweet_mode", TweetMode.ToString().ToLower()));
            }

            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 == null || !parameters.ContainsKey("Type"))
            {
                throw new ArgumentException("You must set Type.", "Type");
            }

            Type = RequestProcessorHelper.ParseEnum <SavedSearchType>(parameters["Type"]);

            switch (Type)
            {
            case SavedSearchType.Searches:
                return(BuildSearchesUrl());

            case SavedSearchType.Show:
                return(BuildShowUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }
        /// <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 virtual Request BuildUrl(Dictionary <string, string> parameters)
        {
            if (parameters == null || !parameters.ContainsKey(nameof(Type)))
            {
                throw new ArgumentException($"You must set {nameof(Type)}.", nameof(Type));
            }

            Type = RequestProcessorHelper.ParseEnum <AccountActivityType>(parameters[nameof(Type)]);

            switch (Type)
            {
            case AccountActivityType.Subscriptions:
                return(BuildSubscriptionsUrl(parameters));

            case AccountActivityType.Webhooks:
                return(BuildWebhooksUrl(parameters));

            default:
                throw new InvalidOperationException(
                          $"Didn't recognize '{Type}' for {nameof(Type)} parameter in AccountActivityRequestProcessor.BuildUrl.");
            }
        }
Example #30
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 <ComplianceType>(parameters[nameof(Type)]);
            }
            else
            {
                throw new ArgumentException($"{nameof(Type)} is required", nameof(Type));
            }

            switch (Type)
            {
            case ComplianceType.MultipleJobs:
                return(BuildMultipleJobsUrlParameters(parameters));

            case ComplianceType.SingleJob:
                return(BuildSingleJobUrl(parameters));

            default:
                throw new InvalidOperationException("The default case of BuildUrl should never execute because a Type must be specified.");
            }
        }