Exemple #1
0
        /// <summary>
        /// Removes one or more users from a Site Stream
        /// </summary>
        /// <param name="userIDs">List of user IDs to remove from Site Stream</param>
        /// <param name="streamID">ID of Site Stream to remove users from</param>
        /// <returns>Control Stream with CommandResponse property for Twitter's response message</returns>
        public async Task <ControlStream> RemoveSiteStreamUserAsync(List <ulong> userIDs, string streamID, CancellationToken cancelToken = default(CancellationToken))
        {
            if (string.IsNullOrWhiteSpace(streamID))
            {
                throw new ArgumentNullException("streamID", "streamID is required.");
            }

            var newUrl = SiteStreamUrl + "site/c/" + streamID + "/remove_user.json";

            string userIDString = string.Join(",", userIDs.Select(user => user.ToString()).ToArray());

            var reqProc = new ControlStreamRequestProcessor <ControlStream>();

            var resultsJson =
                await TwitterExecutor.PostToTwitterAsync <ControlStream>(
                    newUrl,
                    new Dictionary <string, string>
            {
                { "user_id", userIDString }
            },
                    cancelToken)
                .ConfigureAwait(false);

            return(reqProc.ProcessActionResult(resultsJson, ControlStreamType.Info));
        }
        /// <summary>
        /// Removes one or more users from a Site Stream
        /// </summary>
        /// <param name="ctx">Twitter Context</param>
        /// <param name="userIDs">List of user IDs to remove from Site Stream</param>
        /// <param name="streamID">ID of Site Stream to remove users from</param>
        /// <param name="callback">Async Callback</param>
        /// <returns>Control Stream with CommandResponse property for Twitter's response message</returns>
        public static ControlStream RemoveSiteStreamUser(this TwitterContext ctx, List<ulong> userIDs, string streamID, Action<TwitterAsyncResponse<ControlStream>> callback)
        {
            if (string.IsNullOrEmpty(streamID)) throw new ArgumentNullException("streamID", "streamID is required.");

            var newUrl = ctx.SiteStreamUrl + "site/c/" + streamID + "/remove_user.json";

            string userIDString = string.Join(",", userIDs.Select(user => user.ToString()).ToArray());

            var reqProc = new ControlStreamRequestProcessor<ControlStream>();

            var twitExe = ctx.TwitterExecutor;

            twitExe.AsyncCallback = callback;
            var resultsJson =
                twitExe.PostToTwitter(
                    newUrl,
                    new Dictionary<string, string>
                    {
                        {"user_id", userIDString}
                    },
                    response => reqProc.ProcessActionResult(response, ControlStreamType.Info));

            ControlStream cs = reqProc.ProcessActionResult(resultsJson, ControlStreamType.Info);
            return cs;
        }
        protected internal IRequestProcessor <T> CreateRequestProcessor <T>(string requestType)
            where T : class
        {
            var baseUrl = BaseUrl;
            IRequestProcessor <T> req;

            switch (requestType)
            {
            case "Account":
                req = new AccountRequestProcessor <T>();
                break;

            case "Blocks":
                req = new BlocksRequestProcessor <T>();
                break;

            case "ControlStream":
                req = new ControlStreamRequestProcessor <T>
                {
                    SiteStreamUrl = SiteStreamUrl
                };
                break;

            case "DirectMessage":
                req = new DirectMessageRequestProcessor <T>();
                break;

            case "Favorites":
                req = new FavoritesRequestProcessor <T>();
                break;

            case "Friendship":
                req = new FriendshipRequestProcessor <T>();
                break;

            case "Geo":
                req = new GeoRequestProcessor <T>();
                break;

            case "Help":
                req = new HelpRequestProcessor <T>();
                break;

            case "List":
                req = new ListRequestProcessor <T>();
                break;

            case "Mute":
                req = new MuteRequestProcessor <T>();
                break;

            case "Raw":
                req = new RawRequestProcessor <T>();
                break;

            case "SavedSearch":
                req = new SavedSearchRequestProcessor <T>();
                break;

            case "Search":
                req = new SearchRequestProcessor <T>();
                break;

            case "Status":
                req = new StatusRequestProcessor <T>();
                break;

            case "Streaming":
                baseUrl = StreamingUrl;
                req     = new StreamingRequestProcessor <T>
                {
                    UserStreamUrl   = UserStreamUrl,
                    SiteStreamUrl   = SiteStreamUrl,
                    TwitterExecutor = TwitterExecutor
                };
                break;

            case "Trend":
                req = new TrendRequestProcessor <T>();
                break;

            case "User":
                req = new UserRequestProcessor <T>();
                break;

            case "Vine":
                req = new VineRequestProcessor <T>
                {
                    VineUrl = VineUrl
                };
                break;

            default:
                throw new ArgumentException("Type, " + requestType + " isn't a supported LINQ to Twitter entity.", "requestType");
            }

            if (baseUrl != null)
            {
                req.BaseUrl = baseUrl;
            }

            return(req);
        }
