/// <summary>
        /// Deletes an existing welcome message rule.
        /// <param name="welcomeMessageRuleID">ID of the welcome message rule.</param>
        /// <param name="cancelToken">Async cancellation token.</param>
        public async Task DeleteWelcomeMessageRuleAsync(ulong welcomeMessageRuleID, CancellationToken cancelToken = default(CancellationToken))
        {
            if (welcomeMessageRuleID == 0)
            {
                throw new ArgumentException($"{nameof(welcomeMessageRuleID)} is a required parameter, but it's value is 0, which is invalid.", nameof(welcomeMessageRuleID));
            }

            var newUrl = BaseUrl + "direct_messages/welcome_messages/rules/destroy.json?id=" + welcomeMessageRuleID;

            var postData = new Dictionary <string, string>
            {
                ["id"] = welcomeMessageRuleID.ToString()
            };

            RawResult =
                await TwitterExecutor.SendJsonToTwitterAsync(
                    HttpMethod.Delete.ToString(),
                    newUrl,
                    postData,
                    "",
                    cancelToken)
                .ConfigureAwait(false) ?? string.Empty;

            var            reqProc = new WelcomeMessageRequestProcessor <WelcomeMessage>();
            WelcomeMessage msg     = reqProc.ProcessActionResult(RawResult, WelcomeMessageType.ShowMessage);

            msg.ID = welcomeMessageRuleID;
        }
        /// <summary>
        /// Marks a welcome message as the default.
        /// </summary>
        /// <param name="welcomeMessageID">ID of the welcome message.</param>
        /// <param name="cancelToken">Async cancellation token.</param>
        /// <returns>Direct message events data.</returns>
        public async Task <WelcomeMessage> NewWelcomeMessageRuleAsync(ulong welcomeMessageID, CancellationToken cancelToken = default(CancellationToken))
        {
            if (welcomeMessageID == 0)
            {
                throw new ArgumentException($"{nameof(welcomeMessageID)} is a required parameter, but it's value is 0, which is invalid.", nameof(welcomeMessageID));
            }

            var newUrl = BaseUrl + "direct_messages/welcome_messages/rules/new.json";

            var msgParams = new WelcomeMessageValue
            {
                WelcomeMessageRule = new WelcomeMessageRule
                {
                    WelcomeMessageID = welcomeMessageID.ToString()
                }
            };

            RawResult =
                await TwitterExecutor.SendJsonToTwitterAsync(
                    HttpMethod.Post.ToString(),
                    newUrl,
                    new Dictionary <string, string>(),
                    msgParams,
                    cancelToken)
                .ConfigureAwait(false);

            var            reqProc = new WelcomeMessageRequestProcessor <WelcomeMessage>();
            WelcomeMessage msg     = reqProc.ProcessActionResult(RawResult, WelcomeMessageType.ShowMessage);

            msg.ID = welcomeMessageID;

            return(msg);
        }
        /// <summary>
        /// Updates an existing welcome message.
        /// <param name="welcomeMessageID">ID of the welcome message.</param>
        /// <paramref name="name">Updated welcome message name.</paramref>
        /// <param name="text">Updated welcome message contents.</param>
        /// <param name="cancelToken">Async cancellation token.</param>
        /// <returns>Direct message events data.</returns>
        public async Task <WelcomeMessage> UpdateWelcomeMessageAsync(ulong welcomeMessageID, string name, string text, CancellationToken cancelToken = default(CancellationToken))
        {
            if (welcomeMessageID == 0)
            {
                throw new ArgumentException($"{nameof(welcomeMessageID)} is a required parameter, but it's value is 0, which is invalid.", nameof(welcomeMessageID));
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentException($"{nameof(text)} is a required parameter.", nameof(text));
            }

            var newUrl = BaseUrl + "direct_messages/welcome_messages/update.json?id=" + welcomeMessageID;

            var postData = new Dictionary <string, string>
            {
                ["id"] = welcomeMessageID.ToString()
            };

            var msgParams = new WelcomeMsg
            {
                Name        = name,
                MessageData = new WelcomeMessageData
                {
                    Text = text
                }
            };

            RawResult =
                await TwitterExecutor.SendJsonToTwitterAsync(
                    HttpMethod.Put.ToString(),
                    newUrl,
                    postData,
                    msgParams,
                    cancelToken)
                .ConfigureAwait(false);

            var            reqProc = new WelcomeMessageRequestProcessor <WelcomeMessage>();
            WelcomeMessage msg     = reqProc.ProcessActionResult(RawResult, WelcomeMessageType.ShowMessage);

            //msg.ID = welcomeMessageID;
            //msg.Text = text;

            return(msg);
        }
示例#4
0
        /// <summary>
        /// Creates a new welcome message.
        /// </summary>
        /// <param name="name">Name of welcome message.</param>
        /// <param name="text">Welcome message contents.</param>
        /// <param name="cancelToken">Async cancellation token.</param>
        /// <returns>Direct message events data.</returns>
        public async Task <WelcomeMessage?> NewWelcomeMessageAsync(string name, string text, CancellationToken cancelToken = default(CancellationToken))
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentException($"{nameof(text)} is a required parameter.", nameof(text));
            }

            var newUrl = BaseUrl + "direct_messages/welcome_messages/new.json";

            var msgParams = new WelcomeMessageValue
            {
                WelcomeMessage = new WelcomeMsg
                {
                    Name        = name,
                    MessageData = new WelcomeMessageData
                    {
                        Text = text
                    }
                },
                Apps = JsonDocument.Parse("null").RootElement
            };

            RawResult =
                await TwitterExecutor.SendJsonToTwitterAsync(
                    HttpMethod.Post.ToString(),
                    newUrl,
                    new Dictionary <string, string>(),
                    msgParams,
                    cancelToken)
                .ConfigureAwait(false);

            var            reqProc = new WelcomeMessageRequestProcessor <WelcomeMessage>();
            WelcomeMessage?msg     = reqProc.ProcessActionResult(RawResult, WelcomeMessageType.ShowMessage);

            //msg.Name = name;
            //msg.Text = text;

            return(msg);
        }
示例#5
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);
        }