funky 0.2.18 → 0.2.19

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: f79e490243da7655f0de7e622a6888db059af5a3
4
- data.tar.gz: ac848b830fe8ddc6e1acb4dfe195157f366f25c4
3
+ metadata.gz: d0cc82139ba77645ca8723e3aa7ca8ffd5fdb4e0
4
+ data.tar.gz: 2dbead2613813de4aea2dd1ef1f067fd07482298
5
5
  SHA512:
6
- metadata.gz: eb7519f9f86c6b71a9feb16824fb89030a5c06be77167c5b8c9ddb1ab7e6ad25ba2364c54d883f034728c76c9a8e3d8ba385cb7e0a234000826c75379ceb9751
7
- data.tar.gz: 3f5d7a338a2b22631d088fff7b50d86bdcca35a4b7b810b6e8ed76c8f292daa76a813a634d6243211e03c79a784fdfe24c522692a7477f263defb3a4f55165da
6
+ metadata.gz: 72c3b1d0fe5ca08a8eb6e4c0406ec715b8973f0e2fd9d3f7496fff1f01a8c63df5eb5e46cd8de3b969f113394612d9fc9abf7fd0bf5682c11d37809ec777c8d8
7
+ data.tar.gz: 2e889e3efb8e57161daa8a6e384628b62d18bd44cf9b2ac7b5290115d01a7a543bff9a1e3f79f4a39f40081b70a219bdae511769127d859e4f777fedd0fc044d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ 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
+ ## 0.2.19 - 2017/04/20
10
+
11
+ * [IMPROVEMENT] Retry 3 times after a server error or a socket error, to fetch
12
+ data even with any temporary issue from Facebook.
13
+
9
14
  ## 0.2.18 - 2017/04/19
10
15
 
11
16
  * [ENHANCEMENT] `Funky::Page#videos` now fetches more videos by time-based pagination.
data/README.md CHANGED
@@ -47,12 +47,12 @@ There are two ways to configure Funky with your App ID and App Secret:
47
47
  end
48
48
  ```
49
49
 
50
- ##API Overview
50
+ ## API Overview
51
51
 
52
52
  Funky consists of 2 different surface APIs - one to fetch video data
53
53
  from Facebook and one to fetch page data from Facebook.
54
54
 
55
- ##Pages API
55
+ ## Pages API
56
56
 
57
57
  ### Use #where clause to get an array of videos
58
58
 
@@ -65,7 +65,7 @@ pages.first.username # => 'SonyPicturesGlobal'
65
65
 
66
66
  ```
67
67
 
68
- ##Videos API
68
+ ## Videos API
69
69
 
70
70
  ### Use #where clause to get an array of videos
71
71
 
@@ -1,5 +1,7 @@
1
- require 'funky/connections/base'
2
1
  require 'json'
2
+ require 'time'
3
+
4
+ require 'funky/connections/base'
3
5
 
4
6
  module Funky
5
7
  # @api private
@@ -9,23 +9,34 @@ module Funky
9
9
  Net::HTTP::Get.new(uri.request_uri)
10
10
  end
11
11
 
12
- def self.response_for(http_request, uri)
12
+ def self.response_for(http_request, uri, max_retries = 3)
13
13
  response = Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
14
14
  http.request http_request
15
15
  end
16
- response
16
+ if response.is_a? Net::HTTPSuccess
17
+ response
18
+ elsif response.is_a? Net::HTTPServerError
19
+ sleep_and_retry_response_for(http_request, uri, max_retries, response.body)
20
+ else
21
+ raise ContentNotFound, "Error #{response.code}: #{response.body}"
22
+ end
17
23
  rescue SocketError => e
18
- raise ConnectionError, e.message
24
+ sleep_and_retry_response_for(http_request, uri, max_retries, e.message)
19
25
  end
20
26
 
21
- def self.json_for(uri)
22
- response = response_for(get_http_request(uri), uri)
23
- if response.code == '200'
24
- JSON.parse(response.body, symbolize_names: true)
27
+ def self.sleep_and_retry_response_for(http_request, uri, retries, message)
28
+ if retries > 0
29
+ sleep (4 - retries) ** 2
30
+ response_for http_request, uri, retries - 1
25
31
  else
26
- raise ContentNotFound, "Error #{response.code}: #{response.body}"
32
+ raise ConnectionError, message
27
33
  end
28
34
  end
35
+
36
+ def self.json_for(uri, max_retries = 3)
37
+ response = response_for(get_http_request(uri), uri)
38
+ JSON.parse(response.body, symbolize_names: true)
39
+ end
29
40
  end
30
41
  end
31
42
  end
data/lib/funky/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Funky
2
- VERSION = "0.2.18"
2
+ VERSION = "0.2.19"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.18
4
+ version: 0.2.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler