changeset 244:ebb65a26f070 legit-client

Remove unused twitter api library
author nanaya <me@nanaya.net>
date Mon, 17 Jul 2023 04:22:13 +0900
parents bc2f45058c9e
children 2935c5e52a71
files Gemfile Gemfile.lock app/lib/clients.rb app/models/tweet.rb config/initializers/ext_twitter_tweet.rb config/initializers/twitter_tweet_cache_key.rb
diffstat 6 files changed, 0 insertions(+), 182 deletions(-) [+]
line wrap: on
line diff
--- a/Gemfile	Sun Jul 16 08:53:59 2023 +0900
+++ b/Gemfile	Mon Jul 17 04:22:13 2023 +0900
@@ -8,7 +8,6 @@
 
 gem "redis"
 
-gem "twitter"
 gem "twitter-text"
 
 gem "newrelic_rpm"
--- a/Gemfile.lock	Sun Jul 16 08:53:59 2023 +0900
+++ b/Gemfile.lock	Mon Jul 17 04:22:13 2023 +0900
@@ -19,46 +19,20 @@
       i18n (>= 1.6, < 2)
       minitest (>= 5.1)
       tzinfo (~> 2.0)
-    addressable (2.8.1)
-      public_suffix (>= 2.0.2, < 6.0)
-    buftok (0.2.0)
     builder (3.2.4)
     concurrent-ruby (1.1.10)
     connection_pool (2.3.0)
     crass (1.0.6)
-    domain_name (0.5.20190701)
-      unf (>= 0.0.5, < 1.0.0)
-    equalizer (0.0.11)
     erubi (1.12.0)
-    ffi (1.15.5)
-    ffi-compiler (1.0.1)
-      ffi (>= 1.0.0)
-      rake
-    http (4.4.1)
-      addressable (~> 2.3)
-      http-cookie (~> 1.0)
-      http-form_data (~> 2.2)
-      http-parser (~> 1.2.0)
-    http-cookie (1.0.5)
-      domain_name (~> 0.5)
-    http-form_data (2.3.0)
-    http-parser (1.2.3)
-      ffi-compiler (>= 1.0, < 2.0)
-    http_parser.rb (0.6.0)
-    http_parser.rb (0.6.0-java)
     i18n (1.12.0)
       concurrent-ruby (~> 1.0)
     idn-ruby (0.1.5)
     loofah (2.19.1)
       crass (~> 1.0.2)
       nokogiri (>= 1.5.9)
-    memoizable (0.4.2)
-      thread_safe (~> 0.3, >= 0.3.1)
     method_source (1.0.0)
     mini_portile2 (2.8.1)
     minitest (5.17.0)
-    multipart-post (2.2.3)
-    naught (1.1.0)
     newrelic_rpm (8.15.0)
     nio4r (2.5.8)
     nio4r (2.5.8-java)
@@ -69,7 +43,6 @@
       racc (~> 1.4)
     nokogiri (1.14.0-x86-mingw32)
       racc (~> 1.4)
-    public_suffix (5.0.1)
     puma (6.0.2)
       nio4r (~> 2.0)
     puma (6.0.2-java)
@@ -96,21 +69,7 @@
       redis-client (>= 0.9.0)
     redis-client (0.12.0)
       connection_pool
-    simple_oauth (0.3.1)
     thor (1.2.1)
-    thread_safe (0.3.6)
-    thread_safe (0.3.6-java)
-    twitter (7.0.0)
-      addressable (~> 2.3)
-      buftok (~> 0.2.0)
-      equalizer (~> 0.0.11)
-      http (~> 4.0)
-      http-form_data (~> 2.0)
-      http_parser.rb (~> 0.6.0)
-      memoizable (~> 0.4.0)
-      multipart-post (~> 2.0)
-      naught (~> 1.0)
-      simple_oauth (~> 0.3.0)
     twitter-text (3.1.0)
       idn-ruby
       unf (~> 0.1.0)
@@ -134,7 +93,6 @@
   puma
   railties (~> 7.0.1)
   redis
-  twitter
   twitter-text
 
 BUNDLED WITH
