flexirest 1.2.6 → 1.2.7

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: 0e9746fdcafdd6c3cf776ad61e5c1382d45d2a0f
4
- data.tar.gz: 8dc300d322046a6cde7c8cd94ebdc9d4e5beca6d
3
+ metadata.gz: 71f15a9ae128d914e4299af6b2df98729145280b
4
+ data.tar.gz: 374b73a1124535bb95a8a4abebb90a08cd402cb0
5
5
  SHA512:
6
- metadata.gz: 8a78959e3b2b15fcbb34e00a967187ecf2857796201f56d3279f18d28596539c0e51225712ba9f8c33c005600aaa8c0845693d9e2361aacf5af394a941288a70
7
- data.tar.gz: e3e739a54e53b54218f6224ba8b52ef0261ea6f853b2ec819352fd2f60db86ea861a6b4513038b2ba3efcea33a891334602e717f622a0f8e7487ec771e812e31
6
+ metadata.gz: 98ef9ff1466118b4d1fb39c6b1539ea04c7eb0823cda405850faaa1b13b75c8c5ce424fab97f50429a8a4caa43680d36de8dc2843f31fbf9f4f3356e1ee6855e
7
+ data.tar.gz: 780454d7b0f960d595b0e921acf8e3a3fcd7dd962f3deeee348706508c0f43a37115c0129d834faaa983891046f2580bf54d1885ee8bdcc3222c73ff89f4f10e
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.7
4
+
5
+ Features:
6
+
7
+ - Adds a per request `timeout` option, for individually slow calls
8
+
3
9
  ## 1.2.5/1.2.6
4
10
 
5
11
  Bugfixes:
data/README.md CHANGED
@@ -548,6 +548,16 @@ class Person < Flexirest::Base
548
548
  end
549
549
  ```
550
550
 
551
+ ### Per-request Timeouts
552
+
553
+ There are times when an API is generally quick, but one call is very intensive. You don't want to set a global timeout in the Faraday configuration block, you just want to increase the timeout for this single call. To do this, you can simply pass a `timeout` option when mapping the call containing the response (in seconds).
554
+
555
+ ```ruby
556
+ class Person < Flexirest::Base
557
+ get :all, '/people', timeout: 5
558
+ end
559
+ ```
560
+
551
561
  ### Raw Requests
552
562
 
553
563
  Sometimes you have have a URL that you just want to force through, but have the response handled in the same way as normal objects or you want to have the filters run (say for authentication). The easiest way to do that is to call `_request` on the class:
@@ -38,6 +38,7 @@ module Flexirest
38
38
  set_defaults(options)
39
39
  make_safe_request(path) do
40
40
  @session.get(path) do |req|
41
+ set_per_request_timeout(req, options) if options[:timeout]
41
42
  req.headers = req.headers.merge(options[:headers])
42
43
  sign_request(req, options[:api_auth])
43
44
  end
@@ -48,6 +49,7 @@ module Flexirest
48
49
  set_defaults(options)
49
50
  make_safe_request(path) do
50
51
  @session.put(path) do |req|
52
+ set_per_request_timeout(req, options) if options[:timeout]
51
53
  req.headers = req.headers.merge(options[:headers])
52
54
  req.body = data
53
55
  sign_request(req, options[:api_auth])
@@ -59,6 +61,7 @@ module Flexirest
59
61
  set_defaults(options)
60
62
  make_safe_request(path) do
61
63
  @session.post(path) do |req|
64
+ set_per_request_timeout(req, options) if options[:timeout]
62
65
  req.headers = req.headers.merge(options[:headers])
63
66
  req.body = data
64
67
  sign_request(req, options[:api_auth])
@@ -70,6 +73,7 @@ module Flexirest
70
73
  set_defaults(options)
71
74
  make_safe_request(path) do
72
75
  @session.delete(path) do |req|
76
+ set_per_request_timeout(req, options) if options[:timeout]
73
77
  req.headers = req.headers.merge(options[:headers])
74
78
  sign_request(req, options[:api_auth])
75
79
  end
@@ -78,6 +82,11 @@ module Flexirest
78
82
 
79
83
  private
80
84
 
85
+ def set_per_request_timeout(req, options)
86
+ req.options.timeout = options[:timeout].to_i
87
+ req.options.open_timeout = options[:timeout].to_i
88
+ end
89
+
81
90
  def new_session
82
91
  Faraday.new({url: @base_url}, &Flexirest::Base.faraday_config)
83
92
  end
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.2.6"
2
+ VERSION = "1.2.7"
3
3
  end
@@ -98,6 +98,15 @@ describe Flexirest::Connection do
98
98
  end
99
99
  end
100
100
 
101
+ context 'with custom timeouts' do
102
+ it 'should set a custom timeout' do
103
+ stub_request(:get, "www.example.com/foo")
104
+ .to_return(body: "{result:true}")
105
+ expect_any_instance_of(Flexirest::Connection).to receive(:set_per_request_timeout)
106
+ @connection.get("/foo", {:timeout => "5"})
107
+ end
108
+ end
109
+
101
110
  context 'with api auth signing requests' do
102
111
  before(:each) do
103
112
  # Need to still call this to load the api_auth library so tests work
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.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-03 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler