use of com.meniga.sdk.models.feed.MenigaFeed in project mobile-sdk-android by meniga.
the class MenigaFeedConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
Type typeOfFeed = new TypeToken<MenigaFeed>() {
}.getType();
if (typeOfFeed.equals(type)) {
return new Converter<ResponseBody, MenigaFeed>() {
@Override
public MenigaFeed convert(ResponseBody resBody) throws IOException {
MenigaFeed feed = new MenigaFeed();
JsonArray arr = getAsArray(resBody.byteStream());
for (JsonElement element : arr) {
feed.add(feedItemFactory.getMenigaFeetItem((JsonObject) element));
}
try {
InputStreamReader isr = new InputStreamReader(resBody.byteStream());
JsonElement jelement = new JsonParser().parse(isr);
JsonObject jobject = jelement.getAsJsonObject();
if (jobject.has("meta")) {
JsonObject meta = jobject.getAsJsonObject("meta");
feed.setHasMoreData(meta.get("hasMoreData").getAsBoolean());
} else {
feed.setHasMoreData(true);
}
} catch (Exception ex) {
feed.setHasMoreData(true);
}
return feed;
}
};
}
return null;
}
use of com.meniga.sdk.models.feed.MenigaFeed in project mobile-sdk-android by meniga.
the class MenigaFeedTest method test.
@Test
public void test() throws Exception {
// Create a MockWebServer. These are lean enough that you can create a new
// instance for every unit test.
MockWebServer server = new MockWebServer();
// Schedule some responses.
server.enqueue(new MockResponse().setBody(FileImporter.getJsonFileFromRaw("feed.json")));
// Start the server.
server.start();
// Ask the server for its URL. You'll need this to make HTTP requests.
HttpUrl baseUrl = server.url("/v1");
MenigaSettings settings = new MenigaSettings.Builder().endpoint(baseUrl).build();
MenigaSDK.init(settings);
Task<MenigaFeed> feedTaskTask = MenigaFeed.fetch(new DateTime(), new DateTime()).getTask();
feedTaskTask.waitForCompletion();
MenigaFeed feed = feedTaskTask.getResult();
Assert.assertNotNull(feed);
Assert.assertEquals(12, feed.size());
// Shut down the server. Instances cannot be reused.
server.shutdown();
}
Aggregations