Class: FCS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/fcs/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Client

Initialize a new Client object



14
15
16
17
18
19
20
21
# File 'lib/fcs/client.rb', line 14

def initialize(attrs={})
  attrs = FCS.options.merge(attrs)
  Config::VALID_OPTIONS_KEYS.each do |key|
    instance_variable_set("@#{key}".to_sym, attrs[key])
  end

  connect if @auto_connect
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delgate api call to Request



32
33
34
35
36
37
# File 'lib/fcs/client.rb', line 32

def method_missing(method, *args, &block)
  klass = class_for_api_command(method)

  return klass.new(@socket).send(method, *args, &block) if klass
  super(method, *args, &block)
end

Instance Method Details

#connectObject



23
24
25
26
27
28
29
# File 'lib/fcs/client.rb', line 23

def connect
  unless @socket
    @socket = TCPSocket.open(@remote_host, @remote_port, @local_host, @local_port)
    Response.new(@socket).parse_response
  end
  @socket
end