use of com.reprezen.kaizen.oasparser.model3.RequestBody in project Infinity-For-Reddit by Docile-Alligator.
the class UploadImageUtils method parseJSONResponseFromAWS.
public static Map<String, RequestBody> parseJSONResponseFromAWS(String response) throws JSONException {
JSONObject responseObject = new JSONObject(response);
JSONArray nameValuePairs = responseObject.getJSONObject(JSONUtils.ARGS_KEY).getJSONArray(JSONUtils.FIELDS_KEY);
Map<String, RequestBody> nameValuePairsMap = new HashMap<>();
for (int i = 0; i < nameValuePairs.length(); i++) {
nameValuePairsMap.put(nameValuePairs.getJSONObject(i).getString(JSONUtils.NAME_KEY), APIUtils.getRequestBody(nameValuePairs.getJSONObject(i).getString(JSONUtils.VALUE_KEY)));
}
return nameValuePairsMap;
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project Infinity-For-Reddit by Docile-Alligator.
the class SubmitPost method submitVideoPost.
public static void submitVideoPost(Executor executor, Handler handler, Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, Retrofit uploadVideoRetrofit, String accessToken, String subredditName, String title, File buffer, String mimeType, Bitmap posterBitmap, Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
String fileType = mimeType.substring(mimeType.indexOf("/") + 1);
Map<String, String> uploadImageParams = new HashMap<>();
uploadImageParams.put(APIUtils.FILEPATH_KEY, "post_video." + fileType);
uploadImageParams.put(APIUtils.MIMETYPE_KEY, mimeType);
Call<String> uploadImageCall = api.uploadImage(APIUtils.getOAuthHeader(accessToken), uploadImageParams);
try {
Response<String> uploadImageResponse = uploadImageCall.execute();
if (uploadImageResponse.isSuccessful()) {
Map<String, RequestBody> nameValuePairsMap = UploadImageUtils.parseJSONResponseFromAWS(uploadImageResponse.body());
RequestBody fileBody = RequestBody.create(buffer, MediaType.parse("application/octet-stream"));
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", "post_video." + fileType, fileBody);
RedditAPI uploadVideoToAWSApi;
if (fileType.equals("gif")) {
uploadVideoToAWSApi = uploadMediaRetrofit.create(RedditAPI.class);
} else {
uploadVideoToAWSApi = uploadVideoRetrofit.create(RedditAPI.class);
}
Call<String> uploadMediaToAWS = uploadVideoToAWSApi.uploadMediaToAWS(nameValuePairsMap, fileToUpload);
Response<String> uploadMediaToAWSResponse = uploadMediaToAWS.execute();
if (uploadMediaToAWSResponse.isSuccessful()) {
String url = UploadImageUtils.parseXMLResponseFromAWS(uploadMediaToAWSResponse.body());
if (url == null) {
submitPostListener.submitFailed(null);
return;
}
String imageUrlOrError = UploadImageUtils.uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, posterBitmap);
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
if (fileType.equals("gif")) {
submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, url, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_VIDEOGIF, imageUrlOrError, submitPostListener);
} else {
submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, url, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_VIDEO, imageUrlOrError, submitPostListener);
}
} else {
submitPostListener.submitFailed(imageUrlOrError);
}
} else {
submitPostListener.submitFailed(uploadMediaToAWSResponse.code() + " " + uploadMediaToAWSResponse.message());
}
} else {
submitPostListener.submitFailed(uploadImageResponse.code() + " " + uploadImageResponse.message());
}
} catch (IOException | XmlPullParserException | JSONException e) {
e.printStackTrace();
submitPostListener.submitFailed(e.getMessage());
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project captcha by anji-plus.
the class BlockPuzzleDialog method loadCaptcha.
private void loadCaptcha() {
Map<String, Object> params = new HashMap<>();
params.put("captchaType", "blockPuzzle");
JSONObject jsonObject = new JSONObject(params);
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
RetrofitUtils.getServerApi().getAsync(body).compose(RxHelper.observableIO2Main(mContext)).subscribe(new BaseObserver<CaptchaGetIt>(mContext, true) {
@Override
public void onSuccess(CaptchaGetIt data) {
baseImageBase64 = data.getOriginalImageBase64();
slideImageBase64 = data.getJigsawImageBase64();
token = data.getToken();
key = data.getSecretKey();
dragView.setUp(ImageUtil.base64ToBitmap(baseImageBase64), ImageUtil.base64ToBitmap(slideImageBase64));
dragView.setSBUnMove(true);
initEvent();
}
@Override
public void onFailure(Throwable e, String errorMsg) {
dragView.setSBUnMove(false);
Toast.makeText(mContext, errorMsg, Toast.LENGTH_SHORT).show();
}
});
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project captcha by anji-plus.
the class WordCaptchaDialog method loadCaptcha.
private void loadCaptcha() {
bottomTitle.setText("数据加载中......");
bottomTitle.setTextColor(Color.BLACK);
Map<String, Object> params = new HashMap<>();
params.put("captchaType", "clickWord");
JSONObject jsonObject = new JSONObject(params);
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
Log.i("wuyan", "body:" + jsonObject);
RetrofitUtils.getServerApi().getWordCaptchaAsync(body).compose(RxHelper.observableIO2Main(mContext)).subscribe(new BaseObserver<WordCaptchaGetIt>(mContext, true) {
@Override
public void onSuccess(WordCaptchaGetIt data) {
baseImageBase64 = data.getOriginalImageBase64();
token = data.getToken();
key = data.getSecretKey();
String wordStr = "";
int j = 0;
for (int i = 0; i < data.getWordList().size(); i++) {
j++;
wordStr += data.getWordList().get(i);
if (j < data.getWordList().size()) {
wordStr += ",";
}
}
wordView.setSize(data.getWordList().size());
bottomTitle.setText("请依此点击【" + wordStr + "】");
bottomTitle.setTextColor(Color.BLACK);
wordView.setUp(ImageUtil.base64ToBitmap(baseImageBase64));
initEvent();
}
@Override
public void onFailure(Throwable e, String errorMsg) {
bottomTitle.setText("加载失败,请刷新");
bottomTitle.setTextColor(Color.RED);
wordView.setSize(-1);
Toast.makeText(mContext, errorMsg, Toast.LENGTH_SHORT).show();
}
});
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project captcha by anji-plus.
the class WordCaptchaDialog method checkCaptcha.
private void checkCaptcha(String cryptedStr) {
Map<String, Object> params = new HashMap<>();
params.put("captchaType", "clickWord");
params.put("token", token);
params.put("pointJson", AESUtil.encode(cryptedStr, key));
JSONObject jsonObject = new JSONObject(params);
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString());
Log.i("wuyan", "body:" + jsonObject);
RetrofitUtils.getServerApi().checkAsync(body).compose(RxHelper.observableIO2Main(mContext)).subscribe(new BaseObserver<CaptchaCheckIt>(mContext, false) {
@Override
public void onSuccess(CaptchaCheckIt data) {
bottomTitle.setText("验证成功");
bottomTitle.setTextColor(Color.GREEN);
wordView.ok();
handler.postDelayed(new Runnable() {
@Override
public void run() {
loadCaptcha();
dismiss();
}
}, 1000);
if (mOnResultsListener != null) {
String result = token + "---" + cryptedStr;
mOnResultsListener.onResultsClick(AESUtil.encode(result, key));
}
}
@Override
public void onFailure(Throwable e, String errorMsg) {
bottomTitle.setText("验证失败");
bottomTitle.setTextColor(Color.RED);
wordView.fail();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// 刷新验证码
loadCaptcha();
}
}, 1000);
}
});
}
Aggregations