Created
February 24, 2026 21:43
-
-
Save developer88/2809d29216d7bb709865eef1867817bc to your computer and use it in GitHub Desktop.
latest_ruby_tag_fetcher.trb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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