use of retrofit2.http.POST in project kripton by xcesco.
the class TestConversion method test.
@Test
public void test() throws IOException {
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://jsonplaceholder.typicode.com/").addConverterFactory(KriptonBinderConverterFactory.create()).build();
JsonPlaceHolderService service = retrofit.create(JsonPlaceHolderService.class);
// Response<List<Post>> response = service.getAllPost().execute();
// log(response.toString());
// log(""+list);
}
use of retrofit2.http.POST in project caronae-android by caronae.
the class RideOfferAct method configureActivityWithRide.
private void configureActivityWithRide(final RideForJson rideWithUsers, boolean isFull) {
final boolean requested = getIntent().getBooleanExtra("requested", false);
if (rideWithUsers == null) {
Util.toast(getString(R.string.act_activeride_rideNUll));
finish();
}
AllRidesFrag.setPageThatWas(rideWithUsers.isGoing());
final User driver = rideWithUsers.getDriver();
final boolean isDriver = driver.getDbId() == App.getUser().getDbId();
int color = Util.getColorbyZone(rideWithUsers.getZone());
join_bt.setBackgroundColor(color);
location_dt.setTextColor(color);
final String location;
if (rideWithUsers.isGoing())
location = rideWithUsers.getNeighborhood() + " ➜ " + rideWithUsers.getHub();
else
location = rideWithUsers.getHub() + " ➜ " + rideWithUsers.getNeighborhood();
String profilePicUrl = driver.getProfilePicUrl();
if (profilePicUrl == null || profilePicUrl.isEmpty()) {
Picasso.with(this.getApplicationContext()).load(R.drawable.user_pic).into(user_pic);
} else {
Picasso.with(this.getApplicationContext()).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic);
}
user_pic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isDriver) {
// dont allow user to open own profile
Intent intent = new Intent(getApplicationContext(), ProfileAct.class);
intent.putExtra("user", new Gson().toJson(driver));
intent.putExtra("from", "rideoffer");
startActivity(intent);
}
}
});
location_dt.setText(location);
name_dt.setText(driver.getName());
profile_dt.setText(driver.getProfile());
if (rideWithUsers.getRoute().equals("")) {
way_dt.setText("- - -");
} else {
way_dt.setText(rideWithUsers.getRoute());
}
if (rideWithUsers.getPlace().equals("")) {
place_dt.setText("- - -");
} else {
place_dt.setText(rideWithUsers.getPlace());
}
course_dt.setText(driver.getCourse());
if (rideWithUsers.isGoing())
time_dt.setText(getString(R.string.arrivingAt, Util.formatTime(rideWithUsers.getTime())));
else
time_dt.setText(getString(R.string.leavingAt, Util.formatTime(rideWithUsers.getTime())));
time_dt.setTextColor(color);
date_dt.setText(Util.formatBadDateWithoutYear(rideWithUsers.getDate()));
date_dt.setTextColor(color);
if (rideWithUsers.getDescription().equals("")) {
description_dt.setText("- - -");
} else {
description_dt.setText(rideWithUsers.getDescription());
}
if (isDriver) {
join_bt.setVisibility(View.GONE);
} else {
if (requested) {
join_bt.setVisibility(View.GONE);
requested_dt.setVisibility(View.VISIBLE);
} else {
if (isFull) {
join_bt.setText("CARONA CHEIA");
join_bt.setClickable(false);
} else {
join_bt.setClickable(true);
final Context context = this;
join_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<ActiveRide> list = ActiveRide.find(ActiveRide.class, "date = ? and going = ?", rideWithUsers.getDate(), rideWithUsers.isGoing() ? "1" : "0");
if (list != null && !list.isEmpty()) {
Util.toast(getString(R.string.act_rideOffer_rideConflict));
return;
}
com.rey.material.app.Dialog.Builder builder = new SimpleDialog.Builder(R.style.SlideInDialog) {
@Override
protected void onBuildDone(com.rey.material.app.Dialog dialog) {
dialog.layoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().getAttributes().windowAnimations = R.style.SlideInRightDialog;
}
@Override
public void onPositiveActionClicked(com.rey.material.app.DialogFragment fragment) {
final ProgressDialog pd = ProgressDialog.show(context, "", getString(R.string.wait), true, true);
CaronaeAPI.service(context).requestJoin(String.valueOf(rideWithUsers.getDbId())).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
RideRequestSent rideRequest = new RideRequestSent(rideWithUsers.getDbId(), rideWithUsers.isGoing(), rideWithUsers.getDate());
rideRequest.save();
createChatAssets(rideWithUsers);
join_bt.startAnimation(getAnimationForSendButton());
requested_dt.startAnimation(getAnimationForResquestedText());
App.getBus().post(rideRequest);
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.errorRequestSent));
Log.e("requestJoin", response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
Log.e("requestJoin", t.getMessage());
}
});
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(com.rey.material.app.DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
((SimpleDialog.Builder) builder).message(getString(R.string.act_rideOffer_requestWarn)).title(getString(R.string.attention)).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
com.rey.material.app.DialogFragment fragment = com.rey.material.app.DialogFragment.newInstance(builder);
fragment.show(getSupportFragmentManager(), "a");
}
});
}
}
}
configureShareButton();
}
use of retrofit2.http.POST in project graylog2-server by Graylog2.
the class ClusterSystemShutdownResource method shutdown.
@POST
@Timed
@AuditEvent(type = AuditEventTypes.NODE_SHUTDOWN_INITIATE)
public void shutdown(@PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
LOG.warn("Deprecated API endpoint /cluster/{nodeId}/shutdown was called. Shutting down nodes via the API is " + "discouraged in favor of using a service manager to control the server process.");
final Node targetNode = nodeService.byNodeId(nodeId);
RemoteSystemShutdownResource remoteSystemShutdownResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemShutdownResource.class);
final Response response = remoteSystemShutdownResource.shutdown().execute();
if (response.code() != ACCEPTED.getStatusCode()) {
LOG.warn("Unable send shut down signal to node {}: {}", nodeId, response.message());
throw new WebApplicationException(response.message(), BAD_GATEWAY);
}
}
use of retrofit2.http.POST in project iNGAGE by davis123123.
the class UserRecentCommentHandler method enqueue.
// save recent comment in database
public void enqueue(String username, String thread_id, String messageText, String side, String ip) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
String url = "http://" + ip + "/track_user_comment.php/";
Retrofit retrofit = new Retrofit.Builder().client(httpClient.build()).addConverterFactory(GsonConverterFactory.create()).baseUrl(url).build();
Interface service = retrofit.create(Interface.class);
Call<ResponseBody> call = service.post(username, thread_id, messageText, side, ip);
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();
Log.i("STATE", "Retrofit reponse: " + 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.http.POST in project retrofit by square.
the class RequestBuilderTest method postWithUrl.
@Test
public void postWithUrl() {
class Example {
@POST
Call<ResponseBody> method(@Url String url, @Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
Request request = buildRequest(Example.class, "http://example.com/foo/bar", body);
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar");
assertBody(request.body(), "hi");
}
Aggregations