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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +10 -8
- data/lib/flexirest/configuration.rb +7 -1
- data/lib/flexirest/request.rb +6 -2
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/request_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbe7c1432cd8992f3dfd355a9fed8cbee4be01e7
|
4
|
+
data.tar.gz: f03b53479a859ca5efab8e9443fb4e866f989a19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7212ded06e8af46d42c07d5ed65856f18f595351a8102e9f48125f1662611e47cff0183f8c01c9bd83aaabdb020e946d9bf6f0d82d0965bdc8b9bb36f7359701
|
7
|
+
data.tar.gz: 0ff3eeba770b12c1ef02f0db7f6a13d717ae6868bc1754168e402531f5979714d4900d77ce85fe816c2911648ac4addd70e37232234b0382d39bef161bd118cc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Flexirest
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/
|
5
|
-
[![Code Climate](https://codeclimate.com/github/
|
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/
|
8
|
-
[![Percentage of issues still open](http://isitmaintained.com/badge/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
|
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/
|
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/
|
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
|
-
|
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
|
data/lib/flexirest/request.rb
CHANGED
@@ -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?
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/request_spec.rb
CHANGED
@@ -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.
|
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
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|