lib/norikra/client.rb in norikra-client-1.4.0 vs lib/norikra/client.rb in norikra-client-1.5.0
- old
+ new
@@ -9,17 +9,16 @@
class ServiceUnavailableError < MessagePack::RPCOverHTTP::RemoteError; end
end
class Client
RPC_DEFAULT_PORT = 26571
- TIMEOUT_OPTIONS = [:connect_timeout, :send_timeout, :receive_timeout]
- def initialize(host='localhost', port=RPC_DEFAULT_PORT, opts={})
+ def initialize(host='localhost', port=RPC_DEFAULT_PORT, connect_timeout: nil, send_timeout: nil, receive_timeout: nil)
@client = MessagePack::RPCOverHTTP::Client.new("http://#{host}:#{port}/")
- @client.connect_timeout = opts[:connect_timeout] if opts.has_key?(:connect_timeout) && @client.respond_to?('connect_timeout='.to_sym)
- @client.send_timeout = opts[:send_timeout] if opts.has_key?(:send_timeout) && @client.respond_to?('send_timeout='.to_sym)
- @client.receive_timeout = opts[:receive_timeout] if opts.has_key?(:receive_timeout) && @client.respond_to?('receive_timeout='.to_sym)
+ @client.connect_timeout = connect_timeout if connect_timeout
+ @client.send_timeout = send_timeout if send_timeout
+ @client.receive_timeout = receive_timeout if receive_timeout
end
def targets
@client.call(:targets) #=> {:name => "name", :auto_field => true}
end