Mutualize Adapter initialization in a class and method

This commit is contained in:
gregoirenovel 2018-03-28 15:24:43 +02:00
parent 53c8396b41
commit a9360a8be2
5 changed files with 14 additions and 28 deletions

View file

@ -0,0 +1,6 @@
class ApiEntreprise::Adapter
def initialize(siret_or_siren, procedure_id)
@siret_or_siren = siret_or_siren
@procedure_id = procedure_id
end
end

View file

@ -1,9 +1,4 @@
class ApiEntreprise::EntrepriseAdapter
def initialize(siren, procedure_id)
@siren = siren
@procedure_id = procedure_id
end
class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter
def to_params
if data_source.present?
params = data_source[:entreprise].slice(*attr_to_fetch)
@ -17,7 +12,7 @@ class ApiEntreprise::EntrepriseAdapter
private
def data_source
@data_source ||= ApiEntreprise::API.entreprise(@siren, @procedure_id)
@data_source ||= ApiEntreprise::API.entreprise(@siret_or_siren, @procedure_id)
rescue
@data_source = nil
end

View file

@ -1,9 +1,4 @@
class ApiEntreprise::EtablissementAdapter
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter
def to_params
if data_source.present?
params = data_source[:etablissement].slice(*attr_to_fetch)
@ -19,7 +14,7 @@ class ApiEntreprise::EtablissementAdapter
private
def data_source
@data_source ||= ApiEntreprise::API.etablissement(@siret, @procedure_id)
@data_source ||= ApiEntreprise::API.etablissement(@siret_or_siren, @procedure_id)
rescue
@data_source = nil
end

View file

@ -1,9 +1,4 @@
class ApiEntreprise::ExercicesAdapter
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter
def to_array
if data_source.present?
data_source[:exercices].map do |exercice|
@ -17,7 +12,7 @@ class ApiEntreprise::ExercicesAdapter
private
def data_source
@data_source ||= ApiEntreprise::API.exercices(@siret, @procedure_id)
@data_source ||= ApiEntreprise::API.exercices(@siret_or_siren, @procedure_id)
rescue
@data_source = nil
end

View file

@ -1,9 +1,4 @@
class ApiEntreprise::RNAAdapter
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
def to_params
if data_source.present? && data_source[:association][:id].present?
params = data_source[:association].slice(*attr_to_fetch)
@ -17,7 +12,7 @@ class ApiEntreprise::RNAAdapter
private
def data_source
@data_source ||= ApiEntreprise::API.rna(@siret, @procedure_id)
@data_source ||= ApiEntreprise::API.rna(@siret_or_siren, @procedure_id)
rescue
@data_source = nil
end