use of retrofit2.Retrofit in project mobile-sdk-android by meniga.
the class MenigaIdNameKeyValConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
Type typeListOfNetWorthType = new TypeToken<List<KeyVal<Long, String>>>() {
}.getType();
if (typeListOfNetWorthType.equals(type)) {
return new Converter<ResponseBody, Object>() {
@Override
public Object convert(ResponseBody value) throws IOException {
List<KeyVal<Long, String>> list = new ArrayList<>();
JsonArray arr = getAsArray(value.byteStream());
for (int i = 0; i < arr.size(); i++) {
JsonObject entry = (JsonObject) arr.get(i);
KeyVal<Long, String> item = new KeyVal<>(entry.get("id").getAsLong(), entry.get("name").getAsString());
list.add(item);
}
return list;
}
};
}
return null;
}
use of retrofit2.Retrofit in project mobile-sdk-android by meniga.
the class MenigaRedemptionConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
Type typeOfRedemptions = new TypeToken<MenigaRedemptions>() {
}.getType();
if (typeOfRedemptions.equals(type)) {
return new Converter<ResponseBody, MenigaRedemptions>() {
@Override
public MenigaRedemptions convert(ResponseBody resBody) throws IOException {
InputStreamReader isr = new InputStreamReader(resBody.byteStream());
JsonElement element;
try {
element = new JsonParser().parse(isr);
} finally {
isr.close();
}
Gson gson = GsonProvider.getGsonBuilder();
MenigaRedemptions page = gson.fromJson(getAsArray(element), MenigaRedemptions.class);
JsonObject object = element.getAsJsonObject();
JsonObject meta = object.getAsJsonObject("meta");
List<MenigaScheduledReimbursement> cashBackRaw = gson.fromJson(meta.getAsJsonArray("scheduledReimbursements"), new TypeToken<List<MenigaScheduledReimbursement>>() {
}.getType());
MenigaRedemptions main = MenigaConverter.mergeMeta(gson, page, meta);
main.setScheduledReimbursement(cashBackRaw);
return main;
}
};
}
return null;
}
use of retrofit2.Retrofit in project mobile-sdk-android by meniga.
the class MenigaTransactionUpdateConverter method responseBodyConverter.
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, final Retrofit retrofit) {
Type typeOfTransactionUpdate = new TypeToken<MenigaTransactionUpdate>() {
}.getType();
if (typeOfTransactionUpdate.equals(type)) {
return new Converter<ResponseBody, Object>() {
@Override
public Object convert(ResponseBody resBody) throws IOException {
Gson gson = GsonProvider.getGsonBuilder();
InputStreamReader isr = null;
try {
isr = new InputStreamReader(resBody.byteStream());
JsonElement element = new JsonParser().parse(isr);
isr.close();
JsonObject json = element.getAsJsonObject();
List<MenigaTransaction> updatedTransactions = new ArrayList<>();
if (json.get("data").isJsonArray()) {
updatedTransactions = gson.fromJson(json.getAsJsonArray("data"), new TypeToken<List<MenigaTransaction>>() {
}.getType());
} else {
MenigaTransaction updated = gson.fromJson(json.getAsJsonObject("data"), new TypeToken<MenigaTransaction>() {
}.getType());
updatedTransactions.add(updated);
}
List<MenigaTransaction> transactions = new ArrayList<>();
if (json.has("meta")) {
transactions = gson.fromJson(json.getAsJsonArray("meta"), new TypeToken<List<MenigaTransaction>>() {
}.getType());
}
return MenigaTransactionUpdate.fromList(updatedTransactions, transactions);
} finally {
if (isr != null) {
isr.close();
}
}
}
};
}
return null;
}
use of retrofit2.Retrofit in project iNGAGE by davis123123.
the class UserInfoHandler method enqueue.
public void enqueue(String username) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Log.i("STATE", "Retrofit url" + get_url);
Retrofit retrofit = new Retrofit.Builder().client(httpClient.build()).addConverterFactory(GsonConverterFactory.create()).baseUrl(get_url).build();
Interface service = retrofit.create(Interface.class);
Call<ResponseBody> call = service.get(username);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.i("STATE", "Retrofit response code: " + response.code());
if (response.isSuccessful()) {
Log.i("STATE", "Retrofit POST Success");
try {
serverResponse = response.body().string();
callBackData.notifyChange(serverResponse);
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.i("Retrofit Error Code:", String.valueOf(response.code()));
Log.i("Retrofit Error Body", response.errorBody().toString());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.i("STATE", "Retrofit Failure");
}
});
}
use of retrofit2.Retrofit in project run-wallet-android by runplay.
the class RunIotaAPICore method postConstruct.
/**
* added header for IRI
*/
private void postConstruct() {
boolean USE_AUTH = false;
// if(host.contains(".runplay.com") || host.contains(".runpg.com"))
// USE_AUTH=true;
final String nodeUrl = protocol + "://" + host + ":" + port;
if (USE_AUTH) {
// Log.e("IRI-CONNECT","Using Auth OK");
String creds = Base64.encodeToString((uname + ":" + upassword).getBytes(), false);
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = builder.readTimeout(5000, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder().addHeader(X_IOTA_API_VERSION_HEADER_NAME, X_IOTA_API_VERSION_HEADER_VALUE).addHeader("Authorization", "Basic " + creds).build();
return chain.proceed(newRequest);
}
}).connectTimeout(5000, TimeUnit.SECONDS).build();
// use client to create Retrofit service
final Retrofit retrofit = new Retrofit.Builder().baseUrl(nodeUrl).addConverterFactory(GsonConverterFactory.create()).client(client).build();
service = retrofit.create(IotaAPIService.class);
} else {
// Log.e("IRI-CONNECT","NOOTTTTT Using Auth");
final OkHttpClient client = new OkHttpClient.Builder().readTimeout(5000, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder().addHeader(X_IOTA_API_VERSION_HEADER_NAME, X_IOTA_API_VERSION_HEADER_VALUE).build();
return chain.proceed(newRequest);
}
}).connectTimeout(5000, TimeUnit.SECONDS).build();
// use client to create Retrofit service
final Retrofit retrofit = new Retrofit.Builder().baseUrl(nodeUrl).addConverterFactory(GsonConverterFactory.create()).client(client).build();
service = retrofit.create(IotaAPIService.class);
}
// Create OkHttpBuilder
log.debug("Jota-API Java proxy pointing to node url: '{}'", nodeUrl);
}
Aggregations