Class: Tox::Status
- Inherits:
-
Object
- Object
- Tox::Status
- Defined in:
- lib/tox/status.rb
Overview
Tox network status received from server running https://github.com/Tox/ToxStatus
Constant Summary collapse
- OFFICIAL_URL =
JSON API endpoint of the official network status server.
'https://nodes.tox.chat/json'
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #all_nodes ⇒ Object
- #data ⇒ Object private
-
#initialize(url = OFFICIAL_URL) ⇒ Status
constructor
A new instance of Status.
- #inspect ⇒ Object
- #last_refresh ⇒ Object
- #last_scan ⇒ Object
- #tcp_nodes ⇒ Object
- #udp_nodes ⇒ Object
Constructor Details
#initialize(url = OFFICIAL_URL) ⇒ Status
Returns a new instance of Status.
13 14 15 |
# File 'lib/tox/status.rb', line 13 def initialize(url = OFFICIAL_URL) self.url = url end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
11 12 13 |
# File 'lib/tox/status.rb', line 11 def url @url end |
Instance Method Details
#all_nodes ⇒ Object
31 32 33 |
# File 'lib/tox/status.rb', line 31 def all_nodes @all_nodes ||= data['nodes'].map { |node_data| Node.new node_data }.freeze end |
#data ⇒ Object (private)
49 50 51 |
# File 'lib/tox/status.rb', line 49 def data @data ||= JSON.parse Net::HTTP.get URI.parse url end |
#inspect ⇒ Object
17 18 19 20 21 |
# File 'lib/tox/status.rb', line 17 def inspect @inspect ||= "#<#{self.class} " \ "last_refresh: #{last_refresh}, " \ "last_scan: #{last_scan}>" end |
#last_refresh ⇒ Object
23 24 25 |
# File 'lib/tox/status.rb', line 23 def last_refresh @last_refresh ||= Time.at(data['last_refresh']).utc.freeze end |
#last_scan ⇒ Object
27 28 29 |
# File 'lib/tox/status.rb', line 27 def last_scan @last_scan ||= Time.at(data['last_scan']).utc.freeze end |
#tcp_nodes ⇒ Object
39 40 41 |
# File 'lib/tox/status.rb', line 39 def tcp_nodes @tcp_nodes ||= all_nodes.select(&:status_tcp).freeze end |
#udp_nodes ⇒ Object
35 36 37 |
# File 'lib/tox/status.rb', line 35 def udp_nodes @udp_nodes ||= all_nodes.select(&:status_udp).freeze end |