flexirest 1.3.17 → 1.3.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3f5b7fd58fca9e5b1af0e80cd566a98404033d4
4
- data.tar.gz: 66f2a9a29930347f6e72452b12d2adff5ab18145
3
+ metadata.gz: cbe7c1432cd8992f3dfd355a9fed8cbee4be01e7
4
+ data.tar.gz: f03b53479a859ca5efab8e9443fb4e866f989a19
5
5
  SHA512:
6
- metadata.gz: c2f55e90d6c57f50cb85b90f3acdd1981d8ff0bb206591ecf26f1d002c286cf71c4bc76d1b3d671c9f5a459d92ba3b12e6627e0c0fc2692a12c8b3e6e52ece67
7
- data.tar.gz: 989344a2cece5f68cb99df45b2a4a0bb9372839be88c3853acf20d9b8710b813cfa26a7ed976176c450e6090dd204541ba5451f16319bbd09fa33fa49ba1b948
6
+ metadata.gz: 7212ded06e8af46d42c07d5ed65856f18f595351a8102e9f48125f1662611e47cff0183f8c01c9bd83aaabdb020e946d9bf6f0d82d0965bdc8b9bb36f7359701
7
+ data.tar.gz: 0ff3eeba770b12c1ef02f0db7f6a13d717ae6868bc1754168e402531f5979714d4900d77ce85fe816c2911648ac4addd70e37232234b0382d39bef161bd118cc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.18
4
+
5
+ Feature:
6
+
7
+ - Simplistic load balancing of API servers by supplying an array of URLs to `base_url`. It then pulls a random one out for each request.
8
+
3
9
  ## 1.3.17
4
10
 
5
11
  Bugfix:
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Flexirest
2
2
 