Exemple #4
0
        protected internal IRequestProcessor <T> CreateRequestProcessor <T>(string requestType)
            where T : class
        {
            string baseUrl = BaseUrl;
            IRequestProcessor <T> req;

            switch (requestType)
            {
            case nameof(Account):
                req = new AccountRequestProcessor <T>();
                break;

            case nameof(AccountActivity):
                req = new AccountActivityRequestProcessor <T>();
                break;

            case nameof(Blocks):
                req = new BlocksRequestProcessor <T>();
                break;

            case nameof(ControlStream):
                req = new ControlStreamRequestProcessor <T>
                {
                    SiteStreamUrl = SiteStreamUrl
                };
                break;

            case nameof(DirectMessage):
                req = new DirectMessageRequestProcessor <T>();
                break;

            case nameof(DirectMessageEvents):
                req = new DirectMessageEventsRequestProcessor <T>();
                break;

            case nameof(Favorites):
                req = new FavoritesRequestProcessor <T>();
                break;

            case nameof(Friendship):
                req = new FriendshipRequestProcessor <T>();
                break;

            case nameof(Geo):
                req = new GeoRequestProcessor <T>();
                break;

            case nameof(Help):
                req = new HelpRequestProcessor <T>();
                break;

            case nameof(List):
                req = new ListRequestProcessor <T>();
                break;

            case nameof(Media):
                req = new MediaRequestProcessor <T>
                {
                    UploadUrl = UploadUrl
                };
                break;

            case nameof(Mute):
                req = new MuteRequestProcessor <T>();
                break;

            case nameof(Raw):
                req = new RawRequestProcessor <T>();
                break;

            case nameof(SavedSearch):
                req = new SavedSearchRequestProcessor <T>();
                break;

            case nameof(Search):
                req = new SearchRequestProcessor <T>();
                break;

            case nameof(Status):
                req = new StatusRequestProcessor <T>();
                break;

            case nameof(Streaming):
                baseUrl = StreamingUrl;
                req     = new StreamingRequestProcessor <T>
                {
                    UserStreamUrl   = UserStreamUrl,
                    SiteStreamUrl   = SiteStreamUrl,
                    TwitterExecutor = TwitterExecutor
                };
                break;

            case nameof(Trend):
                req = new TrendRequestProcessor <T>();
                break;

            case nameof(User):
                req = new UserRequestProcessor <T>();
                break;

            case nameof(Vine):
                req = new VineRequestProcessor <T>
                {
                    VineUrl = VineUrl
                };
                break;

            case nameof(WelcomeMessage):
                req = new WelcomeMessageRequestProcessor <T>();
                break;

            default:
                throw new ArgumentException($"Type, {requestType} isn't a supported LINQ to Twitter entity.", nameof(requestType));
            }

            if (baseUrl != null)
            {
                req.BaseUrl = baseUrl;
            }

            return(req);
        }