Class: Aniview::Client::AniClient
- Inherits:
-
Object
- Object
- Aniview::Client::AniClient
- Includes:
- Util
- Defined in:
- lib/aniview/client/aniclient.rb
Instance Method Summary collapse
-
#connect ⇒ TCPSocket, false
connects to aniview daemon.
-
#getAllCereal ⇒ Object
sends the message “itemshash” to the daemon.
-
#getItems ⇒ Object
sends the message “items” to the daemon and decodes the serialized object using Util.decode_object.
-
#info ⇒ Object
sends the message “info” to the daemon .
-
#initialize(pref) ⇒ Object
constructor
initializes a new AniClient @.
-
#lastchecked ⇒ Object
sends the message “lastchecked” to the daemon.
-
#sendMsg(msg) ⇒ Object
sends message to aniview daemon.
-
#server? ⇒ true, false
checks if the server is online (sends message “up?” to the daemon).
-
#stopDaemon ⇒ "okay"
sends the message “quit” to the daemon.
Methods included from Util
decode_object, encode_object, error_message, format_duration, format_progress, format_size, mounted_filesystem?, parse_format, readline
Constructor Details
#initialize(pref) ⇒ Object
initializes a new AniClient @
16 17 18 |
# File 'lib/aniview/client/aniclient.rb', line 16 def initialize(pref) @pref = pref end |
Instance Method Details
#connect ⇒ TCPSocket, false
connects to aniview daemon
24 25 26 27 28 29 30 |
# File 'lib/aniview/client/aniclient.rb', line 24 def connect begin TCPSocket.new 'localhost', @pref.get("daemon")["port"] rescue Errno::ECONNREFUSED return false end end |
#getAllCereal ⇒ Object
sends the message “itemshash” to the daemon
see #sendMsg
101 102 103 |
# File 'lib/aniview/client/aniclient.rb', line 101 def getAllCereal sendMsg "itemshash" end |
#getItems ⇒ Object
sends the message “items” to the daemon and decodes the serialized object using Util.decode_object
see #sendMsg
91 92 93 |
# File 'lib/aniview/client/aniclient.rb', line 91 def getItems Util.decode_object(sendMsg "items") end |
#info ⇒ Object
sends the message “info” to the daemon
see #sendMsg
69 70 71 |
# File 'lib/aniview/client/aniclient.rb', line 69 def info sendMsg "info" end |
#lastchecked ⇒ Object
sends the message “lastchecked” to the daemon
see #sendMsg
80 81 82 |
# File 'lib/aniview/client/aniclient.rb', line 80 def lastchecked sendMsg "lastchecked" end |
#sendMsg(msg) ⇒ Object
sends message to aniview daemon
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aniview/client/aniclient.rb', line 39 def sendMsg msg begin s = connect return "offline" if s == false s.puts msg r = s.gets.chomp s.close return r rescue Errno::ECONNRESET return "" end end |
#server? ⇒ true, false
checks if the server is online (sends message “up?” to the daemon)
see #sendMsg
111 112 113 114 |
# File 'lib/aniview/client/aniclient.rb', line 111 def server? return false unless sendMsg("up?") == "true" return true end |
#stopDaemon ⇒ "okay"
sends the message “quit” to the daemon
see #sendMsg
58 59 60 |
# File 'lib/aniview/client/aniclient.rb', line 58 def stopDaemon sendMsg "quit" end |