Update README and getResponse().
This commit is contained in:
parent
7e349f3d35
commit
cb9a603b0e
|
@ -6,8 +6,8 @@ A Java library to query Paqle. Work in progress.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
TODO.
|
Paqle paqle = new Paqle("MyCompany", "myUsername", "myPassword");
|
||||||
|
PaqleResponse response = paqle.getResponse(["57020415"]);
|
||||||
|
|
||||||
### Gradle
|
### Gradle
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ A Java library to query Paqle. Work in progress.
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'biz.nellemann.libs:libpaqle:1.+'
|
compile 'biz.nellemann.libs:libpaqle:1.+'
|
||||||
runtime "org.slf4j:slf4j-simple:1.7.28"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
|
@ -78,12 +78,7 @@ public class Paqle {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
protected String getJson(List<String> vatNumbers) throws Exception {
|
||||||
* @param vatNumbers
|
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
protected String getJson(List<String> vatNumbers) throws IOException, Exception {
|
|
||||||
String cvrIds = String.join(",", vatNumbers);
|
String cvrIds = String.join(",", vatNumbers);
|
||||||
String jsonText = get(baseUrl + "/entities?customer=" + company + "&news&cvrIds=" + cvrIds);
|
String jsonText = get(baseUrl + "/entities?customer=" + company + "&news&cvrIds=" + cvrIds);
|
||||||
log.debug("getEntities() response: " + jsonText);
|
log.debug("getEntities() response: " + jsonText);
|
||||||
|
@ -91,16 +86,23 @@ public class Paqle {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
protected PaqleResponse deserializeJson(String json) throws JsonSyntaxException {
|
||||||
* Use GSON to deserialize JSON into POJO's.
|
Gson gson = new Gson();
|
||||||
*
|
PaqleResponse response = gson.fromJson(json, PaqleResponse.class);
|
||||||
* @param json
|
return response;
|
||||||
* @return
|
}
|
||||||
*/
|
|
||||||
protected PaqleResponse getResponse(String json) throws JsonSyntaxException {
|
|
||||||
Gson gson = new Gson();
|
protected PaqleResponse getResponse(List<String> vatNumbers) {
|
||||||
PaqleResponse response = gson.fromJson(json, PaqleResponse.class);
|
PaqleResponse response;
|
||||||
return response;
|
try {
|
||||||
|
String json = getJson(vatNumbers);
|
||||||
|
response = deserializeJson(json);
|
||||||
|
} catch ( Exception e) {
|
||||||
|
log.error("Error", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,33 +20,23 @@ class PaqleSpec extends Specification {
|
||||||
mockServer.shutdown()
|
mockServer.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
void "test succesfull parsing of test JSON"() {
|
void "test successful parsing of test JSON"() {
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
def testFile = new File(getClass().getResource('/test.json').toURI())
|
def testFile = new File(getClass().getResource('/test.json').toURI())
|
||||||
def testJson = testFile.getText('UTF-8')
|
def testJson = testFile.getText('UTF-8')
|
||||||
|
mockServer.enqueue(new MockResponse().setBody(testJson));
|
||||||
|
HttpUrl baseUrl = mockServer.url("/");
|
||||||
|
paqle.baseUrl = baseUrl.toString()
|
||||||
|
|
||||||
when:
|
when:
|
||||||
PaqleResponse response = paqle.getResponse(testJson)
|
PaqleResponse response = paqle.getResponse(["2955224", "4004110055"])
|
||||||
|
|
||||||
then:
|
then:
|
||||||
response.Entities.size() == 2
|
response.Entities.size() == 2
|
||||||
response.News.size() == 100
|
response.News.size() == 100
|
||||||
}
|
}
|
||||||
|
|
||||||
void "test succesful HTTP GET 15027800"() {
|
// TODO: Test error-cases, 401, 404, timeouts, empty responses, etc.
|
||||||
|
|
||||||
setup:
|
|
||||||
mockServer.enqueue(new MockResponse().setBody("{}"));
|
|
||||||
HttpUrl baseUrl = mockServer.url("/");
|
|
||||||
paqle.baseUrl = baseUrl.toString()
|
|
||||||
|
|
||||||
when:
|
|
||||||
def jsonString = paqle.getJson(["15027800"])
|
|
||||||
|
|
||||||
then:
|
|
||||||
jsonString != null
|
|
||||||
jsonString == "{}"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue