Use Typhoeus and set agressive timeouts

This commit is contained in:
Paul Chavard 2018-03-26 16:38:03 +02:00
parent 197089a746
commit f35aef0eb6
3 changed files with 15 additions and 3 deletions

View file

@ -46,6 +46,7 @@ gem 'openid_connect'
gem 'omniauth-github'
gem 'rest-client'
gem 'typhoeus'
gem 'clamav-client', require: 'clamav/client'

View file

@ -196,6 +196,8 @@ GEM
http_parser.rb (~> 0.6.0)
erubi (1.7.0)
erubis (2.7.0)
ethon (0.11.0)
ffi (>= 1.3.0)
eventmachine (1.2.5)
excon (0.60.0)
execjs (2.7.0)
@ -730,6 +732,8 @@ GEM
turbolinks (5.1.0)
turbolinks-source (~> 5.1)
turbolinks-source (5.1.0)
typhoeus (1.3.0)
ethon (>= 0.9.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.7)
@ -854,6 +858,7 @@ DEPENDENCIES
therubyracer
timecop
turbolinks
typhoeus
uglifier (>= 1.3.0)
unicode_utils
unicorn

View file

@ -30,11 +30,17 @@ class ApiEntreprise::API
def self.call(resource_name, siret_or_siren, procedure_id)
url = url(resource_name, siret_or_siren)
params = params(siret_or_siren, procedure_id)
verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE
result = RestClient::Resource.new(url, verify_ssl: verify_ssl_mode).get(params: params)
response = Typhoeus.get(url,
ssl_verifypeer: false,
params: params,
timeout: 20)
JSON.parse(result, symbolize_names: true)
if response.success?
JSON.parse(response.body, symbolize_names: true)
else
raise RestClient::ResourceNotFound
end
end
def self.url(resource_name, siret_or_siren)