use of retrofit2.http.POST in project plaid by nickbutcher.
the class DesignerNewsStory method setupCommentField.
@NonNull
private View setupCommentField() {
View enterCommentView = getLayoutInflater().inflate(R.layout.designer_news_enter_comment, commentsList, false);
enterComment = (EditText) enterCommentView.findViewById(R.id.comment);
postComment = (ImageButton) enterCommentView.findViewById(R.id.post_comment);
postComment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (designerNewsPrefs.isLoggedIn()) {
if (TextUtils.isEmpty(enterComment.getText()))
return;
enterComment.setEnabled(false);
postComment.setEnabled(false);
final Call<Comment> comment = designerNewsPrefs.getApi().comment(story.id, enterComment.getText().toString());
comment.enqueue(new Callback<Comment>() {
@Override
public void onResponse(Call<Comment> call, Response<Comment> response) {
enterComment.getText().clear();
enterComment.setEnabled(true);
postComment.setEnabled(true);
commentsAdapter.addComment(response.body());
}
@Override
public void onFailure(Call<Comment> call, Throwable t) {
Toast.makeText(getApplicationContext(), "Failed to post comment :(", Toast.LENGTH_SHORT).show();
enterComment.setEnabled(true);
postComment.setEnabled(true);
}
});
} else {
needsLogin(postComment, 0);
}
enterComment.clearFocus();
}
});
enterComment.setOnFocusChangeListener(enterCommentFocus);
return enterCommentView;
}
use of retrofit2.http.POST in project iNGAGE by davis123123.
the class UserRecentCommentHandler method enqueue.
// get all recent comments for each room, for the user
public void enqueue(String username) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
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();
createCommentsList(serverResponse);
callBackData.notifyChange();
} 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.http.POST in project instructure-android by instructure.
the class AddSubmissionFragment method setUpCallback.
// /////////////////////////////////////////////////////////////////////////
// CallBack
// /////////////////////////////////////////////////////////////////////////
public void setUpCallback() {
canvasCallbackSubmission = new StatusCallback<Submission>() {
@Override
public void onResponse(@NonNull Response<Submission> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
if (!apiCheck()) {
return;
}
Submission result = response.body();
if (result.getBody() != null || result.getUrl() != null) {
Toast.makeText(getActivity(), R.string.successPostingSubmission, Toast.LENGTH_LONG).show();
// clear text fields because they are saved
textSubmission.setText("");
urlSubmission.setText("");
// Send broadcast so list is updated.
EventBus.getDefault().post(new FileUploadEvent(new FileUploadNotification(null, new ArrayList<Attachment>())));
Navigation navigation = getNavigation();
if (navigation != null)
navigation.popCurrentFragment();
} else {
Toast.makeText(getActivity(), R.string.errorPostingSubmission, Toast.LENGTH_LONG).show();
}
}
};
mLTIToolCallback = new StatusCallback<List<LTITool>>() {
@Override
public void onResponse(@NonNull Response<List<LTITool>> response, @NonNull LinkHeaders linkHeaders, @NonNull ApiType type) {
for (LTITool ltiTool : response.body()) {
final String url = ltiTool.getUrl();
if (url != null && url.contains("instructuremedia.com/lti/launch")) {
mArcUpload.setVisibility(View.VISIBLE);
mArcLTITool = ltiTool;
break;
}
}
// check to see if we should automatically show the file upload dialog
showFileUploadDialog();
}
@Override
public void onFail(@Nullable Call<List<LTITool>> call, @NonNull Throwable error, @Nullable Response response) {
// we don't want to show it if this failed due to there being no cache
if (response != null && response.code() != 504) {
showFileUploadDialog();
}
}
};
}
use of retrofit2.http.POST in project autorest.java by Azure.
the class HeadersImpl method paramDatetimeRfc1123WithServiceResponseAsync.
/**
* Send a post request with header values "scenario": "valid", "value": "Wed, 01 Jan 2010 12:34:56 GMT" or "scenario": "min", "value": "Mon, 01 Jan 0001 00:00:00 GMT".
*
* @param scenario Send a post request with header values "scenario": "valid" or "min"
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceResponse} object if successful.
*/
public Observable<ServiceResponse<Void>> paramDatetimeRfc1123WithServiceResponseAsync(String scenario) {
if (scenario == null) {
throw new IllegalArgumentException("Parameter scenario is required and cannot be null.");
}
final DateTime value = null;
DateTimeRfc1123 valueConverted = null;
if (value != null) {
valueConverted = new DateTimeRfc1123(value);
}
return service.paramDatetimeRfc1123(scenario, valueConverted).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
@Override
public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
try {
ServiceResponse<Void> clientResponse = paramDatetimeRfc1123Delegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of retrofit2.http.POST in project autorest.java by Azure.
the class LRORetrysImpl method post202Retry200WithServiceResponseAsync.
/**
* Long running post request, service returns a 500, then a 202 to the initial request, with 'Location' and 'Retry-After' headers, Polls return a 200 with a response body after success.
*
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable for the request
*/
public Observable<ServiceResponseWithHeaders<Void, LRORetrysPost202Retry200Headers>> post202Retry200WithServiceResponseAsync() {
final Product product = null;
Observable<Response<ResponseBody>> observable = service.post202Retry200(product, this.client.acceptLanguage(), this.client.userAgent());
return client.getAzureClient().getPostOrDeleteResultWithHeadersAsync(observable, new TypeToken<Void>() {
}.getType(), LRORetrysPost202Retry200Headers.class);
}
Aggregations