okuyama 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.1.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.3)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.6.5)
12
+ rake (0.9.2.2)
13
+ rcov (1.0.0)
14
+ rdoc (3.12)
15
+ json (~> 1.4)
16
+ rspec (2.8.0)
17
+ rspec-core (~> 2.8.0)
18
+ rspec-expectations (~> 2.8.0)
19
+ rspec-mocks (~> 2.8.0)
20
+ rspec-core (2.8.0)
21
+ rspec-expectations (2.8.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.1.0)
30
+ jeweler (~> 1.8.3)
31
+ rcov
32
+ rdoc (~> 3.12)
33
+ rspec (~> 2.8.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Kenji Hara
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = okuyama
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to okuyama
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Kenji Hara. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "okuyama"
18
+ gem.homepage = "http://github.com/haracane/okuyama"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{okuyama client for Ruby}
21
+ gem.description = %Q{okuyama client for Ruby}
22
+ gem.email = "haracane@gmail.com"
23
+ gem.authors = ["Kenji Hara"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "okuyama #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,55 @@
1
+ module Okuyama
2
+ class Client
3
+ def initialize(options)
4
+ @host = options[:host] || 'localhost'
5
+ @port = options[:port] || 8888
6
+ end
7
+
8
+ def socket
9
+ if @socket.nil? then
10
+ @socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
11
+ sockaddr = Socket.sockaddr_in(@port, @host)
12
+ @socket.connect(sockaddr)
13
+ end
14
+ return @socket
15
+ end
16
+
17
+ def close
18
+ @socket.close if @socket
19
+ @socket = nil
20
+ end
21
+
22
+ def get_value(key, options=nil)
23
+ message = Okuyama::Protocol.get_value(key,options)
24
+ result = self.send_msg(message,options)
25
+ return result[1]
26
+ end
27
+
28
+ def send_msg(msg, options=nil)
29
+ client = self.socket
30
+ Okuyama.logger.debug "send: #{msg}"
31
+ self.socket.puts(msg)
32
+ result = socket.gets
33
+ result.chomp!
34
+ Okuyama.logger.debug "recv: #{result}"
35
+ ret = self.parse_result(result,options)
36
+ end
37
+
38
+ def set_value(key, val, options=nil)
39
+ tag_list = options[:tags] if options
40
+ message = Okuyama::Protocol.set_value(key, tag_list, val, options)
41
+ result = self.send_msg(message)
42
+ return result
43
+ end
44
+
45
+ def parse_result(result,options=nil)
46
+ record = result.split(/,/)
47
+ code = record.shift
48
+ case code
49
+ when '2'
50
+ record[1] = Base64.decode64(record[1])
51
+ end
52
+ return record
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,21 @@
1
+ module Okuyama
2
+ module Protocol
3
+ def self.set_value(key, tag_list, val, options=nil)
4
+ key_base64 = Base64.encode64(key).chomp
5
+ val_base64 = Base64.encode64(val).chomp
6
+ tags = nil
7
+ if tag_list then
8
+ tags = tag_list.map{|t|Base64.encode64(t).chomp}.join(':')
9
+ end
10
+ tags ||= "(B)"
11
+ dlock = 0
12
+ return "1,#{key_base64},#{tags},#{dlock},#{val_base64}"
13
+ end
14
+
15
+ def self.get_value(key, options=nil)
16
+ key_base64 = Base64.encode64(key).chomp
17
+ return "2,#{key_base64}"
18
+ end
19
+
20
+ end
21
+ end
data/lib/okuyama.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'base64'
2
+ require 'socket'
3
+
4
+ autoload :Logger, 'logger'
5
+
6
+ module Okuyama
7
+ autoload :Client, 'okuyama/client'
8
+ autoload :Protocol, 'okuyama/protocol'
9
+
10
+ class OkuyamaError < RuntimeError; end
11
+
12
+ def self.logger
13
+ @logger ||= (rails_logger || default_logger)
14
+ end
15
+
16
+ def self.rails_logger
17
+ (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
18
+ (defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:debug) && RAILS_DEFAULT_LOGGER)
19
+ end
20
+
21
+ def self.default_logger
22
+ require 'logger'
23
+ l = Logger.new(STDOUT)
24
+ l.level = Logger::INFO
25
+ l
26
+ end
27
+
28
+ def self.logger=(logger)
29
+ @logger = logger
30
+ end
31
+
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Okuyama::Client do
4
+ before :each do
5
+ @client = Okuyama::Client.new(:host=>'localhost', :port=>8888)
6
+ end
7
+
8
+ after :each do
9
+ @client.close
10
+ end
11
+
12
+ it "should set value without tags" do
13
+ result = @client.set_value('testkey', 'testval')
14
+ result.should == ["true", "OK"]
15
+ end
16
+
17
+ it "should set value with tags" do
18
+ result = @client.set_value('testkey', 'testval', :tags=>['testtag'])
19
+ result.should == ["true", "OK"]
20
+ end
21
+
22
+ it "should get value with tags" do
23
+ result = @client.set_value('testkey', 'testval')
24
+ result = @client.get_value('testkey')
25
+ result.should == 'testval'
26
+ end
27
+
28
+ end
29
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Okuyama" do
4
+ # it "fails" do
5
+ # fail "hey buddy, you should probably rename this file and start specing for real"
6
+ # end
7
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'okuyama'
5
+
6
+ Okuyama.logger = Logger.new(STDERR)
7
+ Okuyama.logger.level = Logger::ERROR
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: okuyama
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Kenji Hara
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-24 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ type: :development
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 47
28
+ segments:
29
+ - 2
30
+ - 8
31
+ - 0
32
+ version: 2.8.0
33
+ version_requirements: *id001
34
+ name: rspec
35
+ prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 31
44
+ segments:
45
+ - 3
46
+ - 12
47
+ version: "3.12"
48
+ version_requirements: *id002
49
+ name: rdoc
50
+ prerelease: false
51
+ - !ruby/object:Gem::Dependency
52
+ type: :development
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 19
59
+ segments:
60
+ - 1
61
+ - 1
62
+ - 0
63
+ version: 1.1.0
64
+ version_requirements: *id003
65
+ name: bundler
66
+ prerelease: false
67
+ - !ruby/object:Gem::Dependency
68
+ type: :development
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 49
75
+ segments:
76
+ - 1
77
+ - 8
78
+ - 3
79
+ version: 1.8.3
80
+ version_requirements: *id004
81
+ name: jeweler
82
+ prerelease: false
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ requirement: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ version_requirements: *id005
95
+ name: rcov
96
+ prerelease: false
97
+ description: okuyama client for Ruby
98
+ email: haracane@gmail.com
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ extra_rdoc_files:
104
+ - LICENSE.txt
105
+ - README.rdoc
106
+ files:
107
+ - .document
108
+ - .rspec
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.rdoc
113
+ - Rakefile
114
+ - VERSION
115
+ - lib/okuyama.rb
116
+ - lib/okuyama/client.rb
117
+ - lib/okuyama/protocol.rb
118
+ - spec/okuyama/client_spec.rb
119
+ - spec/okuyama_spec.rb
120
+ - spec/spec_helper.rb
121
+ homepage: http://github.com/haracane/okuyama
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.21
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: okuyama client for Ruby
154
+ test_files: []
155
+