Class: Tox::Status

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#urlObject

Returns the value of attribute url.



11
12
13
# File 'lib/tox/status.rb', line 11

def url
  @url
end

Instance Method Details

#all_nodesObject



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

#dataObject (private)



49
50
51
# File 'lib/tox/status.rb', line 49

def data
  @data ||= JSON.parse Net::HTTP.get URI.parse url
end

#inspectObject



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_refreshObject



23
24
25
# File 'lib/tox/status.rb', line 23

def last_refresh
  @last_refresh ||= Time.at(data['last_refresh']).utc.freeze
end

#last_scanObject



27
28
29
# File 'lib/tox/status.rb', line 27

def last_scan
  @last_scan ||= Time.at(data['last_scan']).utc.freeze
end

#tcp_nodesObject



39
40
41
# File 'lib/tox/status.rb', line 39

def tcp_nodes
  @tcp_nodes ||= all_nodes.select(&:status_tcp).freeze
end

#udp_nodesObject



35
36
37
# File 'lib/tox/status.rb', line 35

def udp_nodes
  @udp_nodes ||= all_nodes.select(&:status_udp).freeze
end