Mutualize Adapter initialization in a class and method
This commit is contained in:
parent
53c8396b41
commit
a9360a8be2
5 changed files with 14 additions and 28 deletions
6
app/lib/api_entreprise/adapter.rb
Normal file
6
app/lib/api_entreprise/adapter.rb
Normal 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
|
|
@ -1,9 +1,4 @@
|
||||||
class ApiEntreprise::EntrepriseAdapter
|
class ApiEntreprise::EntrepriseAdapter < ApiEntreprise::Adapter
|
||||||
def initialize(siren, procedure_id)
|
|
||||||
@siren = siren
|
|
||||||
@procedure_id = procedure_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_params
|
def to_params
|
||||||
if data_source.present?
|
if data_source.present?
|
||||||
params = data_source[:entreprise].slice(*attr_to_fetch)
|
params = data_source[:entreprise].slice(*attr_to_fetch)
|
||||||
|
@ -17,7 +12,7 @@ class ApiEntreprise::EntrepriseAdapter
|
||||||
private
|
private
|
||||||
|
|
||||||
def data_source
|
def data_source
|
||||||
@data_source ||= ApiEntreprise::API.entreprise(@siren, @procedure_id)
|
@data_source ||= ApiEntreprise::API.entreprise(@siret_or_siren, @procedure_id)
|
||||||
rescue
|
rescue
|
||||||
@data_source = nil
|
@data_source = nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
class ApiEntreprise::EtablissementAdapter
|
class ApiEntreprise::EtablissementAdapter < ApiEntreprise::Adapter
|
||||||
def initialize(siret, procedure_id)
|
|
||||||
@siret = siret
|
|
||||||
@procedure_id = procedure_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_params
|
def to_params
|
||||||
if data_source.present?
|
if data_source.present?
|
||||||
params = data_source[:etablissement].slice(*attr_to_fetch)
|
params = data_source[:etablissement].slice(*attr_to_fetch)
|
||||||
|
@ -19,7 +14,7 @@ class ApiEntreprise::EtablissementAdapter
|
||||||
private
|
private
|
||||||
|
|
||||||
def data_source
|
def data_source
|
||||||
@data_source ||= ApiEntreprise::API.etablissement(@siret, @procedure_id)
|
@data_source ||= ApiEntreprise::API.etablissement(@siret_or_siren, @procedure_id)
|
||||||
rescue
|
rescue
|
||||||
@data_source = nil
|
@data_source = nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
class ApiEntreprise::ExercicesAdapter
|
class ApiEntreprise::ExercicesAdapter < ApiEntreprise::Adapter
|
||||||
def initialize(siret, procedure_id)
|
|
||||||
@siret = siret
|
|
||||||
@procedure_id = procedure_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_array
|
def to_array
|
||||||
if data_source.present?
|
if data_source.present?
|
||||||
data_source[:exercices].map do |exercice|
|
data_source[:exercices].map do |exercice|
|
||||||
|
@ -17,7 +12,7 @@ class ApiEntreprise::ExercicesAdapter
|
||||||
private
|
private
|
||||||
|
|
||||||
def data_source
|
def data_source
|
||||||
@data_source ||= ApiEntreprise::API.exercices(@siret, @procedure_id)
|
@data_source ||= ApiEntreprise::API.exercices(@siret_or_siren, @procedure_id)
|
||||||
rescue
|
rescue
|
||||||
@data_source = nil
|
@data_source = nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
class ApiEntreprise::RNAAdapter
|
class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
|
||||||
def initialize(siret, procedure_id)
|
|
||||||
@siret = siret
|
|
||||||
@procedure_id = procedure_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_params
|
def to_params
|
||||||
if data_source.present? && data_source[:association][:id].present?
|
if data_source.present? && data_source[:association][:id].present?
|
||||||
params = data_source[:association].slice(*attr_to_fetch)
|
params = data_source[:association].slice(*attr_to_fetch)
|
||||||
|
@ -17,7 +12,7 @@ class ApiEntreprise::RNAAdapter
|
||||||
private
|
private
|
||||||
|
|
||||||
def data_source
|
def data_source
|
||||||
@data_source ||= ApiEntreprise::API.rna(@siret, @procedure_id)
|
@data_source ||= ApiEntreprise::API.rna(@siret_or_siren, @procedure_id)
|
||||||
rescue
|
rescue
|
||||||
@data_source = nil
|
@data_source = nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue