use of okhttp3.RequestBody in project Reader by TheKeeperOfPie.
the class Reddit method tokenAuthBlocking.
public String tokenAuthBlocking() throws ExecutionException, InterruptedException {
RequestBody requestBody = new FormBody.Builder().add(QUERY_GRANT_TYPE, QUERY_REFRESH_TOKEN).add(QUERY_REFRESH_TOKEN, accountManager.getPassword(account)).build();
Request request = Reddit.withRequestBasicAuth().url(Reddit.ACCESS_URL).post(requestBody).build();
try {
return okHttpClientDefault.newCall(request).execute().body().string();
} catch (IOException e) {
return null;
}
}
use of okhttp3.RequestBody in project Reader by TheKeeperOfPie.
the class Reddit method getApplicationWideTokenBlocking.
private void getApplicationWideTokenBlocking() {
if ("".equals(preferences.getString(AppSettings.DEVICE_ID, ""))) {
preferences.edit().putString(AppSettings.DEVICE_ID, UUID.randomUUID().toString()).apply();
}
RequestBody requestBody = new FormBody.Builder().add(QUERY_GRANT_TYPE, INSTALLED_CLIENT_GRANT).add(QUERY_DEVICE_ID, preferences.getString(AppSettings.DEVICE_ID, UUID.randomUUID().toString())).build();
Request request = new Request.Builder().url(ACCESS_URL).post(requestBody).build();
try {
String response = okHttpClientDefault.newCall(request).execute().body().string();
// Check if an account was set while fetching a token
if (account == null) {
JSONObject jsonObject = new JSONObject(response);
tokenAuth = jsonObject.getString(QUERY_ACCESS_TOKEN);
timeExpire = System.currentTimeMillis() + jsonObject.getLong(QUERY_EXPIRES_IN) * SEC_TO_MS;
}
} catch (JSONException | IOException e) {
e.printStackTrace();
}
}
use of okhttp3.RequestBody in project MVCHelper by LuckyJayce.
the class PostFileMethod method buildRequset.
@Override
protected Request.Builder buildRequset(String url, Map<String, Object> params) {
MultipartBody.Builder builder = new MultipartBody.Builder();
if (params != null) {
for (Entry<String, ?> entry : params.entrySet()) {
builder.addFormDataPart(entry.getKey(), String.valueOf(entry.getValue()));
}
}
if (httpbodys != null) {
for (Entry<String, Data2<String, RequestBody>> entry : httpbodys.entrySet()) {
String key = entry.getKey();
Data2<String, RequestBody> body = entry.getValue();
builder.addFormDataPart(key, body.getValue1(), body.getValue2());
}
}
RequestBody formBody = builder.build();
if (listener != null) {
formBody = new CountingRequestBody(formBody, listener);
}
return new Request.Builder().url(url).post(formBody);
}
use of okhttp3.RequestBody in project MVCHelper by LuckyJayce.
the class PostMethod method buildRequset.
@Override
protected Request.Builder buildRequset(String url, Map<String, Object> params) {
FormBody.Builder builder = new FormBody.Builder();
if (params != null) {
for (Entry<String, ?> entry : params.entrySet()) {
builder.add(entry.getKey(), String.valueOf(entry.getValue()));
}
}
RequestBody formBody = builder.build();
return new Request.Builder().url(url).post(formBody);
}
use of okhttp3.RequestBody in project MVCHelper by LuckyJayce.
the class PutMethod method buildRequset.
@Override
protected Request.Builder buildRequset(String url, Map<String, Object> params) {
FormBody.Builder builder = new FormBody.Builder();
if (params != null) {
for (Entry<String, ?> entry : params.entrySet()) {
builder.add(entry.getKey(), String.valueOf(entry.getValue()));
}
}
RequestBody formBody = builder.build();
return new Request.Builder().url(url).put(formBody);
}
Aggregations