Search in sources :

Example 31 with POST

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);
}
Also used : Retrofit(retrofit2.Retrofit) Test(org.junit.Test)

Example 32 with POST

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();
}
Also used : User(br.ufrj.caronae.models.User) Gson(com.google.gson.Gson) ProgressDialog(android.app.ProgressDialog) SimpleDialog(com.rey.material.app.SimpleDialog) List(java.util.List) ActiveRide(br.ufrj.caronae.models.ActiveRide) Context(android.content.Context) Call(retrofit2.Call) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) Response(retrofit2.Response) Callback(retrofit2.Callback) RideRequestSent(br.ufrj.caronae.models.RideRequestSent) RoundedTransformation(br.ufrj.caronae.RoundedTransformation)

Example 33 with POST

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);
    }
}
Also used : Response(retrofit2.Response) RemoteSystemShutdownResource(org.graylog2.rest.resources.system.RemoteSystemShutdownResource) WebApplicationException(javax.ws.rs.WebApplicationException) Node(org.graylog2.cluster.Node) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 34 with POST

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");
        }
    });
}
Also used : OkHttpClient(okhttp3.OkHttpClient) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 35 with POST

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");
}
Also used : Request(okhttp3.Request) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) MultipartBody(okhttp3.MultipartBody) Body(retrofit2.http.Body) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)40 Test (org.junit.Test)33 Request (okhttp3.Request)31 Response (retrofit2.Response)27 ServiceResponse (com.microsoft.rest.ServiceResponse)22 RequestBody (okhttp3.RequestBody)19 TypeToken (com.google.common.reflect.TypeToken)18 Product (fixtures.lro.models.Product)18 Buffer (okio.Buffer)14 MultipartBody (okhttp3.MultipartBody)13 Part (retrofit2.http.Part)10 OkHttpClient (okhttp3.OkHttpClient)8 Body (retrofit2.http.Body)8 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 Field (retrofit2.http.Field)6 FieldMap (retrofit2.http.FieldMap)6 PartMap (retrofit2.http.PartMap)6 List (java.util.List)5 Map (java.util.Map)5