TweetSanitizer

Gem Version Build Status Code Climate Coverage Status Dependency Status

This is extension of twitter. Sanitize Twitter::Tweet#text

Example

tweet = @client.status("https://twitter.com/github/status/866677968608927744")
tweet.text
#=> "Introducing GitHub Marketplace, a new place to browse and buy integrations using your GitHub account.… https://t.co/dK0Tmcmm72"
using TweetSanitizer::TwitterExtension

extended_tweet = @client.status("https://twitter.com/github/status/866677968608927744", tweet_mode: "extended")
extended_tweet.sanitized_text
#=> "Introducing GitHub Marketplace, a new place to browse and buy integrations using your GitHub account. https://github.com/blog/2359-introducing-github-marketplace-and-more-tools-to-customize-your-workflow"

Features

  • Expand urls in Twitter::Tweet#text (e.g. t.co url -> original url)
  • Remove media urls in Twitter::Tweet#text
  • Unescape special html characters in Twitter::Tweet#text (e.g. (&gt; &lt;) -> (> <))

Installation

Add this line to your application's Gemfile:

gem 'tweet_sanitizer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tweet_sanitizer

Usage

using TweetSanitizer::TwitterExtension

extended_tweet = @client.status("https://twitter.com/github/status/866677968608927744", tweet_mode: "extended")
extended_tweet.sanitized_text

Case 2. Use TweetSanitizer.sanitize

extended_tweet = @client.status("https://twitter.com/github/status/866677968608927744", tweet_mode: "extended")
TweetSanitizer.sanitize(extended_tweet)

:warning: Note

When you get Twitter::Tweet instance, pass tweet_mode: "extended" option to methods. (e.g. Twitter::REST::Client#status, Twitter::REST::Client#search)

Because full_text attribute is returned when only tweet_mode=extended is passed to Twitter API

See following.

https://dev.twitter.com/overview/api/upcoming-changes-to-tweets

Development

cp .env.example .env
vi .env
./bin/console
[1] pry(main)> @client.status("https://twitter.com/sue445/status/896748477262082049")
=> #<Twitter::Tweet id=896748477262082049>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/tweet_sanitizer.

License

The gem is available as open source under the terms of the MIT License.