public string GenerateUserIdParameter(long userId, string parameterName = "user_id") { if (!_userQueryValidator.IsUserIdValid(userId)) { return(null); } return(String.Format("{0}={1}", parameterName, userId)); }
public string GetMuteQuery(long userId) { if (!_userQueryValidator.IsUserIdValid(userId)) { return(null); } string userIdParameter = _userQueryParameterGenerator.GenerateUserIdParameter(userId); return(GenerateCreateMuteQuery(userIdParameter)); }
public string GetFriendIdsQuery(long userId, int maxFriendsToRetrieve) { if (!_userQueryValidator.IsUserIdValid(userId)) { return(null); } string userIdParameter = _userQueryParameterGenerator.GenerateUserIdParameter(userId); return(GenerateGetFriendIdsQuery(userIdParameter, maxFriendsToRetrieve)); }
public void ThrowIfMessageCannotBePublished(IPublishMessageParameters parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters), "Publish message parameters cannot be null."); } if (!IsMessageTextValid(parameters.Text)) { throw new ArgumentException("Message text is not valid."); } if (!_userQueryValidator.IsUserIdValid(parameters.RecipientId)) { throw new ArgumentException("Recipient User ID is not valid"); } // If quick reply options are specified, validate them if (parameters.QuickReplyOptions != null && parameters.QuickReplyOptions.Length > 0) { if (parameters.QuickReplyOptions.Length > TweetinviConsts.MESSAGE_QUICK_REPLY_MAX_OPTIONS) { throw new ArgumentException("There are too many Quick Reply Options. You can only have up to " + TweetinviConsts.MESSAGE_QUICK_REPLY_MAX_OPTIONS); } var hasDescription = parameters.QuickReplyOptions[0].Description != null; foreach (var o in parameters.QuickReplyOptions) { // If one option has a description, then they all must // https://developer.twitter.com/en/docs/direct-messages/quick-replies/api-reference/options if ((hasDescription && o.Description == null) || (!hasDescription && o.Description != null)) { throw new ArgumentException("If one Quick Reply Option has a description, then they all must"); } if (o.Label == null) { throw new ArgumentException("Quick Reply Option Label is a required field"); } if (o.Label.UTF32Length() > TweetinviConsts.MESSAGE_QUICK_REPLY_LABEL_MAX_LENGTH) { throw new ArgumentException("Quick Reply Option Label too long. Max length is " + TweetinviConsts.MESSAGE_QUICK_REPLY_LABEL_MAX_LENGTH); } if (o.Description != null && o.Description.UTF32Length() > TweetinviConsts.MESSAGE_QUICK_REPLY_DESCRIPTION_MAX_LENGTH) { throw new ArgumentException("Quick Reply Option Description too long. Max length is " + TweetinviConsts.MESSAGE_QUICK_REPLY_DESCRIPTION_MAX_LENGTH); } if (o.Metadata != null && o.Metadata.UTF32Length() > TweetinviConsts.MESSAGE_QUICK_REPLY_METADATA_MAX_LENGTH) { throw new ArgumentException("Quick Reply Option Metadata too long. Max length is " + TweetinviConsts.MESSAGE_QUICK_REPLY_METADATA_MAX_LENGTH); } } } }
// Publish Message public string GetPublishMessageQuery(IMessageDTO messageDTO) { if (!_messageQueryValidator.CanMessageDTOBePublished(messageDTO)) { return(null); } if (_userQueryValidator.CanUserBeIdentified(messageDTO.Recipient)) { return(GetPublishMessageQuery(messageDTO.Text, messageDTO.Recipient)); } if (_userQueryValidator.IsUserIdValid(messageDTO.RecipientId)) { return(GetPublishMessageQuery(messageDTO.Text, messageDTO.RecipientId)); } return(GetPublishMessageQuery(messageDTO.Text, messageDTO.RecipientScreenName)); }
public bool CanMessageDTOBePublished(IMessageDTO messageDTO) { bool isMessageInValidState = messageDTO != null && !messageDTO.IsMessagePublished && !messageDTO.IsMessageDestroyed; if (!isMessageInValidState) { return(false); } bool isRecipientValid = _userQueryValidator.CanUserBeIdentified(messageDTO.Recipient) || _userQueryValidator.IsUserIdValid(messageDTO.RecipientId) || _userQueryValidator.IsScreenNameValid(messageDTO.RecipientScreenName); bool messageTextIsValid = IsMessageTextValid(messageDTO.Text); return(isRecipientValid && messageTextIsValid); }
public string GetUserSubscribedListsQuery(long userId, bool getOwnedListsFirst) { if (!_userQueryValidator.IsUserIdValid(userId)) { return(null); } var userIdentifier = _userQueryParameterGenerator.GenerateUserIdParameter(userId); return(GenerateUserListsQuery(userIdentifier, getOwnedListsFirst)); }
public string GenerateIdOrScreenNameParameter( IUserIdentifier user, string idParameterName = "user_id", string screenNameParameterName = "screen_name") { _userQueryValidator.ThrowIfUserCannotBeIdentified(user); if (_userQueryValidator.IsUserIdValid(user.Id)) { return(GenerateUserIdParameter(user.Id, idParameterName)); } return(GenerateScreenNameParameter(user.ScreenName, screenNameParameterName)); }
public bool CanMessageBePublished(IMessagePublishParameters parameters) { var message = parameters.Message; var text = parameters.Text; bool messageTextIsValid = IsMessageTextValid(text); bool isRecipientValid = _userQueryValidator.CanUserBeIdentified(parameters.Recipient) || _userQueryValidator.IsUserIdValid(parameters.RecipientId) || _userQueryValidator.IsScreenNameValid(parameters.RecipientScreenName); bool isMessageInValidState = message == null || (!message.IsMessagePublished && !message.IsMessageDestroyed); if (!isMessageInValidState) { return(false); } return(isRecipientValid && messageTextIsValid); }
public string GenerateIdentifierParameter(ITwitterListIdentifier twitterListIdentifier) { if (twitterListIdentifier.Id != TweetinviSettings.DEFAULT_ID) { return(string.Format(Resources.List_ListIdParameter, twitterListIdentifier.Id.ToString(CultureInfo.InvariantCulture))); } string ownerIdentifier; if (_userQueryValidator.IsUserIdValid(twitterListIdentifier.OwnerId)) { ownerIdentifier = string.Format(Resources.List_OwnerIdParameter, twitterListIdentifier.OwnerId.ToString(CultureInfo.InvariantCulture)); } else { ownerIdentifier = string.Format(Resources.List_OwnerScreenNameParameter, twitterListIdentifier.OwnerScreenName); } var slugParameter = string.Format(Resources.List_SlugParameter, twitterListIdentifier.Slug); return(string.Format("{0}{1}", slugParameter, ownerIdentifier)); }
public IListIdentifier Create(ITweetListDTO tweetListDTO) { if (tweetListDTO == null) { return(null); } if (tweetListDTO.Id != TweetinviConstants.DEFAULT_ID) { return(Create(tweetListDTO.Id)); } if (!String.IsNullOrEmpty(tweetListDTO.Slug) && _userQueryValidator.CanUserBeIdentified(tweetListDTO.Creator)) { if (_userQueryValidator.IsUserIdValid(tweetListDTO.Creator.Id)) { return(Create(tweetListDTO.Slug, tweetListDTO.Creator.Id)); } return(Create(tweetListDTO.Slug, tweetListDTO.Creator.ScreenName)); } return(null); }