Class: NeocitiesRed::Services::Site::Informer
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::Site::Informer
- Defined in:
- lib/neocities_red/services/site/informer.rb
Overview
Retrieves and formats site information for the Neocities site.
Queries the Neocities API for site metadata (domain, bandwidth, created_at, last_updated, etc.) and formats it as rows suitable for display in a TTY::Table.
Instance Attribute Summary collapse
-
#client ⇒ NeocitiesRed::Client
readonly
The authenticated API client.
Instance Method Summary collapse
-
#initialize(client, subargs = [], sitename = nil) ⇒ Informer
constructor
A new instance of Informer.
-
#pretty_print ⇒ Array<Array(String, Object)>
Formats the site stats as bold-labeled rows.
-
#stats ⇒ Hash
Fetches site information from the Neocities API.
Constructor Details
#initialize(client, subargs = [], sitename = nil) ⇒ Informer
Returns a new instance of Informer.
29 30 31 32 33 34 |
# File 'lib/neocities_red/services/site/informer.rb', line 29 def initialize(client, = [], sitename = nil) @client = client @subargs = @sitename = sitename @pastel = Pastel.new(eachline: "\n") end |
Instance Attribute Details
#client ⇒ NeocitiesRed::Client (readonly)
Returns the authenticated API client.
23 24 25 |
# File 'lib/neocities_red/services/site/informer.rb', line 23 def client @client end |
Instance Method Details
#pretty_print ⇒ Array<Array(String, Object)>
Formats the site stats as bold-labeled rows.
Timestamp fields (+created_at+, last_updated) are converted
to local time for readability.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/neocities_red/services/site/informer.rb', line 54 def pretty_print out = [] stats[:info].each do |k, v| v = Time.parse(v).localtime if v && %i[created_at last_updated].include?(k) out << [@pastel.bold(k.to_s), v] end out end |
#stats ⇒ Hash
Fetches site information from the Neocities API.
40 41 42 43 44 45 46 |
# File 'lib/neocities_red/services/site/informer.rb', line 40 def stats response = @client.info(@subargs[0] || @sitename) raise NeocitiesRed::APIError, response[:message] if response[:result] == "error" response end |