コード例 #1
0
        // Publish Tweet
        public string GetPublishTweetQuery(IPublishTweetParameters queryParameters)
        {
            _tweetQueryValidator.ThrowIfTweetCannotBePublished(queryParameters);

            var text = queryParameters.Text;

            var useExtendedMode = _tweetinviSettingsAccessor.CurrentThreadSettings.TweetMode == TweetMode.Extended;

            var quotedTweetUrl = GetQuotedTweetUrl(queryParameters);

            if (!useExtendedMode && quotedTweetUrl != null)
            {
                text = text.TrimEnd() + " " + quotedTweetUrl;
            }

            var query = new StringBuilder(string.Format(Resources.Tweet_Publish, CleanupString(text)));

            if (queryParameters.Parameters != null)
            {
                if (queryParameters.InReplyToTweet != null)
                {
                    query.AddParameterToQuery("in_reply_to_status_id", queryParameters.InReplyToTweet.Id);

                    // Extended Tweet prefix auto-population
                    query.AddParameterToQuery("auto_populate_reply_metadata", queryParameters.AutoPopulateReplyMetadata);
                    if (queryParameters.ExcludeReplyUserIds != null)
                    {
                        query.AddParameterToQuery("exclude_reply_user_ids", String.Join(",", queryParameters.ExcludeReplyUserIds));
                    }
                }

                query.AddParameterToQuery("possibly_sensitive", queryParameters.PossiblySensitive);

                if (queryParameters.Coordinates != null)
                {
                    query.AddParameterToQuery("lat", queryParameters.Coordinates.Latitude.ToString(CultureInfo.InvariantCulture));
                    query.AddParameterToQuery("long", queryParameters.Coordinates.Longitude.ToString(CultureInfo.InvariantCulture));
                }

                query.AddParameterToQuery("place_id", queryParameters.PlaceId);
                query.AddParameterToQuery("display_coordinates", queryParameters.DisplayExactCoordinates);
                query.AddParameterToQuery("trim_user", queryParameters.TrimUser);
                query.AddParameterToQuery("tweet_mode", _tweetinviSettingsAccessor.CurrentThreadSettings.TweetMode.ToString().ToLowerInvariant());

                if (useExtendedMode && quotedTweetUrl != null)
                {
                    query.AddParameterToQuery("attachment_url", quotedTweetUrl);
                }

                if (queryParameters.MediaIds.Count > 0)
                {
                    var mediaIdsParameter = string.Join(",", queryParameters.MediaIds.Select(x => x.ToString(CultureInfo.InvariantCulture)));
                    query.AddParameterToQuery("media_ids", mediaIdsParameter);
                }

                query.Append(_queryParameterGenerator.GenerateAdditionalRequestParameters(queryParameters.FormattedCustomQueryParameters));
            }

            return(query.ToString());
        }
コード例 #2
0
        // Publish Tweet
        public string GetPublishTweetQuery(IPublishTweetParameters queryParameters)
        {
            _tweetQueryValidator.ThrowIfTweetCannotBePublished(queryParameters);

            var text = queryParameters.Text;

            if (queryParameters.QuotedTweet != null)
            {
                var quotedTweet = queryParameters.QuotedTweet;
                if (quotedTweet.CreatedBy != null)
                {
                    text = text.TrimEnd();

                    text += string.Format(" https://twitter.com/{0}/status/{1}",
                                          quotedTweet.CreatedBy.ScreenName,
                                          quotedTweet.Id.ToString(CultureInfo.InvariantCulture));
                }
            }

            var query = new StringBuilder(string.Format(Resources.Tweet_Publish, CleanupString(text)));

            if (queryParameters.Parameters != null)
            {
                if (queryParameters.InReplyToTweet != null)
                {
                    query.AddParameterToQuery("in_reply_to_status_id", queryParameters.InReplyToTweet.Id);
                }

                query.AddParameterToQuery("possibly_sensitive", queryParameters.PossiblySensitive);

                if (queryParameters.Coordinates != null)
                {
                    query.AddParameterToQuery("lat", queryParameters.Coordinates.Latitude.ToString(CultureInfo.InvariantCulture));
                    query.AddParameterToQuery("long", queryParameters.Coordinates.Longitude.ToString(CultureInfo.InvariantCulture));
                }

                query.AddParameterToQuery("place_id", queryParameters.PlaceId);
                query.AddParameterToQuery("display_coordinates", queryParameters.DisplayExactCoordinates);
                query.AddParameterToQuery("trim_user", queryParameters.TrimUser);
                query.AddParameterToQuery("auto_populate_reply_metadata", queryParameters.AutoPopulateReplyMetadata);
                query.AddParameterToQuery("tweet_mode", _tweetinviSettingsAccessor.CurrentThreadSettings.TweetMode?.ToString().ToLowerInvariant());

                if (queryParameters.MediaIds.Count > 0)
                {
                    var mediaIdsParameter = string.Join("%2C", queryParameters.MediaIds.Select(x => x.ToString(CultureInfo.InvariantCulture)));
                    query.AddParameterToQuery("media_ids", mediaIdsParameter);
                }

                query.Append(_queryParameterGenerator.GenerateAdditionalRequestParameters(queryParameters.FormattedCustomQueryParameters));
            }

            return(query.ToString());
        }
コード例 #3
0
        private ITweetDTO InternalPublishTweet(IPublishTweetParameters parameters)
        {
            // The exceptions have to be raised before the QueryGenerator as
            // We do not want to wait for the media to be uploaded to throw the
            // Exception. And The logic of uploading the media should live in
            // the TweetController

            _tweetQueryValidator.ThrowIfTweetCannotBePublished(parameters);

            UploadMedias(parameters);

            return(_tweetQueryExecutor.PublishTweet(parameters));
        }
コード例 #4
0
        public string PublishTweet(string text, IPublishTweetOptionalParameters optionalParameters = null)
        {
            // The exceptions have to be raised before the QueryGenerator as
            // We do not want to wait for the media to be uploaded to throw the
            // Exception. And The logic of uploading the media should live in
            // the TweetController

            var publishParameter = new PublishTweetParameters(text, optionalParameters);

            _tweetQueryValidator.ThrowIfTweetCannotBePublished(publishParameter);
            _tweetController.UploadMedias(publishParameter);

            var query = _tweetQueryGenerator.GetPublishTweetQuery(publishParameter);

            return(_twitterAccessor.ExecuteJsonPOSTQuery(query));
        }