lib/udp2sqs_client/client.rb in udp2sqs_client-0.1.0 vs lib/udp2sqs_client/client.rb in udp2sqs_client-0.2.0
- old
+ new
@@ -2,22 +2,24 @@
module Udp2sqsClient
class Client
- def initialize
- @host, @port = "localhost", 9732
- end
+ attr_reader :host, :port
- def configure(host: "localhost", port: 9732)
- @host, @port = host, port
+ def initialize(options = {})
+ @host = options.fetch(:host, "localhost")
+ @port = options.fetch(:post, 9732)
end
- def send(message)
- s = UDPSocket.new
- bytes_sent = s.send(message, 0, @host, @port)
- return bytes_sent == message.bytesize
+ def send_message(message)
+ begin
+ s = UDPSocket.new
+ bytes_sent = s.send(message, 0, host, port)
+ bytes_sent == message.bytesize
+ rescue SocketError => e
+ $stderr.puts "Udp2sqs failed to send : #{e}"
+ false
+ end
end
-
end
-
end