demarches-normaliennes/app/lib/siade/api.rb

54 lines
1.3 KiB
Ruby
Raw Normal View History

class SIADE::API
2015-08-10 11:05:06 +02:00
class << self
attr_accessor :token
end
ENTREPRISE_RESOURCE_NAME = "entreprises"
ETABLISSEMENT_RESOURCE_NAME = "etablissements"
EXERCICES_RESOURCE_NAME = "exercices"
RNA_RESOURCE_NAME = "associations"
2015-08-10 11:05:06 +02:00
def initialize
end
def self.entreprise(siren, procedure_id)
call(ENTREPRISE_RESOURCE_NAME, siren, procedure_id)
2015-08-10 11:05:06 +02:00
end
def self.etablissement(siret, procedure_id)
call(ETABLISSEMENT_RESOURCE_NAME, siret, procedure_id)
2015-08-10 11:05:06 +02:00
end
def self.exercices(siret, procedure_id)
call(EXERCICES_RESOURCE_NAME, siret, procedure_id)
end
def self.rna(siret, procedure_id)
call(RNA_RESOURCE_NAME, siret, procedure_id)
2015-12-11 10:36:16 +01:00
end
def self.call(resource_name, siret_or_siren, procedure_id)
2018-03-15 13:55:54 +01:00
params = mandatory_params(siret_or_siren, procedure_id)
2017-11-20 18:55:59 +01:00
params[:token] = SIADETOKEN
2015-08-10 11:05:06 +02:00
verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE
RestClient::Resource.new(
url(resource_name, siret_or_siren),
2015-08-10 11:05:06 +02:00
verify_ssl: verify_ssl_mode
).get(params: params)
2015-08-10 11:05:06 +02:00
end
def self.url(resource_name, siret_or_siren)
2018-03-15 14:11:53 +01:00
[SIADEURL, "v2", resource_name, siret_or_siren].join("/")
end
def self.mandatory_params(siret_or_siren, procedure_id)
{
context: "demarches-simplifiees.fr",
recipient: siret_or_siren,
object: "procedure_id: #{procedure_id}"
}
end
2015-08-10 11:05:06 +02:00
end