create ApiEntreprise::EffectifsAdapter
This commit is contained in:
parent
589217b9ed
commit
599d8e33e8
4 changed files with 64 additions and 0 deletions
|
@ -3,6 +3,7 @@ class ApiEntreprise::API
|
||||||
ETABLISSEMENT_RESOURCE_NAME = "etablissements"
|
ETABLISSEMENT_RESOURCE_NAME = "etablissements"
|
||||||
EXERCICES_RESOURCE_NAME = "exercices"
|
EXERCICES_RESOURCE_NAME = "exercices"
|
||||||
RNA_RESOURCE_NAME = "associations"
|
RNA_RESOURCE_NAME = "associations"
|
||||||
|
EFFECTIFS_RESOURCE_NAME = "effectifs_mensuels_acoss_covid"
|
||||||
|
|
||||||
TIMEOUT = 15
|
TIMEOUT = 15
|
||||||
|
|
||||||
|
@ -28,6 +29,11 @@ class ApiEntreprise::API
|
||||||
call(RNA_RESOURCE_NAME, siret, procedure_id)
|
call(RNA_RESOURCE_NAME, siret, procedure_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.effectifs(siren, procedure_id, annee, mois)
|
||||||
|
endpoint = [EFFECTIFS_RESOURCE_NAME, annee, mois, "entreprise"].join('/')
|
||||||
|
call(endpoint, siren, procedure_id)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.call(resource_name, siret_or_siren, procedure_id)
|
def self.call(resource_name, siret_or_siren, procedure_id)
|
||||||
|
|
26
app/lib/api_entreprise/effectifs_adapter.rb
Normal file
26
app/lib/api_entreprise/effectifs_adapter.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
class ApiEntreprise::EffectifsAdapter < ApiEntreprise::Adapter
|
||||||
|
def initialize(siren, procedure_id, annee, mois)
|
||||||
|
@siren = siren
|
||||||
|
@procedure_id = procedure_id
|
||||||
|
@annee = annee
|
||||||
|
@mois = mois
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_resource
|
||||||
|
ApiEntreprise::API.effectifs(@siren, @procedure_id, @annee, @mois)
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_params
|
||||||
|
if data_source[:effectifs_mensuels].present?
|
||||||
|
{
|
||||||
|
effectif_mensuel: data_source[:effectifs_mensuels],
|
||||||
|
effectif_mois: @mois,
|
||||||
|
effectif_annee: @annee
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
6
spec/fixtures/files/api_entreprise/effectifs.json
vendored
Normal file
6
spec/fixtures/files/api_entreprise/effectifs.json
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"siren": "418166096",
|
||||||
|
"annee": "2020",
|
||||||
|
"mois": "02",
|
||||||
|
"effectifs_mensuels": 100.5
|
||||||
|
}
|
26
spec/lib/api_entreprise/effectifs_adapter_spec.rb
Normal file
26
spec/lib/api_entreprise/effectifs_adapter_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
describe ApiEntreprise::EffectifsAdapter do
|
||||||
|
let(:siren) { '418166096' }
|
||||||
|
let(:procedure_id) { 22 }
|
||||||
|
let(:annee) { "2020" }
|
||||||
|
let(:mois) { "02" }
|
||||||
|
let(:adapter) { described_class.new(siren, procedure_id, annee, mois) }
|
||||||
|
subject { adapter.to_params }
|
||||||
|
|
||||||
|
before do
|
||||||
|
stub_request(:get, /https:\/\/entreprise.api.gouv.fr\/v2\/effectifs_mensuels_acoss_covid\/#{annee}\/#{mois}\/entreprise\/#{siren}?.*token=/)
|
||||||
|
.to_return(body: body, status: status)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the SIREN is valid" do
|
||||||
|
let(:body) { File.read('spec/fixtures/files/api_entreprise/effectifs.json') }
|
||||||
|
let(:status) { 200 }
|
||||||
|
|
||||||
|
it '#to_params class est une Hash ?' do
|
||||||
|
expect(subject).to be_an_instance_of(Hash)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renvoie les effectifs du mois demandé" do
|
||||||
|
expect(subject[:effectif_mensuel]).to eq(100.5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue