2018-03-15 16:56:21 +01:00
|
|
|
class ApiEntreprise::ExercicesAdapter
|
2018-03-15 12:02:45 +01:00
|
|
|
def initialize(siret, procedure_id)
|
2015-11-16 11:23:29 +01:00
|
|
|
@siret = siret
|
2018-03-15 12:02:45 +01:00
|
|
|
@procedure_id = procedure_id
|
2015-11-16 11:23:29 +01:00
|
|
|
end
|
|
|
|
|
2018-03-28 10:52:54 +02:00
|
|
|
def to_array
|
2018-03-15 14:41:04 +01:00
|
|
|
if data_source.present?
|
|
|
|
data_source[:exercices].map do |exercice|
|
|
|
|
exercice.slice(*attr_to_fetch)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
[]
|
2017-12-01 10:56:29 +01:00
|
|
|
end
|
2018-02-21 16:29:22 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-03-15 14:30:10 +01:00
|
|
|
def data_source
|
2018-03-15 16:56:21 +01:00
|
|
|
@data_source ||= ApiEntreprise::API.exercices(@siret, @procedure_id)
|
2018-03-15 14:30:10 +01:00
|
|
|
rescue
|
|
|
|
@data_source = nil
|
|
|
|
end
|
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
def attr_to_fetch
|
|
|
|
[:ca, :date_fin_exercice, :date_fin_exercice_timestamp]
|
2015-11-16 11:23:29 +01:00
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|