Introduce model/ and repository/ structure under lib/

Models: Message, WikiPage, Game (typed structs instead of raw hashes)
Repositories: MessageBoard, OnlineUsers, WikiClient, CatalogClient
bbs.rb uses attribute access (page.title, game.play_path, …) throughout

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-30 09:37:57 +02:00
parent 75d1063572
commit 6856b073f6
8 changed files with 68 additions and 38 deletions

29
lib/repository/catalog.rb Normal file
View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
require 'net/http'
require 'json'
require 'uri'
require_relative '../model/game'
class CatalogClient
API_URL = 'https://games.teletype.hu/api/software'
GAMES_URL = 'https://games.teletype.hu'
def fetch
uri = URI(API_URL)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
http.open_timeout = 12
http.read_timeout = 12
data = JSON.parse(http.get(uri.path).body)
entries = data.is_a?(Hash) ? (data['softwares'] || []) : data
entries.filter_map { |e| Game.new(e) if e.is_a?(Hash) }
rescue => e
warn "Catalog fetch error: #{e}"
[]
end
def play_url(path)
"#{GAMES_URL}#{path}"
end
end