Merged in development (pull request #2)

Development work merged in.
This commit is contained in:
Mark Nellemann 2021-12-11 19:38:05 +00:00
commit 8c6d784306
8 changed files with 85 additions and 61 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 ## 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/). 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 ## Development
To build and test the code: To build and test the code:

View file

@ -15,4 +15,5 @@ pipelines:
- gradle - gradle
name: Build and Release name: Build and Release
script: script:
- bash ./gradlew clean build bintrayUpload - bash ./gradlew clean build
- shopt -s nullglob ; for file in ${BITBUCKET_CLONE_DIR}/build/libs/*.jar ; do curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${file}" ; done

View file

@ -1,21 +1,7 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
//classpath 'com.bmuschko:gradle-clover-plugin:2.2.3'
}
}
apply plugin: "idea"
apply plugin: "java-library" apply plugin: "java-library"
apply plugin: "groovy" apply plugin: "groovy"
apply plugin: 'maven'
apply plugin: 'jacoco' apply plugin: 'jacoco'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
//apply from: "${project.projectDir}/gradle/clover.gradle"
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8
@ -27,16 +13,16 @@ repositories {
dependencies { dependencies {
implementation("org.slf4j:slf4j-api:${slf4jVersion}") implementation("org.slf4j:slf4j-api:${slf4jVersion}")
api("com.google.code.gson:gson:2.8.5") api('com.google.code.gson:gson:2.8.9')
api("com.squareup.okhttp3:okhttp:4.1.0") api('com.squareup.okhttp3:okhttp:4.9.3')
testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}") testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}")
testImplementation('com.squareup.okhttp3:mockwebserver:4.1.0') testImplementation('com.squareup.okhttp3:mockwebserver:4.9.3')
testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}") testImplementation("org.codehaus.groovy:groovy-all:${groovyVersion}")
testCompile("org.spockframework:spock-core:${spockVersion}") { testImplementation("org.spockframework:spock-core:${spockVersion}") {
exclude group: "org.codehaus.groovy" exclude group: "org.codehaus.groovy"
} }
testCompile( 'com.athaydes:spock-reports:1.6.2' ) { testImplementation('com.athaydes:spock-reports:2.1.1-groovy-3.0') {
transitive = false // this avoids affecting your version of Groovy/Spock transitive = false // this avoids affecting your version of Groovy/Spock
} }
@ -53,31 +39,20 @@ publishing {
} }
} }
bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
override = true test {
configurations = ['archives'] useJUnitPlatform()
pkg {
repo = "libs"
name = "libcvrapi"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = licenses
publish = true
}
} }
jacoco { jacoco {
toolVersion = "0.8.4" toolVersion = "0.8.7"
} }
jacocoTestReport { jacocoTestReport {
group = "verification" group = "verification"
reports { reports {
xml.enabled false xml.required = false
csv.enabled false csv.required = false
html.destination file("${buildDir}/reports/coverage") html.destination file("${buildDir}/reports/coverage")
} }
afterEvaluate { afterEvaluate {

View file

@ -1,9 +1,9 @@
id = libcvrapi id = libcvrapi
group = biz.nellemann.libs group = biz.nellemann.libs
version = 1.0.7 version = 1.0.9
licenses = ['APACHE-2.0'] // or something else licenses = ['APACHE-2.0'] // or something else
groovyVersion = 2.5.8 groovyVersion = 3.0.9
slf4jVersion = 1.7.28 slf4jVersion = 1.7.32
spockVersion = 1.3-groovy-2.5 spockVersion = 2.0-groovy-3.0
siteUrl = https://bitbucket.org/mnellemann/libcvrapi siteUrl = https://bitbucket.org/mnellemann/libcvrapi
gitUrl = https://bitbucket.org/mnellemann/libcvrapi.git gitUrl = https://bitbucket.org/mnellemann/libcvrapi.git

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

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

View file

@ -0,0 +1,6 @@
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.showShortLogName=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS
org.slf4j.simpleLogger.levelInBrackets=true
#org.slf4j.simpleLogger.defaultLogLevel=debug