diff --git a/Gemfile b/Gemfile index b96c3669b..4b90958f8 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,7 @@ gem 'openid_connect' gem 'omniauth-github' gem 'rest-client' +gem 'typhoeus' gem 'clamav-client', require: 'clamav/client' diff --git a/Gemfile.lock b/Gemfile.lock index 497a70518..54fc7664c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/lib/api_entreprise/api.rb b/app/lib/api_entreprise/api.rb index ad1086371..df076ac98 100644 --- a/app/lib/api_entreprise/api.rb +++ b/app/lib/api_entreprise/api.rb @@ -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)