Skip to content

Instantly share code, notes, and snippets.

@developer88
Created February 24, 2026 21:43
Show Gist options
  • Select an option

  • Save developer88/2809d29216d7bb709865eef1867817bc to your computer and use it in GitHub Desktop.

Select an option

Save developer88/2809d29216d7bb709865eef1867817bc to your computer and use it in GitHub Desktop.
latest_ruby_tag_fetcher.trb
require "httparty"
require "json"
require "time"
class RubyVersion
API_URL = "https://api.github.com/repos/ruby/ruby/releases/latest"
class Response
attr_reader :code: Integer
attr_reader :json: Hash<String, untyped>
def initialize(code: Integer, json: Hash<String, untyped>): nil
@code = code
@json = json
end
def success?: Boolean
(200..299).include?(@code)
end
end
def fetch_response: Response
http = HTTParty.get(API_URL, headers: { 'User-Agent' => 'static-typing-demo' })
Response.new(http.code.to_i, JSON.parse(http.body))
end
def self.fetch(printer: Proc<[String, String, Time], nil>): nil
resp = new.fetch_response
raise "HTTP #{resp.code}" unless (200..299).include?(resp.code)
data = resp.json
published = Time.parse((data['published_at'] || Time.now.utc.iso8601).to_s)
printer.call((data['tag_name'] || data['name']).to_s, data['html_url'], published)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment