-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require "linr/version" | ||
require "linr/connection" | ||
|
||
# A simple UDP client for InfluxDB | ||
module Linr | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "linr/connection/udp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Linr | ||
module Connection | ||
class UDP | ||
# Use non-custom flags | ||
SEND_FLAGS = 0 | ||
|
||
# Establishes a connection | ||
# @param host [String] | ||
# @param port [Fixnum] | ||
def initialize(host, port) | ||
@socket = UDPSocket.new | ||
@socket.connect(host, port) | ||
end | ||
|
||
# Send arbitrary data ober the UDP connection | ||
# @param data [String] | ||
def send(data) | ||
@socket.send(data, SEND_FLAGS) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "spec_helper" | ||
|
||
describe ::Linr::Connection::UDP do | ||
subject { ::Linr::Connection::UDP.new(host, port) } | ||
let(:host) { "127.0.0.1" } | ||
let(:port) { 44_000 } | ||
let(:socket) { UDPSocket.new } | ||
|
||
before do | ||
socket.bind(host, port) | ||
end | ||
|
||
it "sends data as passed" do | ||
payload = "measurement,foo=bar,bat=baz value=12,otherval=21 1439587925" | ||
subject.send(payload) | ||
socket.recvfrom(60).first.must_equal payload | ||
end | ||
end |