API-INSEE-Sirene
view release on metacpan or search on metacpan
Revision history for Perl extension API::INSEE::Sirene.
4.04
- Handle xml response when the API is down
- Fixed typing errors
4.03
- Removed unused import
- Updated README
- Updated documentation
4.02
- The getCustomCriteria method doesn't take $use_historized_field parameter anymore
The module will now auto-detect historized fields
- Added setCurrentEndpoint method
- Updated documentation
3.507
- Updated documentation
3.506
- Fixed badly named variables
3.505
- Updated documentation
- Fixed errors in documentation from the previous version
- Fixed regression about automatic token renewal
- Fixed some return values, now all the functions return the error first and the result second
3.504
- Added automatic token renewal
- Updated documentation
3.503
- Decreased $HARD_MAX_RESULTS value from 10000 to 1000 according to the new specifications applicable from 2019-10-01
- Updated documentation
3.502
- Documentation standardization
- Minor code improvements
- Errors handling improvement. The module will now display better errors
- Added checkResponse() function
- Moved getEstablishmentsByCriteria() to @EXPORT_OK
- Moved getLegalUnitBySIREN() to @EXPORT
3.501 Mon Jul 8 12:40:26 2019
- original version; created by h2xs 1.23 with options
-AX -n API::INSEE::Sirene -v 3.501
lib/API/INSEE/Sirene.pm view on Meta::CPAN
return 1, $self->_dumpRequest($request, $response); # the API may return xml intead of json...
}
switch ($response->code) {
case HTTP_OK {
$self->{'token_expiration'} = time + $json_obj->{'expires_in'};
$self->{'user_agent'}->default_header( Authorization => "Bearer $json_obj->{'access_token'}" );
return 0;
}
case HTTP_UNAUTHORIZED { # wrong credentials
return 1 , $json_obj->{'error_description'};
}
else { # oh dear we are in trouble
return 1, $self->_dumpRequest($request, $response);
}
}
}
sub _sendRequest {
my ($self, $parameters) = @_;
lib/API/INSEE/Sirene.pm view on Meta::CPAN
return 0, $response->content;
}
case HTTP_MOVED_PERMANENTLY { # duplicated legal unit/ establishment
return 1, sprintf "%s\n%s", $response->message, $response->header('Location');
}
case [
HTTP_REQUEST_URI_TOO_LARGE, HTTP_TOO_MANY_REQUESTS,
HTTP_UNAUTHORIZED, HTTP_FORBIDDEN,
HTTP_SERVICE_UNAVAILABLE
] {
# There is no syntax error in request, the http message should be sufficient to understand the problem
return 1, $response->message;
}
else { # case HTTP_BAD_REQUEST || HTTP_INTERNAL_SERVER_ERROR
return 1, $self->_dumpRequest($request, $response);
}
}
}
sub _buildParameters {
my ($self, $usefull_fields, $desired_fields, $criteria) = @_;
lib/API/INSEE/Sirene.pm view on Meta::CPAN
# or
my $response_json = $sirene->getLegalUnitBySIREN(123456789, 'all');
When you don't specify any desired field, the module returns a selection of fields that are most likely to interest you. (see C<$useful_fields_legal_unit> and C<$useful_fields_establishment> in source code to find out which ones)
If you want all fields, you have to specify it explicitly by passing the value 'all' as parameter.
=head1 RETURN VALUES
Each method returns a list of two elements: a return code, which is 0 in case of success, or something else in case of failure; and the result of the request (some json or an error message). In case of problem when calling API (malformed request for ...
The module may launch a croak if the crendentials are not initialized or if the SIREN/SIRET numbers are not given in a correct format.
=head1 ALIAS
Some fields have more user-friendly aliases:
my $useful_fields_aliases = {
nicSiege => 'nicSiegeUniteLegale',
nom => [ 'denominationUniteLegale', 'nomUniteLegale' ],
( run in 0.260 second using v1.01-cache-2.11-cpan-65fba6d93b7 )