Module: MeshChat::Net::Client
- Defined in:
- lib/meshchat/net/client.rb
Class Method Summary collapse
- .node_for(location: nil, uid: nil, node: nil) ⇒ Node
- .send(location: nil, uid: nil, node: nil, message: nil) ⇒ Object
Class Method Details
.node_for(location: nil, uid: nil, node: nil) ⇒ Node
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/meshchat/net/client.rb', line 43 def node_for(location: nil, uid: nil, node: nil) unless node node = Models::Entry.find_by_location(location) if location node = Models::Entry.find_by_uid(uid) if uid && !node end # TODO: also check for public key? # without the public key, the message is sent in cleartext. :-\ if !(node && node.location) Display.alert "Node not found, or does not have a location" return end node end |
.send(location: nil, uid: nil, node: nil, message: nil) ⇒ Object
Note:
Either the location, node, or uid should be present
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/meshchat/net/client.rb', line 12 def send(location: nil, uid: nil, node: nil, message: nil) # verify node is valid node = self.node_for(location: location, uid: uid, node: node) Thread.new(node, ) do |node, | request = MeshChat::Net::Request.new(node, ) payload = { message: request.payload } begin Curl::Easy.http_post(node.location, payload.to_json) do |c| c.headers['Accept'] = 'application/json' c.headers['Content-Type'] = 'application/json' if MeshChat::Settings.debug? puts .render c.verbose = true c.on_debug do |type, data| puts data end end end rescue => e node.update(online: false) Display.info "#{node.alias_name} has ventured offline" Display.debug("#{.class.name}: Issue connectiong to #{node.alias_name}@#{node.location}") Display.debug(e.) end end end |