--- a/app/lib/clients.rb	Sun Jul 16 08:53:59 2023 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-class Clients
-  def self.client_options(id)
-    {
-      :timeouts => {
-        :connect => 5,
-        :read => 5,
-        :write => 5,
-      },
-    }.merge $cfg[:twitter][id]
-  end
-
-  def self.instance
-    @@instance ||= self.new
-  end
-
-  def initialize
-    @clients = {}
-  end
-
-  def get(id)
-    @clients[id] ||= Twitter::REST::Client.new(self.class.client_options id)
-  end
-end
--- a/app/models/tweet.rb	Sun Jul 16 08:53:59 2023 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-class Tweet
-  TIMELINE_OPTIONS = {
-    :count => 100,
-    :exclude_replies => false,
-    :include_rts => true,
-    :tweet_mode => :extended,
-  }
-
-  def self.cache_expires_time
-    (15 + rand(15)).minutes
-  end
-
-  def initialize(twitter_id)
-    @twitter_id = twitter_id
-  end
-
-  def id
-    user.id
-  end
-
-  def timeline
-    if @timeline.nil?
-      cache_key = "timeline:v2:#{id}/#{Base64.urlsafe_encode64 id.to_s}"
-      raw = Rails.cache.fetch(cache_key, :expires_in => self.class.cache_expires_time) do
-        client_try(:user_timeline, id, TIMELINE_OPTIONS).tap do |data|
-          if data[:result] == :ok
-            if data[:data].any? && data[:data].first.user.id != id
-              wrong_user = data[:data].first.user
-              throw "Wrong timeline data. Requested: #{id}, got: #{wrong_user.id} (#{wrong_user.screen_name.printable})"
-            end
-
-            data[:data] = data[:data].select do |tweet|
-              tweet.retweeted_status.nil? || tweet.user.id != tweet.retweeted_status.user.id
-            end.map { |tweet| tweet.to_h }
-          end
-        end
-      end
-
-      raise Twitter::Error::NotFound if raw[:result] == :not_found
-
-      @timeline = raw[:data].map { |tweet_hash| Twitter::Tweet.new(tweet_hash) }
-    end
-
-    @timeline
-  end
-
-  def user
-    if @user.nil?
-      cache_key = "user:v1:#{@twitter_id.is_a?(Integer) ? 'id' : 'lookup'}:#{@twitter_id}"
-      raw = Rails.cache.fetch(cache_key, :expires_in => self.class.cache_expires_time) do
-        client_try(:user, @twitter_id).tap do |data|
-          if data[:result] == :ok
-            user = data[:data]
-
-            if user.id != @twitter_id && user.screen_name.downcase != @twitter_id.try(:downcase)
-              throw "Wrong user data. Requested: #{@twitter_id}, got: #{user.id} (#{user.screen_name.printable})"
-            end
-          end
-        end
-      end
-
-      raise Twitter::Error::NotFound if raw[:result] == :not_found
-
-      @user = raw[:data]
-    end
-
-    @user
-  end
-
-  def client
-    Clients.instance.get client_config_id
-  end
-
-  def client_try(method, *args)
-    initial_config_id = client_config_id
-
-    begin
-      data = client.public_send method, *args
-    rescue Twitter::Error::TooManyRequests
-      @client_config_id = (1 + @client_config_id) % @client_config_count
-
-      if initial_config_id == client_config_id
-        raise
-      else
-        retry
-      end
-    rescue Twitter::Error::NotFound
-      return { :result => :not_found }
-    end
-
-    { :result => :ok, :data => data }
-  end
-
-  def client_config_id
-    @client_config_count ||= $cfg[:twitter].size
-    @client_config_id ||= rand(@client_config_count)
-
-    @client_config_id
-  end
-end
--- a/config/initializers/ext_twitter_tweet.rb	Sun Jul 16 08:53:59 2023 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-class Twitter::Tweet
-  def full_text_extended
-    attrs[:full_text].printable
-  end
-  memoize :full_text_extended
-
-  def unescaped_text
-    CGI.unescapeHTML full_text_extended
-  end
-  memoize :unescaped_text
-end
--- a/config/initializers/twitter_tweet_cache_key.rb	Sun Jul 16 08:53:59 2023 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-class Twitter::Tweet
-  def cache_key
-    "twitter/tweet/#{id}"
-  end
-end