load_balance_client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -33,6 +33,23 @@ class LoadBalanceClient
33
33
  end
34
34
  end
35
35
 
36
+ def self.post(url, body)
37
+ server = @@servers[rand(@@servers.length)]
38
+ begin
39
+ RestClient.post(server + url, body) 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 post(url, body) unless @@servers.length == 0
50
+ end
51
+ end
52
+
36
53
  def self.delete(url)
37
54
  server = @@servers[rand(@@servers.length)]
38
55
  begin
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "load_balance_client"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Acuff", "Justin Hill", "Matt Brown"]
12
- s.date = "2012-02-24"
12
+ s.date = "2012-03-09"
13
13
  s.description = "Simple wrapper around RestClient to make load balanced http requests"
14
14
  s.email = "support@igodigital.com"
15
15
  s.extra_rdoc_files = [
data/test/client_test.rb CHANGED
@@ -11,6 +11,15 @@ class ClientTest < MiniTest::Unit::TestCase
11
11
  assert_equal ['http://localhost:9200'], LoadBalanceClient.server_list
12
12
  end
13
13
 
14
+ def test_bad_node_for_post
15
+ LoadBalanceClient.server_list=['http://localhost:9200', 'http://localhost:46250']
16
+ 10.times do
17
+ LoadBalanceClient.post '/igodigital/users/abc123', {'foo'=>'bar'}.to_json
18
+ end
19
+ assert_equal 1, LoadBalanceClient.server_list.length
20
+ assert_equal ['http://localhost:9200'], LoadBalanceClient.server_list
21
+ end
22
+
14
23
  def test_bad_node_for_get
15
24
  LoadBalanceClient.server_list=['http://localhost:9200', 'http://localhost:46250']
16
25
  10.times do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: load_balance_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-02-24 00:00:00.000000000 Z
14
+ date: 2012-03-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client
18
- requirement: &2156967080 !ruby/object:Gem::Requirement
18
+ requirement: &70234161800420 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 1.6.7
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *2156967080
26
+ version_requirements: *70234161800420
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jeweler
29
- requirement: &2156966540 !ruby/object:Gem::Requirement
29
+ requirement: &70234161796540 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 1.6.4
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *2156966540
37
+ version_requirements: *70234161796540
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: json
40
- requirement: &2156966040 !ruby/object:Gem::Requirement
40
+ requirement: &70234161795100 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: '0'
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *2156966040
48
+ version_requirements: *70234161795100
49
49
  description: Simple wrapper around RestClient to make load balanced http requests
50
50
  email: support@igodigital.com
51
51
  executables: []