slack_twitter_egosa 1.0.5 → 1.0.6

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
  SHA256:
3
- metadata.gz: aacc92d45d103fdc59e58af8b74159c47cac2518fed7661d77c3117b3ff55903
4
- data.tar.gz: 2a1479ef926b3bd2f8bbc70b6e465cd92bf1fec2b0eada3ba08402eae2af9908
3
+ metadata.gz: 1aeb894d9c375f87138b5df774353570e9fb5a62d3a6c452ca1eac344b7d34dd
4
+ data.tar.gz: a59bd58d2ce71f48c02951fab5d6bef8db968501d9d0f94e1333dc3b0a58def8
5
5
  SHA512:
6
- metadata.gz: ce029d23c1ddb615070ef9d99866a56c8f273bd1be0048d1027bdf00a6fba4eb8d9107c6ca63ba654b6ea79d63538e7102611e5c8c59717495b7a310bf24c85c
7
- data.tar.gz: 5e97f133be1c89ab1c5d2e4048e3bd95fc172f8024c7b2525aa9bab11aa011c2dacb5760946fb038cbe4783c0d44685e6f49d136ecb671ff0bedcd1c8212774f
6
+ metadata.gz: bb88c0ce7ac29b88f4f7cb94da7484e6ad52ed886781d30c3412c9ff356b35acb8bd4dba9686984aa7cdbb8b17fa3120178a7490637b74cd9915d6be1c70e5fb
7
+ data.tar.gz: 2b04f6451b6071f89317e4d37c37bc6de8192f594f01bf5af99cc41e4c39bcd66037d9858e33b055e4697c028177bab44c7e7977297c1b9e02739c76c92fa25b
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in slack_twitter_egosa.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'slack_twitter_egosa'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'slack_twitter_egosa'
4
5
 
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'twitter'
4
+
5
+ class TwitterClient
6
+ def initialize(consumer_key:, consumer_secret:, access_token:, access_token_secret:, search_query:)
7
+ @client = Twitter::REST::Client.new do |config|
8
+ config.consumer_key = consumer_key
9
+ config.consumer_secret = consumer_secret
10
+ config.access_token = access_token
11
+ config.access_token_secret = access_token_secret
12
+ end
13
+ @search_query = search_query
14
+ end
15
+
16
+ def home_timeline
17
+ is_first_fetch = @home_timeline_since_id.nil?
18
+
19
+ params = { count: 200, tweet_mode: 'extended' }
20
+ params[:since_id] = @home_timeline_since_id if @home_timeline_since_id
21
+ statuses = @client.home_timeline(params).to_a
22
+ @home_timeline_since_id = statuses.first.id unless statuses.empty?
23
+
24
+ # Tweets acquired for the first time are not subject to notification
25
+ return [] if is_first_fetch
26
+
27
+ statuses
28
+ rescue Twitter::Error::TooManyRequests
29
+ warn 'home_timeline: too many requests'
30
+ []
31
+ rescue HTTP::ConnectionError
32
+ warn 'home_timeline: http connection error'
33
+ []
34
+ end
35
+
36
+ def search
37
+ return [] if @search_query.empty?
38
+
39
+ is_first_fetch = @search_since_id.nil?
40
+
41
+ params = { result_type: 'recent', count: 100, tweet_mode: 'extended' }
42
+ params[:since_id] = @search_since_id if @search_since_id
43
+ statuses = @client.search(@search_query, params).to_a
44
+ @search_since_id = statuses.first.id unless statuses.empty?
45
+
46
+ # Tweets acquired for the first time are not subject to notification
47
+ return [] if is_first_fetch
48
+
49
+ statuses
50
+ rescue Twitter::Error::TooManyRequests
51
+ warn 'search: too many requests'
52
+ []
53
+ rescue HTTP::ConnectionError
54
+ warn 'search: http connection error'
55
+ []
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SlackTwitterEgosa
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
@@ -20,7 +20,7 @@ class WordManager
20
20
  [
21
21
  target.join(' OR '),
22
22
  exclude.map { |word| "-#{word}" }.join(' ')
23
- ].join(' ')
23
+ ].join(' ').strip
24
24
  end
25
25
 
26
26
  def match?(text)
@@ -2,13 +2,13 @@
2
2
 
3
3
  require 'thwait'
4
4
 
5
- require 'slack_twitter_egosa/version'
6
- require 'slack_twitter_egosa/slack_poster'
7
- require 'slack_twitter_egosa/word_manager'
8
- require 'slack_twitter_egosa/user_filter'
5
+ require_relative 'slack_twitter_egosa/version'
6
+ require_relative 'slack_twitter_egosa/slack_poster'
7
+ require_relative 'slack_twitter_egosa/word_manager'
8
+ require_relative 'slack_twitter_egosa/user_filter'
9
+ require_relative 'slack_twitter_egosa/twitter_client'
9
10
 
10
11
  require 'dotenv'
11
- require 'twitter'
12
12
 
13
13
  module SlackTwitterEgosa
14
14
  class << self
@@ -17,17 +17,17 @@ module SlackTwitterEgosa
17
17
 
18
18
  lack_env = check_env(ENV.keys)
19
19
  unless lack_env.empty?
20
- STDERR.puts 'Not enough vnvironment variable'
20
+ warn 'Not enough vnvironment variable'
21
21
  lack_env.each do |env|
22
- STDERR.puts " #{env}"
22
+ warn " #{env}"
23
23
  end
24
24
  exit 1
25
25
  end
26
26
 
27
- threads = [
28
- home_timeline_thread,
29
- search_thread
30
- ]
27
+ Thread.abort_on_exception = true
28
+ threads = []
29
+ threads << home_timeline_thread unless home_timeline_words.query.empty?
30
+ threads << search_thread unless search_words.query.empty?
31
31
  ThreadsWait.all_waits(*threads)
32
32
  end
33
33
 
@@ -45,12 +45,13 @@ module SlackTwitterEgosa
45
45
  end
46
46
 
47
47
  def client
48
- @client ||= Twitter::REST::Client.new do |config|
49
- config.consumer_key = ENV['CONSUMER_KEY']
50
- config.consumer_secret = ENV['CONSUMER_SECRET']
51
- config.access_token = ENV['OAUTH_TOKEN']
52
- config.access_token_secret = ENV['OAUTH_TOKEN_SECRET']
53
- end
48
+ @client ||= TwitterClient.new(
49
+ consumer_key: ENV['CONSUMER_KEY'],
50
+ consumer_secret: ENV['CONSUMER_SECRET'],
51
+ access_token: ENV['OAUTH_TOKEN'],
52
+ access_token_secret: ENV['OAUTH_TOKEN_SECRET'],
53
+ search_query: search_words.query
54
+ )
54
55
  end
55
56
 
56
57
  def poster
@@ -81,18 +82,7 @@ module SlackTwitterEgosa
81
82
  def home_timeline_thread
82
83
  Thread.new do
83
84
  loop do
84
- sleep 180 if @home_timeline_since_id
85
-
86
- params = { count: 200, tweet_mode: 'extended' }
87
- params[:since_id] = @home_timeline_since_id if @home_timeline_since_id
88
- statuses = client.home_timeline(params)
89
- next if statuses.empty?
90
-
91
- before_home_timeline_since_id = @home_timeline_since_id
92
- @home_timeline_since_id = statuses.first.id
93
- next unless before_home_timeline_since_id
94
-
95
- statuses.reverse_each do |status|
85
+ client.home_timeline.reverse_each do |status|
96
86
  if status.retweet?
97
87
  status = status.retweeted_status
98
88
  next if status.user.following?
@@ -100,6 +90,9 @@ module SlackTwitterEgosa
100
90
 
101
91
  poster.post_status(status) if match_on_home_timeline?(status)
102
92
  end
93
+
94
+ # Max 15 requests / 15 min
95
+ sleep 180
103
96
  end
104
97
  end
105
98
  end
@@ -107,20 +100,12 @@ module SlackTwitterEgosa
107
100
  def search_thread
108
101
  Thread.new do
109
102
  loop do
110
- sleep 90 if @search_since_id
111
-
112
- params = { result_type: 'recent', count: 100, tweet_mode: 'extended' }
113
- params[:since_id] = @search_since_id if @search_since_id
114
- statuses = client.search(search_words.query, params).to_a
115
- next if statuses.empty?
116
-
117
- before_search_since_id = @search_since_id
118
- @search_since_id = statuses.first.id
119
- next unless before_search_since_id
120
-
121
- statuses.reverse_each do |status|
103
+ client.search.reverse_each do |status|
122
104
  poster.post_status(status) if match_on_search?(status)
123
105
  end
106
+
107
+ # Max 180 requests / 15 min
108
+ sleep 60
124
109
  end
125
110
  end
126
111
  end
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'slack_twitter_egosa/version'
5
6
 
@@ -19,11 +20,11 @@ Gem::Specification.new do |spec|
19
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
21
  spec.require_paths = ['lib']
21
22
 
22
- spec.add_dependency 'dotenv', '~> 2.4.0'
23
+ spec.add_dependency 'dotenv', '~> 2.7.0'
23
24
  spec.add_dependency 'slack-poster', '~> 2.2.0'
24
25
  spec.add_dependency 'twitter', '~> 6.2.0'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.12'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rake', '~> 13.0'
28
29
  spec.add_development_dependency 'rspec', '~> 3.0'
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack_twitter_egosa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - abcang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.4.0
19
+ version: 2.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.4.0
26
+ version: 2.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: slack-poster
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -115,6 +115,7 @@ files:
115
115
  - exe/slack_twitter_egosa
116
116
  - lib/slack_twitter_egosa.rb
117
117
  - lib/slack_twitter_egosa/slack_poster.rb
118
+ - lib/slack_twitter_egosa/twitter_client.rb
118
119
  - lib/slack_twitter_egosa/user_filter.rb
119
120
  - lib/slack_twitter_egosa/version.rb
120
121
  - lib/slack_twitter_egosa/word_manager.rb
@@ -138,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  - !ruby/object:Gem::Version
139
140
  version: '0'
140
141
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.7.6
142
+ rubygems_version: 3.0.3
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Eegosearching twitter and post to slack.