3
- [![Build Status](https://travis-ci.org/andyjeffries/flexirest.svg?branch=master)](https://travis-ci.org/andyjeffries/flexirest)
4
- [![Coverage Status](https://coveralls.io/repos/andyjeffries/flexirest/badge.png)](https://coveralls.io/r/andyjeffries/flexirest)
5
- [![Code Climate](https://codeclimate.com/github/andyjeffries/flexirest.png)](https://codeclimate.com/github/andyjeffries/flexirest)
3
+ [![Build Status](https://travis-ci.org/flexirest/flexirest.svg?branch=master)](https://travis-ci.org/flexirest/flexirest)
4
+ [![Coverage Status](https://coveralls.io/repos/github/flexirest/flexirest/badge.svg?branch=master)](https://coveralls.io/github/flexirest/flexirest?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/flexirest/flexirest.png)](https://codeclimate.com/github/flexirest/flexirest)
6
6
  [![Gem Version](https://badge.fury.io/rb/flexirest.png)](http://badge.fury.io/rb/flexirest)
7
- [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/andyjeffries/flexirest.svg)](http://isitmaintained.com/project/andyjeffries/flexirest "Average time to resolve an issue")
8
- [![Percentage of issues still open](http://isitmaintained.com/badge/open/andyjeffries/flexirest.svg)](http://isitmaintained.com/project/andyjeffries/flexirest "Percentage of issues still open")
7
+ [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/flexirest/flexirest.svg)](http://isitmaintained.com/project/flexirest/flexirest "Average time to resolve an issue")
8
+ [![Percentage of issues still open](http://isitmaintained.com/badge/open/flexirest/flexirest.svg)](http://isitmaintained.com/project/flexirest/flexirest "Percentage of issues still open")
9
9
 
10
10
  This gem is for accessing REST services in an ActiveRecord style. ActiveResource already exists for this, but it doesn't work where the resource naming doesn't follow Rails conventions, it doesn't have in-built caching and it's not as flexible in general.
11
11
 
@@ -53,7 +53,9 @@ Note I've specified the base_url in the class above. This is useful where you w
53
53
  Flexirest::Base.base_url = "https://www.example.com/api/v1"
54
54
  ```
55
55
 
56
- Any `base_url` settings in specific classes override this declared default. You can then use your new class like this:
56
+ Any `base_url` settings in specific classes override this declared default. You can also assign an array of URLs to `base_url` and Flexirest will randomly pull one of the URLs for each request, giving you a very simplistic load balancing (it doesn't know about the health or load levels of the backends).
57
+
58
+ You can then use your new class like this:
57
59
 
58
60
  ```ruby
59
61
  # Create a new person
@@ -125,7 +127,7 @@ puts @person.to_json
125
127
 
126
128
  ### Ruby on Rails Integration
127
129
 
128
- A detailed guide, how to integrate Flexirest with a RESTful resources can be found in the [Ruby-on-Rails-Integration.md](https://github.com/andyjeffries/flexirest/blob/master/Ruby-on-Rails-Integration.md).
130
+ A detailed guide, how to integrate Flexirest with a RESTful resources can be found in the [Ruby-on-Rails-Integration.md](https://github.com/flexirest/flexirest/blob/master/Ruby-on-Rails-Integration.md).
129
131
 
130
132
  ## Advanced Features
131
133
 
@@ -141,7 +143,7 @@ Flexirest::Base.adapter = :patron
141
143
 
142
144
  In versions before 1.2.0 the adapter was hardcoded to `:patron`, so if you want to ensure it still uses Patron, you should set this setting.
143
145
 
144
- If you want more control you can pass a **complete** configuration block ("complete" means that the block does not *override* [the default configuration](https://github.com/andyjeffries/flexirest/blob/5b1953d89e26c02ca74f74464ccb7cd4c9439dcc/lib/flexirest/configuration.rb#L184-L201), but rather *replaces* it). For available config variables look into the Faraday documentation.
146
+ If you want more control you can pass a **complete** configuration block ("complete" means that the block does not *override* [the default configuration](https://github.com/flexirest/flexirest/blob/5b1953d89e26c02ca74f74464ccb7cd4c9439dcc/lib/flexirest/configuration.rb#L184-L201), but rather *replaces* it). For available config variables look into the Faraday documentation.
145
147
 
146
148
  ```ruby
147
149
  Flexirest::Base.faraday_config do |faraday|
@@ -27,7 +27,13 @@ module Flexirest
27
27
  end
28
28
  value
29
29
  else
30
- value = value.gsub(/\/$/, '')
30
+ if value.is_a?(Array)
31
+ value.each_with_index do |v, k|
32
+ value[k] = v.gsub(/\/$/, '')
33
+ end
34
+ else
35
+ value = value.gsub(/\/$/, '')
36
+ end
31
37
  @base_url = value
32
38
  end
33
39
  end
@@ -45,10 +45,14 @@ module Flexirest
45
45
 
46
46
  def base_url
47
47
  if object_is_class?
48
- @object.base_url
48
+ url = @object.base_url
49
49
  else
50
- @object.class.base_url
50
+ url = @object.class.base_url
51
51
  end
52
+ if url.is_a?(Array)
53
+ url = url.sample
54
+ end
55
+ url
52
56
  end
53
57
 
54
58
  def using_api_auth?
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.3.17"
2
+ VERSION = "1.3.18"
3
3
  end
@@ -44,6 +44,11 @@ describe Flexirest::Request do
44
44
  get :requires, "/requires", requires:[:name, :age]
45
45
  end
46
46
 
47
+ class ExampleLoadBalancedClient < Flexirest::Base
48
+ base_url ["http://api1.example.com", "http://api2.example.com"]
49
+ get :all, "/", :has_many => {:expenses => ExampleOtherClient}
50
+ end
51
+
47
52
  class AuthenticatedExampleClient < Flexirest::Base
48
53
  base_url "http://www.example.com"
49
54
  username "john"
@@ -104,6 +109,21 @@ describe Flexirest::Request do
104
109
  ExampleClient.all
105
110
  end
106
111
 
112
+ it "should get an HTTP connection from one of the servers when called if multiple are specified" do
113
+ connection = double(Flexirest::Connection).as_null_object
114
+ expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{})))
115
+ servers = []
116
+ # TODO: this next test is potentially flakey, if over 10 runs of []#sample it doesn't return both variants, but it's so unlikely...
117
+ 10.times do
118
+ expect(Flexirest::ConnectionManager).to receive(:get_connection) do |arg|
119
+ servers << arg
120
+ connection
121
+ end
122
+ ExampleLoadBalancedClient.all
123
+ end
124
+ expect(servers.uniq.count).to eq(2)
125
+ end
126
+
107
127
  it "should get an HTTP connection with authentication when called" do
108
128
  connection = double(Flexirest::Connection).as_null_object
109
129
  expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john:smith@www.example.com").and_return(connection)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.17
4
+ version: 1.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler