tweet_sanitizer 0.1.0.beta1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95ee13f344a020fee8f62754894bff6ce604aa41
4
- data.tar.gz: 0dd22db74f75368271ed62f967141dd009290e40
3
+ metadata.gz: b6373a02a1ea05e0096cdffb9398f175e7f7a9f2
4
+ data.tar.gz: 12bbee7bc87e4bf0c0765e54f13cf0347d107a48
5
5
  SHA512:
6
- metadata.gz: b9d8a7efbec32e451c484d4f2b9c0bc85d391d890c299a81cb7ac366a2773e6a3636b064ae21404e001331ae9eec156549cea0c459c63002f1f422edda3605f0
7
- data.tar.gz: e075a6c9f8f5e6b29b5ae67e8294edb7f8a69a5f744d552969237a80c59487ef2092b1c87c9ebe85955d15776bfffd5e785fe3bac07a42a6acbd9637ddbb4bd1
6
+ metadata.gz: 259a3972322175046a8a85256a15870532656e1a482e33d6f2da79089fdbc3421a195da343a9fac062d7a8df8a771e30393fac69db859d911e44571eb0cb2f38
7
+ data.tar.gz: 07da5186868e2f7ba9fd86131872d2b7d310b1522e581b4949bd1b08a0c4e429bea6ba9a88bce9cc1782237b8c658eee47fef88dc9d6eb5b0ea110c39963fbf2
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: kZmA3FzhK4Oou7s7aQPRcAW0e8RbRlzhD
data/.travis.yml CHANGED
@@ -1,5 +1,27 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3
7
+ - 2.4.1
8
+ - ruby-head
9
+ bundler_args: "--jobs=2"
10
+ cache: bundler
5
11
  before_install: gem install bundler -v 1.15.3
12
+ before_script:
13
+ - export CODECLIMATE_REPO_TOKEN=b275edefb84b9adf2e55846adb2c2649072895873f85eacafff3cb9a31aec846
14
+ - export CI=true
15
+ script:
16
+ - bundle exec rspec
17
+ - bundle exec codeclimate-test-reporter
18
+ branches:
19
+ only:
20
+ - master
21
+ notifications:
22
+ email: false
23
+ slack:
24
+ secure: Sv+kslA+VVRafEOYfWVM7f+9Tryw+OKFdyqLOodduDexNoLedeqCqYSASJsw33vxgSGhRnWgcCHLzpLdK211bn6H6q3JgKKJQdO9Zxci7iftqn2lXiltL8EdIIHreW7qKYUJhWeM0CCpdLD7R8IGvPv7HbWko2g3JRYqmAmPMBZBU99uX0Sa0pWirEGAY7asqbz4yU2ugCEIRiD5/Ao9y8AltTn4r7m3puIKgm/3WhjJJtasWZFohFf3d/QEybefYoTcEOmRK3WI1yeRC2t0fK55yOLRgndUggSz1DSIad+f+PeyaTG24ErmkaxfGg086OIT8fB/39UNqrxC9xIMWGKLF0g2Xb09JrnvZbl9QVhdTqre/jbaflsQLanSd/nGA3f1uXk/QESL7zYz1qxgXkcREmrQxrZ0yC11L7Xz6nqigkAt/V5/zRM2LOuYBEO+d4hPHAO7IJMyLfppPd8P07QAW9jSmYoDIRqmZfKz/hQ2aUlubc5D64VcLECgbtMUbj6mOEVl4H8ygAJvBOkrx4gJGEU5YxMDDRJt3yAb8VD7Ek2fw5ovLFqkNTp+a8TjksGTA2s2vpNE1dnDhJb6OrCgQNC8hkFkkVhV1V5a0bNuJE+lybErzWzaT/y8YSCCcY8FCytOZOs63zfIWqCDLjJq9/juThUx3hKndYXtc70=
25
+ matrix:
26
+ allow_failures:
27
+ - rvm: ruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Unreleased
2
+ [full changelog](https://github.com/sue445/tweet_sanitizer/compare/v0.1.0...master)
3
+
4
+ ## v0.1.0
5
+ * first release
data/README.md CHANGED
@@ -1,8 +1,31 @@
1
1
  # TweetSanitizer
2
+ [![Gem Version](https://badge.fury.io/rb/tweet_sanitizer.svg)](https://badge.fury.io/rb/tweet_sanitizer)
3
+ [![Build Status](https://travis-ci.org/sue445/tweet_sanitizer.svg?branch=master)](https://travis-ci.org/sue445/tweet_sanitizer)
4
+ [![Code Climate](https://codeclimate.com/github/sue445/tweet_sanitizer.png)](https://codeclimate.com/github/sue445/tweet_sanitizer)
5
+ [![Coverage Status](https://coveralls.io/repos/github/sue445/tweet_sanitizer/badge.svg?branch=master)](https://coveralls.io/github/sue445/tweet_sanitizer?branch=master)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/sue445/tweet_sanitizer.svg)](https://gemnasium.com/github.com/sue445/tweet_sanitizer)
2
7
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tweet_sanitizer`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+ This is extension of [twitter](https://github.com/sferik/twitter). Sanitize `Twitter::Tweet#text`
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
10
+ ## Example
11
+ ```ruby
12
+ tweet = @client.status("https://twitter.com/github/status/866677968608927744")
13
+ tweet.text
14
+ #=> "Introducing GitHub Marketplace, a new place to browse and buy integrations using your GitHub account.… https://t.co/dK0Tmcmm72"
15
+ ```
16
+
17
+ ```ruby
18
+ using TweetSanitizer::TwitterExtension
19
+
20
+ extended_tweet = @client.status("https://twitter.com/github/status/866677968608927744", tweet_mode: "extended")
21
+ extended_tweet.sanitized_text
22
+ #=> "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"
23
+ ```
24
+
25
+ ## Features
26
+ * Expand urls in `Twitter::Tweet#text` (e.g. `t.co` url -> original url)
27
+ * Remove media urls in `Twitter::Tweet#text`
28
+ * Unescape special html characters in `Twitter::Tweet#text` (e.g. `(&gt; &lt;)` -> `(> <)`)
6
29
 
7
30
  ## Installation
8
31
 
@@ -21,8 +44,28 @@ Or install it yourself as:
21
44
  $ gem install tweet_sanitizer
22
45
 
23
46
  ## Usage
47
+ ### Case 1. Use `TweetSanitizer::TwitterExtension` and `Twitter::Tweet#sanitized_text` (Recommended)
48
+ ```ruby
49
+ using TweetSanitizer::TwitterExtension
50
+
51
+ extended_tweet = @client.status("https://twitter.com/github/status/866677968608927744", tweet_mode: "extended")
52
+ extended_tweet.sanitized_text
53
+ ```
54
+
55
+ ### Case 2. Use `TweetSanitizer.sanitize`
56
+ ```ruby
57
+ extended_tweet = @client.status("https://twitter.com/github/status/866677968608927744", tweet_mode: "extended")
58
+ TweetSanitizer.sanitize(extended_tweet)
59
+ ```
60
+
61
+ ### :warning: Note
62
+ When you get `Twitter::Tweet` instance, pass `tweet_mode: "extended"` option to methods. (e.g. `Twitter::REST::Client#status`, `Twitter::REST::Client#search`)
63
+
64
+ Because `full_text` attribute is returned when **only** `tweet_mode=extended` is passed to Twitter API
65
+
66
+ See following.
24
67
 
25
- TODO: Write usage instructions here
68
+ https://dev.twitter.com/overview/api/upcoming-changes-to-tweets
26
69
 
27
70
  ## Development
28
71
 
@@ -39,7 +82,7 @@ vi .env
39
82
 
40
83
  ## Contributing
41
84
 
42
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tweet_sanitizer.
85
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/tweet_sanitizer.
43
86
 
44
87
  ## License
45
88
 
data/bin/console CHANGED
@@ -15,4 +15,6 @@ Dotenv.load
15
15
  config.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"]
16
16
  end
17
17
 
18
+ using TweetSanitizer::TwitterExtension
19
+
18
20
  Pry.start
@@ -1,5 +1,6 @@
1
- require "tweet_sanitizer/version"
2
1
  require "twitter"
2
+ require "tweet_sanitizer/version"
3
+ require "tweet_sanitizer/twitter_extension"
3
4
 
4
5
  module TweetSanitizer
5
6
  # @param tweet [Twitter:Tweet]
@@ -14,24 +15,31 @@ module TweetSanitizer
14
15
  # @param tweet [Twitter:Tweet]
15
16
  # @return [String]
16
17
  def self.expand_urls_text(tweet)
17
- text = tweet.text.dup
18
+ text = tweet_full_text(tweet)
18
19
  return text unless tweet.uris?
19
20
 
20
- tweet.uris.reverse.each_with_object(text) do |uri, expanded|
21
+ tweet.uris.reverse.each_with_object(text.dup) do |uri, expanded|
21
22
  pos1 = uri.indices[0]
22
23
  pos2 = uri.indices[1]
23
24
  expanded[pos1, pos2-pos1] = uri.expanded_url
24
25
  end
25
26
  end
26
27
 
28
+ # @param tweet [Twitter:Tweet]
29
+ # @return [String] `full_text` attribute if exist
30
+ def self.tweet_full_text(tweet)
31
+ # NOTE: Twitter::Tweet#full_text doesn't returns full_text attribute
32
+ # https://github.com/sferik/twitter/blob/v6.1.0/lib/twitter/tweet.rb#L37-L44
33
+ tweet.attrs[:full_text] || tweet.text
34
+ end
35
+
27
36
  # @param tweet [Twitter:Tweet]
28
37
  # @param text [String]
29
38
  # @return [String]
30
39
  def self.remove_media_urls_in_tweet(tweet, text)
31
- text = text.dup
32
40
  return text unless tweet.media?
33
41
 
34
- tweet.media.each_with_object(text) do |media, t|
42
+ tweet.media.each_with_object(text.dup) do |media, t|
35
43
  t.gsub!(media.url, "")
36
44
  t.strip!
37
45
  end
@@ -0,0 +1,10 @@
1
+ module TweetSanitizer
2
+ module TwitterExtension
3
+ refine(Twitter::Tweet) do
4
+ # @return [String]
5
+ def sanitized_text
6
+ TweetSanitizer.sanitize(self)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module TweetSanitizer
2
- VERSION = "0.1.0.beta1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -14,6 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/sue445/tweet_sanitizer"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.required_ruby_version = ">= 2.1.0"
18
+
17
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(test|spec|features)/})
19
21
  end
@@ -24,9 +26,12 @@ Gem::Specification.new do |spec|
24
26
  spec.add_dependency "twitter"
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 1.15"
29
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
30
+ spec.add_development_dependency "coveralls"
27
31
  spec.add_development_dependency "dotenv"
28
32
  spec.add_development_dependency "pry-byebug"
29
33
  spec.add_development_dependency "rake", "~> 10.0"
30
34
  spec.add_development_dependency "rspec", "~> 3.0"
31
35
  spec.add_development_dependency "rspec-parameterized"
36
+ spec.add_development_dependency "simplecov"
32
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweet_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-13 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: dotenv
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +136,20 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
111
153
  description: sanitize tweet
112
154
  email:
113
155
  - sue445@sue445.net
@@ -115,10 +157,12 @@ executables: []
115
157
  extensions: []
116
158
  extra_rdoc_files: []
117
159
  files:
160
+ - ".coveralls.yml"
118
161
  - ".env.example"
119
162
  - ".gitignore"
120
163
  - ".rspec"
121
164
  - ".travis.yml"
165
+ - CHANGELOG.md
122
166
  - Gemfile
123
167
  - LICENSE.txt
124
168
  - README.md
@@ -126,6 +170,7 @@ files:
126
170
  - bin/console
127
171
  - bin/setup
128
172
  - lib/tweet_sanitizer.rb
173
+ - lib/tweet_sanitizer/twitter_extension.rb
129
174
  - lib/tweet_sanitizer/version.rb
130
175
  - tweet_sanitizer.gemspec
131
176
  homepage: https://github.com/sue445/tweet_sanitizer
@@ -140,12 +185,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
185
  requirements:
141
186
  - - ">="
142
187
  - !ruby/object:Gem::Version
143
- version: '0'
188
+ version: 2.1.0
144
189
  required_rubygems_version: !ruby/object:Gem::Requirement
145
190
  requirements:
146
- - - ">"
191
+ - - ">="
147
192
  - !ruby/object:Gem::Version
148
- version: 1.3.1
193
+ version: '0'
149
194
  requirements: []
150
195
  rubyforge_project:
151
196
  rubygems_version: 2.6.11