demarches-normaliennes/lib/siade/rna_adapter.rb

36 lines
556 B
Ruby
Raw Normal View History

2015-12-11 10:36:16 +01:00
class SIADE::RNAAdapter
def initialize(siret)
@siret = siret
2015-12-11 10:36:16 +01:00
end
def data_source
@data_source ||= JSON.parse(SIADE::API.rna(@siret), symbolize_names: true)
2015-12-11 10:36:16 +01:00
end
def to_params
params = {}
data_source[:association].each do |k, v|
params[k] = v if attr_to_fetch.include?(k)
2015-12-11 10:36:16 +01:00
end
params[:association_id] = params[:id]
params.delete(:id)
2015-12-11 10:36:16 +01:00
params
rescue
nil
2015-12-11 10:36:16 +01:00
end
def attr_to_fetch
[:id,
:titre,
:objet,
:date_creation,
:date_declaration,
:date_publication
]
end
end