summaryrefslogtreecommitdiffstats
path: root/bin/convert_github_emojis.rb
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2020-08-17 13:54:26 +0200
committerGravatar √Čtienne Deparis 2020-08-17 20:07:19 +0200
commit36bc1e1503d681bf02165a8947adb32a406e9381 (patch)
treeca7bc780be69c18dc59c9b49e43c4f86a4551b25 /bin/convert_github_emojis.rb
parentc591dcd23863dfff62ee32899dea36cea1da8436 (diff)
downloadstatus-36bc1e1503d681bf02165a8947adb32a406e9381.tar.gz
status-36bc1e1503d681bf02165a8947adb32a406e9381.tar.xz
status-36bc1e1503d681bf02165a8947adb32a406e9381.zip
feat: Do not use curl to fetch emojis list
Diffstat (limited to 'bin/convert_github_emojis.rb')
-rwxr-xr-xbin/convert_github_emojis.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/bin/convert_github_emojis.rb b/bin/convert_github_emojis.rb
index 15ed014..184fd8f 100755
--- a/bin/convert_github_emojis.rb
+++ b/bin/convert_github_emojis.rb
@@ -1,15 +1,20 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
+require 'net/http'
require 'json'
require 'uri'
-# emojis.json should be downloaded from https://api.github.com/emojis first.
-unless File.exist?('tmp/emojis.json')
- Dir.mkdir 'tmp' unless Dir.exist?('tmp')
- system('curl', '-o', 'tmp/emojis.json', 'https://api.github.com/emojis')
+def uri_fetch(uri_str, limit = 10)
+ raise 'Infinit redirect loop' if limit.zero?
+ response = Net::HTTP.get_response(URI(uri_str))
+ if response.is_a?(Net::HTTPRedirection)
+ return uri_fetch(response['location'], limit - 1)
+ end
+ response
end
-source = JSON.parse(IO.read('tmp/emojis.json'))
+
+source = JSON.parse(uri_fetch('https://api.github.com/emojis').body)
data = {}
source.each do |k, v|