diff --git a/README.md b/README.md index 9f6293e..c511fea 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ----------------------------------- -A Java library to query (a Danish VAT API service). Work in progress. +A Java library to query (a Danish VAT API service). ## Usage @@ -12,16 +12,6 @@ A Java library to query (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: diff --git a/build.gradle b/build.gradle index 3fdf960..866de91 100644 --- a/build.gradle +++ b/build.gradle @@ -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" } diff --git a/gradle.properties b/gradle.properties index 0463ed9..3ffab2f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/biz/nellemann/libcvrapi/CvrApi.java b/src/main/java/biz/nellemann/libcvrapi/CvrApi.java index c6001b9..16ce51e 100644 --- a/src/main/java/biz/nellemann/libcvrapi/CvrApi.java +++ b/src/main/java/biz/nellemann/libcvrapi/CvrApi.java @@ -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) { diff --git a/src/test/resources/39895692-free.json b/src/test/resources/39895692-free.json new file mode 100644 index 0000000..d770e31 --- /dev/null +++ b/src/test/resources/39895692-free.json @@ -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 +}