Work on free API

This commit is contained in:
Mark Nellemann 2021-11-03 15:48:13 +01:00
parent 0c5f0a1120
commit f24f9c5e40
5 changed files with 68 additions and 21 deletions

View File

@ -2,7 +2,7 @@
-----------------------------------
A Java library to query <https://www.cvrapi.dk> (a Danish VAT API service). Work in progress.
A Java library to query <https://www.cvrapi.dk> (a Danish VAT API service).
## Usage
@ -12,16 +12,6 @@ A Java library to query <https://www.cvrapi.dk> (a Danish VAT API service). Work
The *Company* represents most of the same properties as seen in the example JSON in the [api documentation](http://docs.rest.cvrapi.dk/).
### Gradle
repositories {
maven { url 'https://dl.bintray.com/mnellemann/libs' }
}
dependencies {
compile 'biz.nellemann.libs:libcvrapi:1.+'
}
## Development
To build and test the code:

View File

@ -14,7 +14,7 @@ repositories {
dependencies {
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
api('com.google.code.gson:gson:2.8.7')
api('com.google.code.gson:gson:2.8.8')
api('com.squareup.okhttp3:okhttp:4.9.1')
testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}")
@ -40,6 +40,11 @@ publishing {
}
}
test {
useJUnitPlatform()
}
jacoco {
toolVersion = "0.8.4"
}

View File

@ -1,6 +1,6 @@
id = libcvrapi
group = biz.nellemann.libs
version = 1.0.7
version = 1.0.8
licenses = ['APACHE-2.0'] // or something else
groovyVersion = 3.0.8
slf4jVersion = 1.7.32

View File

@ -30,6 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Objects;
public class CvrApi {
@ -72,7 +73,7 @@ public class CvrApi {
Response response = client.newCall(request).execute();
switch (response.code()) {
case 200:
return response.body().string();
return Objects.requireNonNull(response.body()).string();
case 401:
log.warn("get() - 401 - Access Denied");
throw new Exception("Access Denied");
@ -88,9 +89,8 @@ public class CvrApi {
/**
* Query the API: https://rest.cvrapi.dk/v1/dk/company/vatNumber
*
* @param vatNumber
* @return
* @throws IOException
* @param vatNumber Danish VAT number
* @return String with JSON
*/
protected String getCompanyJson(String vatNumber) throws Exception {
String response = get(BASE_URL + "/company/" + vatNumber);
@ -102,8 +102,8 @@ public class CvrApi {
/**
* Use GSON to deserialize JSON into POJO's.
*
* @param json
* @return
* @param json String of JSON
* @return Company object
*/
protected Company parseJsonIntoCompany(String json) {
Gson gson = new Gson();
@ -114,8 +114,8 @@ public class CvrApi {
/**
* Lookup company by VAT number
*
* @param vatNumber
* @return
* @param vatNumber Danish VAT number as String
* @return Company object
*/
public Company getCompanyByVatNumber(String vatNumber) {

View File

@ -0,0 +1,52 @@
// https://cvrapi.dk/api?search=39895692&country=dk&format=json
{
"vat": 39895692,
"name": "Cabcon AS",
"address": "Stamholmen 193A, 1. tv.",
"zipcode": "2650",
"city": "Hvidovre",
"cityname": null,
"protected": true,
"phone": "38760324",
"email": "jag@cabcon.dk",
"fax": null,
"startdate": "01\/10 - 2018",
"enddate": null,
"employees": null,
"addressco": "Cabcon A\/S",
"industrycode": 465210,
"industrydesc": "Engroshandel med elektronisk udstyr",
"companycode": 210,
"companydesc": "Anden udenlandsk virksomhed",
"creditstartdate": null,
"creditbankrupt": false,
"creditstatus": null,
"owners": [
{
"name": "Cabcon AS"
}
],
"productionunits": [
{
"pno": 1024011204,
"main": true,
"name": "Cabcon AS",
"address": "Stamholmen 193A, 1. tv.",
"zipcode": "2650",
"city": "Hvidovre",
"cityname": null,
"protected": true,
"phone": "38760324",
"email": "jag@cabcon.dk",
"fax": null,
"startdate": "01\/10 - 2018",
"enddate": null,
"employees": null,
"addressco": "Cabcon A\/S",
"industrycode": 465210,
"industrydesc": "Engroshandel med elektronisk udstyr"
}
],
"t": 100,
"version": 6
}