Add lib RNA connect to apientreprise
This commit is contained in:
parent
d49e9fe75a
commit
704e491cd0
8 changed files with 136 additions and 1 deletions
|
@ -21,6 +21,11 @@ class SIADE::API
|
|||
call(base_url + endpoint)
|
||||
end
|
||||
|
||||
def self.rna(siret)
|
||||
endpoint = "/api/v1/associations/#{siret}"
|
||||
call(base_url + endpoint)
|
||||
end
|
||||
|
||||
def self.call(url, params = {})
|
||||
params.merge!(token: SIADETOKEN)
|
||||
|
||||
|
|
28
lib/siade/rna_adapter.rb
Normal file
28
lib/siade/rna_adapter.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
class SIADE::RNAAdapter
|
||||
def initialize(siren)
|
||||
@siret = siren
|
||||
end
|
||||
|
||||
def data_source
|
||||
@data_source ||= JSON.parse(SIADE::API.rna(@siren), symbolize_names: true)
|
||||
end
|
||||
|
||||
def to_params
|
||||
params = {}
|
||||
|
||||
data_source[:association].each do |k, v|
|
||||
params[k] = v if attr_to_fetch.include?(k)
|
||||
end
|
||||
params
|
||||
end
|
||||
|
||||
def attr_to_fetch
|
||||
[:id,
|
||||
:titre,
|
||||
:objet,
|
||||
:date_creation,
|
||||
:date_declaration,
|
||||
:date_publication
|
||||
]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue