summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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|