Class: LOLastfm::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/LOLastfm/client.rb
Instance Method Summary
collapse
Constructor Details
#initialize(host, port = nil) ⇒ Client
Returns a new instance of Client.
17
18
19
|
# File 'lib/LOLastfm/client.rb', line 17
def initialize (host, port = nil)
@socket = port ? TCPSocket.new(host, port) : UNIXSocket.new(File.expand_path(host))
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/LOLastfm/client.rb', line 25
def method_missing (id, *args, &block)
if @socket.respond_to? id
return @socket.__send__ id, *args, &block
end
super
end
|
Instance Method Details
#close ⇒ Object
41
42
43
44
|
# File 'lib/LOLastfm/client.rb', line 41
def close
@socket.flush
@socket.close
end
|
#read_response ⇒ Object
37
38
39
|
# File 'lib/LOLastfm/client.rb', line 37
def read_response
JSON.parse(?[ + @socket.readline.chomp + ?]).first
end
|
#respond_to_missing?(id, include_private = false) ⇒ Boolean
21
22
23
|
# File 'lib/LOLastfm/client.rb', line 21
def respond_to_missing? (id, include_private = false)
@socket.respond_to?(id, include_private)
end
|
#send_command(type, *arguments) ⇒ Object
33
34
35
|
# File 'lib/LOLastfm/client.rb', line 33
def send_command (type, *arguments)
@socket.puts [type, arguments].to_json
end
|