Class: Funky::Connection::Base Private
- Inherits:
-
Object
- Object
- Funky::Connection::Base
- Defined in:
- lib/funky/connections/base.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Class Method Summary collapse
- .get_http_request(uri) ⇒ Object private
- .json_for(uri, max_retries = 3) ⇒ Object private
- .response_for(http_request, uri, max_retries = 3) ⇒ Object private
- .sleep_and_retry_response_for(http_request, uri, retries, message) ⇒ Object private
Class Method Details
.get_http_request(uri) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/funky/connections/base.rb', line 8 def self.get_http_request(uri) Net::HTTP::Get.new(uri.request_uri) end |
.json_for(uri, max_retries = 3) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 39 |
# File 'lib/funky/connections/base.rb', line 36 def self.json_for(uri, max_retries = 3) response = response_for(get_http_request(uri), uri) JSON.parse(response.body, symbolize_names: true) end |
.response_for(http_request, uri, max_retries = 3) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/funky/connections/base.rb', line 12 def self.response_for(http_request, uri, max_retries = 3) response = Net::HTTP.start(uri.host, 443, use_ssl: true) do |http| http.request http_request end if response.is_a? Net::HTTPSuccess response elsif response.is_a? Net::HTTPServerError sleep_and_retry_response_for(http_request, uri, max_retries, response.body) else raise ContentNotFound, "Error #{response.code}: #{response.body}" end rescue SocketError => e sleep_and_retry_response_for(http_request, uri, max_retries, e.) end |
.sleep_and_retry_response_for(http_request, uri, retries, message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 33 34 |
# File 'lib/funky/connections/base.rb', line 27 def self.sleep_and_retry_response_for(http_request, uri, retries, ) if retries > 0 sleep (4 - retries) ** 2 response_for http_request, uri, retries - 1 else raise ConnectionError, end end |