commit
8c6d784306
12
README.md
12
README.md
|
@ -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:
|
||||
|
|
|
@ -15,4 +15,5 @@ pipelines:
|
|||
- gradle
|
||||
name: Build and Release
|
||||
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
|
||||
|
|
47
build.gradle
47
build.gradle
|
@ -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: "groovy"
|
||||
apply plugin: 'maven'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
//apply from: "${project.projectDir}/gradle/clover.gradle"
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
@ -27,16 +13,16 @@ repositories {
|
|||
dependencies {
|
||||
|
||||
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
|
||||
api("com.google.code.gson:gson:2.8.5")
|
||||
api("com.squareup.okhttp3:okhttp:4.1.0")
|
||||
api('com.google.code.gson:gson:2.8.9')
|
||||
api('com.squareup.okhttp3:okhttp:4.9.3')
|
||||
|
||||
testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}")
|
||||
testImplementation('com.squareup.okhttp3:mockwebserver:4.1.0')
|
||||
testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}")
|
||||
testCompile("org.spockframework:spock-core:${spockVersion}") {
|
||||
testImplementation('com.squareup.okhttp3:mockwebserver:4.9.3')
|
||||
testImplementation("org.codehaus.groovy:groovy-all:${groovyVersion}")
|
||||
testImplementation("org.spockframework:spock-core:${spockVersion}") {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -53,31 +39,20 @@ publishing {
|
|||
}
|
||||
}
|
||||
|
||||
bintray {
|
||||
user = System.getenv('BINTRAY_USER')
|
||||
key = System.getenv('BINTRAY_KEY')
|
||||
|
||||
override = true
|
||||
configurations = ['archives']
|
||||
pkg {
|
||||
repo = "libs"
|
||||
name = "libcvrapi"
|
||||
websiteUrl = siteUrl
|
||||
vcsUrl = gitUrl
|
||||
licenses = licenses
|
||||
publish = true
|
||||
}
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
jacoco {
|
||||
toolVersion = "0.8.4"
|
||||
toolVersion = "0.8.7"
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
group = "verification"
|
||||
reports {
|
||||
xml.enabled false
|
||||
csv.enabled false
|
||||
xml.required = false
|
||||
csv.required = false
|
||||
html.destination file("${buildDir}/reports/coverage")
|
||||
}
|
||||
afterEvaluate {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
id = libcvrapi
|
||||
group = biz.nellemann.libs
|
||||
version = 1.0.7
|
||||
version = 1.0.9
|
||||
licenses = ['APACHE-2.0'] // or something else
|
||||
groovyVersion = 2.5.8
|
||||
slf4jVersion = 1.7.28
|
||||
spockVersion = 1.3-groovy-2.5
|
||||
groovyVersion = 3.0.9
|
||||
slf4jVersion = 1.7.32
|
||||
spockVersion = 2.0-groovy-3.0
|
||||
siteUrl = https://bitbucket.org/mnellemann/libcvrapi
|
||||
gitUrl = https://bitbucket.org/mnellemann/libcvrapi.git
|
||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
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
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
52
src/test/resources/39895692-free.json
Normal file
52
src/test/resources/39895692-free.json
Normal 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
|
||||
}
|
6
src/test/resources/simplelogger.properties
Normal file
6
src/test/resources/simplelogger.properties
Normal 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
|
Loading…
Reference in a new issue