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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 84710c0524e0f1372564277a6c79c58c488518eb0c5bd3aa3b77bbcb0ed1e2b7
4
- data.tar.gz: 9b76c1b8de6609b3291228c736fbc518a44fec6e998f8d602aa29ecee3fdc03f
2
+ SHA1:
3
+ metadata.gz: 463e709b2076a5a3a4a72c51f1cc6795478cd0fa
4
+ data.tar.gz: 56d439b1477fb44290a50a51b92c09739b19434f
5
5
  SHA512:
6
- metadata.gz: a1660a6e93d37e1d3300052030f1dd7ae716ff8186ce0657e36cbbabd0386c3e4ee3e016c8e6e028046feea6583f53bf149e0beaa1d83619155b489741756743
7
- data.tar.gz: a8890a505edaba286a35d35c933008f8a44c784f876915c5ca4cfc07284ba4c5a9cadb284d9440a7ed3ff09c8ff3ab543fac145f0b9ad16f5f38a7149c2a7270
6
+ metadata.gz: e08bf5b55cbc777ee8d08bd2b311d81884881cc4498927ae8f0b1e50bdeace0dcd0742224f216a6ed57807fcdd929528e2a9943e6decbd36a2df12a735f90d69
7
+ data.tar.gz: 21a256c7f3f669603627401ac4642352e8ff0264c544a109aab1355f9b3d92391e3b743ada0b2b93426eb1b343e95bbfedd1b846225e116409b70c12c4bfb2c0
@@ -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
- ## Waiting Time
23
+ ## Response callback
24
24
 
25
- Facebook has [hourly rate limiting](https://developers.facebook.com/docs/graph-api/advanced/rate-limiting/#application-level-rate-limiting). `Fb::HTTPRequest` has `waiting_time` class variable
26
- to sleep the amount of time (in seconds) when it is approaching (with 85% of usage)
27
- in case the variable is set as follows.
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.waiting_time = 360
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
@@ -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
- # @return [Integer] time in seconds for waiting when hourly rate limit
39
- # for the Facebook app reached over 85%
40
- attr_accessor :waiting_time
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
- if (waiting_time = self.class.waiting_time) && rate_limiting_header &&
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
@@ -3,6 +3,6 @@ module Fb
3
3
  module Support
4
4
  # @return [String] the SemVer-compatible gem version.
5
5
  # @see http://semver.org
6
- VERSION = '1.0.0.alpha6'
6
+ VERSION = '1.0.0.alpha7'
7
7
  end
8
8
  end
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.alpha6
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: 2018-08-31 00:00:00.000000000 Z
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.7.6
145
+ rubygems_version: 2.6.14.3
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: Support utilities for Fb gems