use of retrofit2.Retrofit in project Varis-Android by dkhmelenko.
the class TravisRestClient method updateTravisEndpoint.
/**
* Updates Travis endpoint
*
* @param newEndpoint New endpoint
*/
public void updateTravisEndpoint(String newEndpoint) {
Retrofit retrofit = mRetrofit.newBuilder().baseUrl(newEndpoint).client(getHttpClient()).build();
mApiService = retrofit.create(TravisApiService.class);
}
use of retrofit2.Retrofit in project mobile-sdk-android by meniga.
the class MockClient method getApi.
public static MenigaAPI getApi(Interceptor myInterceptor) {
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(myInterceptor).build();
final Retrofit retrofit = new Retrofit.Builder().addConverterFactory(new MenigaTransactionsConverter()).addConverterFactory(new MenigaFeedConverter(new MockFeedItemFactory())).addConverterFactory(new MenigaCategoryConverter()).addConverterFactory(new MenigaOfferConverter()).addConverterFactory(new MenigaRedemptionConverter()).addConverterFactory(new MenigaReimbursementAccountConverter()).addConverterFactory(new MenigaIdNameKeyValConverter()).addConverterFactory(new MenigaChallengesConverter(new ChallengeItemFactory())).addConverterFactory(new MenigaFeedItemConverter(new MockFeedItemFactory())).addConverterFactory(new MenigaBaseConverter()).addConverterFactory(GsonConverterFactory.create()).baseUrl("http://meniga.is/api/").client(client).build();
return retrofit.create(MenigaAPI.class);
}
use of retrofit2.Retrofit in project mobile-sdk-android by meniga.
the class MenigaBaseConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, T> responseBodyConverter(final Type type, Annotation[] annotations, Retrofit retrofit) {
return new Converter<ResponseBody, T>() {
@Override
public T convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
InputStreamReader isr = new InputStreamReader(resBody.byteStream());
JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(isr).getAsJsonObject();
JsonElement jsonElement;
if (jsonObject.has("data") && !type.equals(typeOfObject)) {
jsonElement = jsonObject.get("data");
} else {
jsonElement = jsonObject;
}
return gson.fromJson(jsonElement, type);
}
};
}
use of retrofit2.Retrofit in project mobile-sdk-android by meniga.
the class MenigaCategoryConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
Type typeOfMenigaCategoryList = new TypeToken<List<MenigaCategory>>() {
}.getType();
Type typeOfMenigaCategory = new TypeToken<MenigaCategory>() {
}.getType();
Type typeOfMenigaUserCategoryList = new TypeToken<List<MenigaUserCategory>>() {
}.getType();
Type typeOfMenigaUserCategory = new TypeToken<MenigaUserCategory>() {
}.getType();
if (typeOfMenigaCategoryList.equals(type) || typeOfMenigaUserCategoryList.equals(type)) {
return new Converter<ResponseBody, Object>() {
@Override
public List<MenigaCategory> convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
MenigaCategory[] catsRaw = gson.fromJson(getAsArray(resBody.byteStream()), MenigaCategory[].class);
List<MenigaCategory> cats = new ArrayList<>();
for (MenigaCategory cat : catsRaw) {
if (cat.getIsPublic()) {
cats.add(cat);
} else {
cats.add(new MenigaUserCategory(cat));
}
for (int i = 0; i < cat.getChildren().size(); i++) {
MenigaCategory child = cat.getChildren().get(i);
if (!child.getIsPublic()) {
cat.getChildren().set(i, new MenigaUserCategory(child));
}
}
}
return cats;
}
};
} else if (typeOfMenigaCategory.equals(type) || typeOfMenigaUserCategory.equals(type)) {
return new Converter<ResponseBody, Object>() {
@Override
public MenigaCategory convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
MenigaCategory catRaw = gson.fromJson(getAsObject(resBody.byteStream()), MenigaCategory.class);
if (catRaw.getIsPublic()) {
return catRaw;
} else {
return new MenigaUserCategory(catRaw);
}
}
};
}
return null;
}
use of retrofit2.Retrofit 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;
}
Aggregations