Search in sources :

Example 16 with GET

use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.

the class ApprovedSentencesFragment method setStatus.

public void setStatus(final Long id) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<Void> call = service.setStatus(id, "rejected", pref_token);
        call.enqueue(new Callback<Void>() {

            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setStatue("rejected");
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 17 with GET

use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.

the class PendingSentencesFragment method setStatus.

public void setStatus(final Long id, final String status) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<Void> call = service.setStatus(id, status, pref_token);
        call.enqueue(new Callback<Void>() {

            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setStatue(status);
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 18 with GET

use of retrofit2.http.GET in project Gladys-Android-App by LeptitGeek.

the class PendingSentencesFragment method setLabel.

public void setLabel(final Long id, final String label) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<BrainSentences> call = service.setLabel(id, label, pref_token);
        call.enqueue(new Callback<BrainSentences>() {

            @Override
            public void onResponse(Call<BrainSentences> all, Response<BrainSentences> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setLabel(response.body().getLabel());
                    brainSentences.setService(response.body().getService());
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<BrainSentences> all, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 19 with GET

use of retrofit2.http.GET in project retrofit by square.

the class RequestBuilderTest method getWithEncodedQueryParam.

@Test
public void getWithEncodedQueryParam() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Query(value = "pi%20ng", encoded = true) String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "p%20o%20n%20g");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?pi%20ng=p%20o%20n%20g");
    assertThat(request.body()).isNull();
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 20 with GET

use of retrofit2.http.GET in project retrofit by square.

the class RequestBuilderTest method getWithUnusedAndInvalidNamedPathParam.

@Test
public void getWithUnusedAndInvalidNamedPathParam() {
    class Example {

        // 
        @GET("/foo/bar/{ping}/{kit,kat}/")
        Call<ResponseBody> method(@Path("ping") String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "pong");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/%7Bkit,kat%7D/");
    assertThat(request.body()).isNull();
}
Also used : Path(retrofit2.http.Path) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)61 Test (org.junit.Test)54 Request (okhttp3.Request)52 Response (retrofit2.Response)27 Retrofit (retrofit2.Retrofit)23 Query (retrofit2.http.Query)15 List (java.util.List)14 IOException (java.io.IOException)12 OkHttpClient (okhttp3.OkHttpClient)12 HttpUrl (okhttp3.HttpUrl)10 Path (retrofit2.http.Path)10 ArrayList (java.util.ArrayList)9 BrainSentences (com.gladysinc.gladys.Models.BrainSentences)8 RetrofitAPI (com.gladysinc.gladys.Utils.RetrofitAPI)8 SelfSigningClientBuilder (com.gladysinc.gladys.Utils.SelfSigningClientBuilder)8 ServiceResponse (com.microsoft.rest.ServiceResponse)8 Call (retrofit2.Call)8 Url (retrofit2.http.Url)8 Uri (android.net.Uri)6 View (android.view.View)6