Lowercased fields and use GSON's alternative name to make it work.
This commit is contained in:
parent
cb9a603b0e
commit
d64e80ecb0
|
@ -17,7 +17,6 @@ apply plugin: 'maven-publish'
|
|||
apply plugin: 'com.jfrog.bintray'
|
||||
//apply from: "${project.projectDir}/gradle/clover.gradle"
|
||||
|
||||
version = "${version}-SNAPSHOT"
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
id = libpaqle
|
||||
group = biz.nellemann.libs
|
||||
version = 1.0.0
|
||||
version = 1.0.1
|
||||
licenses = ['APACHE-2.0'] // or something else
|
||||
groovyVersion = 2.5.8
|
||||
slf4jVersion = 1.7.28
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
import biz.nellemann.libpaqle.pojo.PaqleResponse;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -78,25 +79,28 @@ public class Paqle {
|
|||
}
|
||||
|
||||
|
||||
protected String getJson(List<String> vatNumbers) throws Exception {
|
||||
String cvrIds = String.join(",", vatNumbers);
|
||||
String jsonText = get(baseUrl + "/entities?customer=" + company + "&news&cvrIds=" + cvrIds);
|
||||
log.debug("getEntities() response: " + jsonText);
|
||||
protected String getJson(String vatNumber) throws Exception {
|
||||
//String cvrIds = String.join(",", vatNumbers);
|
||||
String jsonText = get(baseUrl + "/entities?customer=" + company + "&news&vatNumbers=" + "DK"+vatNumber);
|
||||
log.debug("getJson() response: " + jsonText);
|
||||
return jsonText;
|
||||
}
|
||||
|
||||
|
||||
protected PaqleResponse deserializeJson(String json) throws JsonSyntaxException {
|
||||
Gson gson = new Gson();
|
||||
//Gson gson = new Gson();
|
||||
Gson gson = new GsonBuilder()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssz")
|
||||
.create();
|
||||
PaqleResponse response = gson.fromJson(json, PaqleResponse.class);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
protected PaqleResponse getResponse(List<String> vatNumbers) {
|
||||
protected PaqleResponse getResponseByVatNumber(String vatNumber) {
|
||||
PaqleResponse response;
|
||||
try {
|
||||
String json = getJson(vatNumbers);
|
||||
String json = getJson(vatNumber);
|
||||
response = deserializeJson(json);
|
||||
} catch ( Exception e) {
|
||||
log.error("Error", e);
|
||||
|
|
|
@ -19,15 +19,24 @@
|
|||
|
||||
package biz.nellemann.libpaqle.pojo;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Entity {
|
||||
|
||||
@SerializedName(value = "published", alternate = {"Published"})
|
||||
Boolean published;
|
||||
|
||||
@SerializedName(value = "hidden", alternate = {"Hidden"})
|
||||
Boolean hidden;
|
||||
Integer OriginalId;
|
||||
Integer CurrentId;
|
||||
|
||||
@SerializedName(value = "type", alternate = {"Type"})
|
||||
String type;
|
||||
|
||||
@SerializedName(value = "countryCode", alternate = {"CountryCode"})
|
||||
String countryCode;
|
||||
String PaqleUrl;
|
||||
|
||||
@SerializedName(value = "paqleUrl", alternate = {"PaqleUrl"})
|
||||
String paqleUrl;
|
||||
|
||||
/*
|
||||
"Entities": [
|
||||
|
|
|
@ -1,16 +1,35 @@
|
|||
package biz.nellemann.libpaqle.pojo;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class News {
|
||||
|
||||
Integer EntityOriginalId;
|
||||
String ClusterHash;
|
||||
String Published;
|
||||
String LanguageCode;
|
||||
@SerializedName(value = "entityOriginalId", alternate = {"EntityOriginalId"})
|
||||
Long entityOriginalId;
|
||||
|
||||
@SerializedName(value = "clusterHash", alternate = {"ClusterHash"})
|
||||
String clusterHash;
|
||||
|
||||
@SerializedName(value = "published", alternate = {"Published"})
|
||||
Date published;
|
||||
|
||||
@SerializedName(value = "languageCode", alternate = {"LanguageCode"})
|
||||
String languageCode;
|
||||
|
||||
@SerializedName(value = "sourceName", alternate = {"SourceName"})
|
||||
String sourceName;
|
||||
String Url;
|
||||
List<NewsHeadline> Headline;
|
||||
|
||||
@SerializedName(value = "url", alternate = {"Url", "URL"})
|
||||
String url;
|
||||
|
||||
@SerializedName(value = "headline", alternate = {"Headline", "HeadLine"})
|
||||
List<NewsHeadline> headline;
|
||||
|
||||
@SerializedName(value = "extract", alternate = {"Extract"})
|
||||
List<NewsHeadline> extract;
|
||||
|
||||
/*
|
||||
News": [
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package biz.nellemann.libpaqle.pojo;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class NewsExtract {
|
||||
|
||||
String Text;
|
||||
Boolean Highlight;
|
||||
@SerializedName(value = "text", alternate = {"Text"})
|
||||
String text;
|
||||
|
||||
@SerializedName(value = "highlight", alternate = {"Highlight", "HighLight"})
|
||||
Boolean highlight;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package biz.nellemann.libpaqle.pojo;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class NewsHeadline {
|
||||
|
||||
String Text;
|
||||
@SerializedName(value = "text", alternate = {"Text"})
|
||||
String text;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package biz.nellemann.libpaqle.pojo;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// https://entityapi.paqle.net/documentation/entities
|
||||
|
||||
public class PaqleResponse {
|
||||
|
||||
List<Entity> Entities;
|
||||
List<News> News;
|
||||
@SerializedName(value = "entities", alternate = {"Entities"})
|
||||
List<Entity> entities;
|
||||
|
||||
@SerializedName(value = "news", alternate = {"News"})
|
||||
List<News> news;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -23,18 +23,19 @@ class PaqleSpec extends Specification {
|
|||
void "test successful parsing of test JSON"() {
|
||||
|
||||
setup:
|
||||
def testFile = new File(getClass().getResource('/test.json').toURI())
|
||||
def testFile = new File(getClass().getResource('/15027800.json').toURI())
|
||||
def testJson = testFile.getText('UTF-8')
|
||||
mockServer.enqueue(new MockResponse().setBody(testJson));
|
||||
HttpUrl baseUrl = mockServer.url("/");
|
||||
paqle.baseUrl = baseUrl.toString()
|
||||
|
||||
when:
|
||||
PaqleResponse response = paqle.getResponse(["2955224", "4004110055"])
|
||||
PaqleResponse response = paqle.getResponseByVatNumber("15027800")
|
||||
|
||||
then:
|
||||
response.Entities.size() == 2
|
||||
response.News.size() == 100
|
||||
response.entities.size() == 1
|
||||
response.news.size() == 100
|
||||
response.news[0].headline.text.contains('Opkøb skubber til Frejas vækst')
|
||||
}
|
||||
|
||||
// TODO: Test error-cases, 401, 404, timeouts, empty responses, etc.
|
||||
|
|
3112
src/test/resources/15027800.json
Normal file
3112
src/test/resources/15027800.json
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue