fbauth 1.0.0.2 → 1.1.0.0
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.
- data/lib/facebook_http.rb +22 -13
- metadata +3 -3
data/lib/facebook_http.rb
CHANGED
@@ -15,26 +15,35 @@ module FacebookHttp
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def caching_enabled?
|
19
|
+
ActionController::Base.cache_store.class.name == "ActiveSupport::Cache::MemCacheStore"
|
20
|
+
end
|
21
|
+
|
18
22
|
def get(url, params = {})
|
19
23
|
json = nil
|
20
24
|
uri = URI.parse(build_get_url(url, params))
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
response = http.request(req)
|
27
|
-
raise "Facebook error response #{response.code} - #{response.body}" unless response.code == '200'
|
25
|
+
|
26
|
+
json = Rails.cache.read(uri.to_s) if caching_enabled?
|
27
|
+
if json.nil?
|
28
|
+
bench = Benchmark.measure do
|
29
|
+
http = Net::HTTP.new uri.host, uri.port
|
28
30
|
begin
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
http.use_ssl = (uri.scheme == "https")
|
32
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
33
|
+
response = http.request(req)
|
34
|
+
raise "Facebook error response #{response.code} - #{response.body}" unless response.code == '200'
|
35
|
+
begin
|
36
|
+
json = JSON.parse(response.body)
|
37
|
+
rescue => e
|
38
|
+
raise "Error parsing facebook response: #{response.body}"
|
39
|
+
end
|
40
|
+
ensure
|
41
|
+
http.finish if http.started?
|
32
42
|
end
|
33
|
-
ensure
|
34
|
-
http.finish if http.started?
|
35
43
|
end
|
44
|
+
logger.warn("Facebook GET call to #{uri.to_s} completed in #{bench.real} seconds")
|
45
|
+
Rails.cache.write(uri.to_s, json, :expires_in => 60) if json && caching_enabled?
|
36
46
|
end
|
37
|
-
logger.warn("Facebook GET call to #{uri.to_s} completed in #{bench.real} seconds")
|
38
47
|
json
|
39
48
|
end
|
40
49
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 87
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
10
|
- 0
|
10
|
-
|
11
|
-
version: 1.0.0.2
|
11
|
+
version: 1.1.0.0
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Three Wise Men Inc.
|