load_balance_client 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +37 -0
- data/README.md +7 -0
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/lib/load_balance_client.rb +62 -0
- data/load_balance_client.gemspec +54 -0
- data/test/client_test.rb +31 -0
- data/test/test_helper.rb +16 -0
- metadata +91 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3@load_balance_client
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'http://gemcutter.org'
|
2
|
+
|
3
|
+
gem 'rest-client', '~>1.6.7'
|
4
|
+
gem 'jeweler', '~>1.6.4'
|
5
|
+
gem 'json'
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem 'autotest'
|
9
|
+
gem 'autotest-growl'
|
10
|
+
gem 'simplecov', '=0.4.2', :require => false
|
11
|
+
gem 'minitest-colorize'
|
12
|
+
gem 'awesome_print'
|
13
|
+
end
|
14
|
+
|
15
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://gemcutter.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.6.2)
|
5
|
+
autotest (4.4.6)
|
6
|
+
ZenTest (>= 4.4.1)
|
7
|
+
autotest-growl (0.2.16)
|
8
|
+
awesome_print (1.0.2)
|
9
|
+
git (1.2.5)
|
10
|
+
jeweler (1.6.4)
|
11
|
+
bundler (~> 1.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
json (1.6.5)
|
15
|
+
mime-types (1.17.2)
|
16
|
+
minitest (2.11.2)
|
17
|
+
minitest-colorize (0.0.4)
|
18
|
+
minitest (~> 2.0)
|
19
|
+
rake (0.9.2.2)
|
20
|
+
rest-client (1.6.7)
|
21
|
+
mime-types (>= 1.16)
|
22
|
+
simplecov (0.4.2)
|
23
|
+
simplecov-html (~> 0.4.4)
|
24
|
+
simplecov-html (0.4.5)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
autotest
|
31
|
+
autotest-growl
|
32
|
+
awesome_print
|
33
|
+
jeweler (~> 1.6.4)
|
34
|
+
json
|
35
|
+
minitest-colorize
|
36
|
+
rest-client (~> 1.6.7)
|
37
|
+
simplecov (= 0.4.2)
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
Dir.glob('lib/tasks/*.rake').each { |r| import r }
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.pattern = "test/*_test.rb"
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'jeweler'
|
9
|
+
Jeweler::Tasks.new do |gem|
|
10
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
11
|
+
gem.name = "load_balance_client"
|
12
|
+
gem.homepage = "https://github.com/iGoDigital-LLC/load_balance_client"
|
13
|
+
gem.license = "MIT"
|
14
|
+
gem.summary = "A load balance client"
|
15
|
+
gem.description = "Simple wrapper around RestClient to make load balanced http requests"
|
16
|
+
gem.email = "support@igodigital.com"
|
17
|
+
gem.authors = ["Nathan Acuff", "Justin Hill", "Matt Brown"]
|
18
|
+
# dependencies defined in Gemfile
|
19
|
+
end
|
20
|
+
Jeweler::RubygemsDotOrgTasks.new
|
21
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class LoadBalanceClient
|
2
|
+
def self.get(url)
|
3
|
+
server = @@servers[rand(@@servers.length)]
|
4
|
+
begin
|
5
|
+
RestClient.get(server + url) do |response, request, result, &block|
|
6
|
+
case response.code
|
7
|
+
when 200
|
8
|
+
JSON.parse(response.body)
|
9
|
+
else
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
rescue Errno::ECONNREFUSED => e
|
14
|
+
@@servers.delete(server)
|
15
|
+
return get(url) unless @@servers.length == 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.put(url, body)
|
20
|
+
server = @@servers[rand(@@servers.length)]
|
21
|
+
begin
|
22
|
+
RestClient.put(server + url, body) do |response, request, result, &block|
|
23
|
+
case response.code
|
24
|
+
when 200
|
25
|
+
JSON.parse(response.body)
|
26
|
+
else
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue Errno::ECONNREFUSED => e
|
31
|
+
@@servers.delete(server)
|
32
|
+
return put(url, body) unless @@servers.length == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.delete(url)
|
37
|
+
server = @@servers[rand(@@servers.length)]
|
38
|
+
begin
|
39
|
+
RestClient.delete(server + url) do |response, request, result, &block|
|
40
|
+
case response.code
|
41
|
+
when 200
|
42
|
+
JSON.parse(response.body)
|
43
|
+
else
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
rescue Errno::ECONNREFUSED => e
|
48
|
+
@@servers.delete(server)
|
49
|
+
return delete(url) unless @@servers.length == 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.server_list=(values)
|
54
|
+
list = values.is_a?(Array) ? values : [values]
|
55
|
+
@@servers = list
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.server_list
|
59
|
+
@@servers
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "load_balance_client"
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nathan Acuff", "Justin Hill", "Matt Brown"]
|
12
|
+
s.date = "2012-02-24"
|
13
|
+
s.description = "Simple wrapper around RestClient to make load balanced http requests"
|
14
|
+
s.email = "support@igodigital.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".rvmrc",
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/load_balance_client.rb",
|
26
|
+
"load_balance_client.gemspec",
|
27
|
+
"test/client_test.rb",
|
28
|
+
"test/test_helper.rb"
|
29
|
+
]
|
30
|
+
s.homepage = "https://github.com/iGoDigital-LLC/load_balance_client"
|
31
|
+
s.licenses = ["MIT"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = "1.8.10"
|
34
|
+
s.summary = "A load balance client"
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.7"])
|
41
|
+
s.add_runtime_dependency(%q<jeweler>, ["~> 1.6.4"])
|
42
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
|
45
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
46
|
+
s.add_dependency(%q<json>, [">= 0"])
|
47
|
+
end
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
|
50
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
+
s.add_dependency(%q<json>, [">= 0"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class ClientTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_bad_node_for_put
|
6
|
+
LoadBalanceClient.server_list=['http://localhost:9200', 'http://localhost:46250']
|
7
|
+
10.times do
|
8
|
+
LoadBalanceClient.put '/igodigital/users/abc123', {'foo'=>'bar'}.to_json
|
9
|
+
end
|
10
|
+
assert_equal 1, LoadBalanceClient.server_list.length
|
11
|
+
assert_equal ['http://localhost:9200'], LoadBalanceClient.server_list
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_bad_node_for_get
|
15
|
+
LoadBalanceClient.server_list=['http://localhost:9200', 'http://localhost:46250']
|
16
|
+
10.times do
|
17
|
+
LoadBalanceClient.get '/'
|
18
|
+
end
|
19
|
+
assert_equal 1, LoadBalanceClient.server_list.length
|
20
|
+
assert_equal ['http://localhost:9200'], LoadBalanceClient.server_list
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_bad_node_for_delete
|
24
|
+
LoadBalanceClient.server_list=['http://localhost:9200', 'http://localhost:46250']
|
25
|
+
10.times do
|
26
|
+
LoadBalanceClient.delete '/igodigital/users/abc123'
|
27
|
+
end
|
28
|
+
assert_equal 1, LoadBalanceClient.server_list.length
|
29
|
+
assert_equal ['http://localhost:9200'], LoadBalanceClient.server_list
|
30
|
+
end
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require
|
3
|
+
require 'simplecov'
|
4
|
+
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter "test/test*"
|
7
|
+
add_group "Lib", "lib"
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'minitest/autorun'
|
11
|
+
|
12
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/load_balance_client")
|
13
|
+
require 'awesome_print'
|
14
|
+
|
15
|
+
ENV['RACK_ENV'] = 'test'
|
16
|
+
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: load_balance_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nathan Acuff
|
9
|
+
- Justin Hill
|
10
|
+
- Matt Brown
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2012-02-24 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rest-client
|
18
|
+
requirement: &2156967080 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.7
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2156967080
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
requirement: &2156966540 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.4
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2156966540
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: json
|
40
|
+
requirement: &2156966040 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *2156966040
|
49
|
+
description: Simple wrapper around RestClient to make load balanced http requests
|
50
|
+
email: support@igodigital.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files:
|
54
|
+
- README.md
|
55
|
+
files:
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- Gemfile.lock
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- VERSION
|
62
|
+
- lib/load_balance_client.rb
|
63
|
+
- load_balance_client.gemspec
|
64
|
+
- test/client_test.rb
|
65
|
+
- test/test_helper.rb
|
66
|
+
homepage: https://github.com/iGoDigital-LLC/load_balance_client
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.10
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: A load balance client
|
91
|
+
test_files: []
|