Cleanup.
This commit is contained in:
parent
2286658446
commit
9df016a5f4
|
@ -40,12 +40,14 @@ public class CvrApi {
|
||||||
private final String userAgent;
|
private final String userAgent;
|
||||||
private final String authenticationToken;
|
private final String authenticationToken;
|
||||||
|
|
||||||
|
|
||||||
public CvrApi(String userAgent, String authenticationToken) {
|
public CvrApi(String userAgent, String authenticationToken) {
|
||||||
this.userAgent = userAgent;
|
this.userAgent = userAgent;
|
||||||
this.authenticationToken = authenticationToken;
|
this.authenticationToken = authenticationToken;
|
||||||
client = new OkHttpClient();
|
client = new OkHttpClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String get(String url) throws IOException, Exception {
|
private String get(String url) throws IOException, Exception {
|
||||||
|
|
||||||
String credential = Credentials.basic(authenticationToken, "");
|
String credential = Credentials.basic(authenticationToken, "");
|
||||||
|
@ -65,8 +67,9 @@ public class CvrApi {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://rest.cvrapi.dk/v1/dk/company/vatNumber
|
* Query the API: https://rest.cvrapi.dk/v1/dk/company/vatNumber
|
||||||
*
|
*
|
||||||
* @param vatNumber
|
* @param vatNumber
|
||||||
* @return
|
* @return
|
||||||
|
@ -77,8 +80,9 @@ public class CvrApi {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use GSON to deserialize JSON into objects.
|
* Use GSON to deserialize JSON into POJO's.
|
||||||
*
|
*
|
||||||
* @param json
|
* @param json
|
||||||
* @return
|
* @return
|
||||||
|
@ -89,16 +93,26 @@ public class CvrApi {
|
||||||
return company;
|
return company;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup company by VAT number
|
||||||
|
*
|
||||||
|
* @param vatNumber
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Company getCompanyByVatNumber(String vatNumber) {
|
public Company getCompanyByVatNumber(String vatNumber) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String json = getCompanyJson(vatNumber);
|
String json = getCompanyJson(vatNumber);
|
||||||
return parseJsonIntoCompany(json);
|
return parseJsonIntoCompany(json);
|
||||||
|
} catch (JsonSyntaxException e) {
|
||||||
|
log.error("Error parsing JSON", e);
|
||||||
|
return null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("IO Error", e);
|
log.error("IO Error", e);
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Other Error", e);
|
log.error("Unknown Error", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue