Search in sources :

Example 96 with GET

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

the class RequestBuilderTest method getWithPathAndQueryAmpersandParam.

@Test
public void getWithPathAndQueryAmpersandParam() {
    class Example {

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

Example 97 with GET

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

the class RequestBuilderTest method getWithUrlThenQuery.

@Test
public void getWithUrlThenQuery() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url String url, @Query("hey") String hey) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "foo/bar/", "hey!");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?hey=hey%21");
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 98 with GET

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

the class RequestBuilderTest method getWithQueryParamPrimitiveArray.

@Test
public void getWithQueryParamPrimitiveArray() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Query("key") int[] keys) {
            return null;
        }
    }
    int[] values = { 1, 2, 3, 1 };
    Request request = buildRequest(Example.class, new Object[] { values });
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?key=1&key=2&key=3&key=1");
    assertThat(request.body()).isNull();
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 99 with GET

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

the class RequestBuilderTest method getWithQueryParam.

@Test
public void getWithQueryParam() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Query("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/?ping=pong");
    assertThat(request.body()).isNull();
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 100 with GET

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

the class RequestBuilderTest method headerParamList.

@Test
public void headerParamList() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Header("foo") List<String> kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, Arrays.asList("bar", null, "baz"));
    assertThat(request.method()).isEqualTo("GET");
    okhttp3.Headers headers = request.headers();
    assertThat(headers.size()).isEqualTo(2);
    assertThat(headers.values("foo")).containsExactly("bar", "baz");
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    assertThat(request.body()).isNull();
}
Also used : Header(retrofit2.http.Header) Request(okhttp3.Request) List(java.util.List) 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