leela_client 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ leela_client (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.8.0)
11
+ rspec-core (~> 2.8.0)
12
+ rspec-expectations (~> 2.8.0)
13
+ rspec-mocks (~> 2.8.0)
14
+ rspec-core (2.8.0)
15
+ rspec-expectations (2.8.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.8.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ leela_client!
24
+ rspec
data/leela_client.gemspec CHANGED
@@ -13,4 +13,6 @@ Gem::Specification.new do |gem|
13
13
 
14
14
  gem.name = "leela_client"
15
15
  gem.version = LeelaClient::VERSION
16
+
17
+ gem.add_development_dependency "rspec"
16
18
  end
data/lib/leela_client.rb CHANGED
@@ -1,5 +1,26 @@
1
1
  require "leela_client/version"
2
+ require "socket"
2
3
 
3
4
  module LeelaClient
4
- # Your code goes here...
5
+ class Client
6
+ attr_reader :data
7
+
8
+ def initialize(service, server="127.0.0.1", port=6968)
9
+ @server, @port = server, port
10
+ @service = service
11
+ @data = []
12
+ end
13
+
14
+ def add(name, value)
15
+ @data << "#{name}|#{value}"
16
+ end
17
+
18
+ def publish
19
+ sock = UDPSocket.new
20
+ sock.connect(@server, @port)
21
+
22
+ message = "#{Socket.gethostname}|#{@service}||" + @data.join("||")
23
+ sock.send(message, 0)
24
+ end
25
+ end
5
26
  end
@@ -1,3 +1,3 @@
1
1
  module LeelaClient
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe LeelaClient do
4
+ it "shold add the correct data in normal order" do
5
+ leela = LeelaClient::Client.new "service"
6
+
7
+ leela.data.should be_empty
8
+ leela.add("attr", 10)
9
+ leela.data.should have(1).item
10
+
11
+ leela.add("attr", 20)
12
+ leela.data.should have(2).items
13
+ leela.data.last.should eql("attr|20")
14
+ end
15
+
16
+ it "should send the complete information to the socket" do
17
+ host = "machine"
18
+ Socket.stub(:gethostname).and_return(host)
19
+
20
+ sock = UDPSocket.new
21
+ sock.bind("127.0.0.1",6968)
22
+
23
+ leela = LeelaClient::Client.new("service", "127.0.0.1", 6968)
24
+ leela.add("param", 50)
25
+ leela.publish
26
+
27
+ sock.recvfrom(100)[0].should eql("machine|service||param|50")
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ require "leela_client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leela_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,19 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-26 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2012-03-28 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &14789040 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *14789040
15
26
  description: A client for leela chart server
16
27
  email:
17
28
  - pothix@pothix.com
@@ -20,7 +31,10 @@ executables: []
20
31
  extensions: []
21
32
  extra_rdoc_files: []
22
33
  files:
34
+ - ./Gemfile.lock
23
35
  - ./leela_client.gemspec
36
+ - ./spec/spec_helper.rb
37
+ - ./spec/leela_client_spec.rb
24
38
  - ./Gemfile
25
39
  - ./Rakefile
26
40
  - ./lib/leela_client/version.rb