Merge pull request #1725 from tchak/fix-api-entreprise-timouts

Use Typhoeus and set agressive timeouts
This commit is contained in:
gregoirenovel 2018-03-26 17:01:43 +02:00 committed by GitHub
commit d72e0e92a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View file

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

View file

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

View file

@ -30,11 +30,17 @@ class ApiEntreprise::API
def self.call(resource_name, siret_or_siren, procedure_id) def self.call(resource_name, siret_or_siren, procedure_id)
url = url(resource_name, siret_or_siren) url = url(resource_name, siret_or_siren)
params = params(siret_or_siren, procedure_id) 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 end
def self.url(resource_name, siret_or_siren) def self.url(resource_name, siret_or_siren)