diff app/lib/clients.rb @ 219:17461f7682a2

One client for everyone
author nanaya <me@nanaya.pro>
date Thu, 27 May 2021 02:28:18 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/lib/clients.rb	Thu May 27 02:28:18 2021 +0900
@@ -0,0 +1,23 @@
+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