fb-support 1.0.0.alpha6 → 1.0.0.alpha7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +14 -5
- data/lib/fb/http_request.rb +16 -7
- data/lib/fb/support/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 463e709b2076a5a3a4a72c51f1cc6795478cd0fa
|
4
|
+
data.tar.gz: 56d439b1477fb44290a50a51b92c09739b19434f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e08bf5b55cbc777ee8d08bd2b311d81884881cc4498927ae8f0b1e50bdeace0dcd0742224f216a6ed57807fcdd929528e2a9943e6decbd36a2df12a735f90d69
|
7
|
+
data.tar.gz: 21a256c7f3f669603627401ac4642352e8ff0264c544a109aab1355f9b3d92391e3b743ada0b2b93426eb1b343e95bbfedd1b846225e116409b70c12c4bfb2c0
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,9 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
+
## 1.0.0.alpha7 - 2019-01-15
|
10
|
+
|
11
|
+
* Remove `waiting_time` and add `on_response` callback.
|
9
12
|
|
10
13
|
## 1.0.0.alpha6 - 2018-08-24
|
11
14
|
|
data/README.md
CHANGED
@@ -20,14 +20,23 @@ Fb::Support provides:
|
|
20
20
|
* [Fb::HTTPRequest](http://www.rubydoc.info/gems/fb-support/Fb/HTTPRequest)
|
21
21
|
* [Fb::HTTPError](http://www.rubydoc.info/gems/fb-support/Fb/HTTPError)
|
22
22
|
|
23
|
-
##
|
23
|
+
## Response callback
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
`Fb::HTTPRequest` has an `on_response` callback which is invoked with
|
26
|
+
the request object and the HTTP response object on a successful
|
27
|
+
response. This can be used for introspecting responses, performing some
|
28
|
+
action when rate limit is near, etc.
|
28
29
|
|
29
30
|
```rb
|
30
|
-
Fb::HTTPRequest.
|
31
|
+
Fb::HTTPRequest.on_response = lambda do |request, response|
|
32
|
+
usage = request.rate_limiting_header
|
33
|
+
Librato.measure 'fb.call_count', usage['call_count']
|
34
|
+
Librato.measure 'fb.total_cputime', usage['total_cputime']
|
35
|
+
Librato.measure 'fb.total_time', usage['total_time']
|
36
|
+
if usage.values.any? {|value| value > 85 }
|
37
|
+
sleep 180
|
38
|
+
end
|
39
|
+
end
|
31
40
|
```
|
32
41
|
|
33
42
|
How to test
|
data/lib/fb/http_request.rb
CHANGED
@@ -34,10 +34,22 @@ module Fb
|
|
34
34
|
@params = options.fetch :params, {}
|
35
35
|
end
|
36
36
|
|
37
|
+
# Callback invoked with the response object on a successful response. Defaults to a noop.
|
38
|
+
# The callback invoked with two parameters: the HTTPRequest object
|
39
|
+
# and the Net::HTTP response object.
|
40
|
+
@@on_response = lambda {|_, _|}
|
41
|
+
|
37
42
|
class << self
|
38
|
-
|
39
|
-
#
|
40
|
-
|
43
|
+
|
44
|
+
# Reader for @@on_response
|
45
|
+
def on_response
|
46
|
+
@@on_response
|
47
|
+
end
|
48
|
+
|
49
|
+
# Writer for @@on_response
|
50
|
+
def on_response=(callback)
|
51
|
+
@@on_response = callback
|
52
|
+
end
|
41
53
|
end
|
42
54
|
|
43
55
|
# Sends the request and returns the response with the body parsed from JSON.
|
@@ -45,10 +57,7 @@ module Fb
|
|
45
57
|
# @raise [Fb::HTTPError] if the request fails.
|
46
58
|
def run
|
47
59
|
if response.is_a? @expected_response
|
48
|
-
|
49
|
-
rate_limiting_header.values.any? {|value| value > 85 }
|
50
|
-
sleep waiting_time
|
51
|
-
end
|
60
|
+
self.class.on_response.call(self, response)
|
52
61
|
response.tap do
|
53
62
|
parse_response!
|
54
63
|
end
|
data/lib/fb/support/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fb-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Baccigalupo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: 1.3.1
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.6.14.3
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Support utilities for Fb gems
|