Search in sources :

Example 1 with QueryName

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

the class RequestBuilderTest method getWithQueryNameParam.

@Test
public void getWithQueryNameParam() {
    class Example {

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

Example 2 with QueryName

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

the class RequestBuilderTest method queryNameParamOptionalOmitsQuery.

@Test
public void queryNameParamOptionalOmitsQuery() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@QueryName String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, new Object[] { null });
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
}
Also used : Request(okhttp3.Request) QueryName(retrofit2.http.QueryName) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 3 with QueryName

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

the class RequestBuilderTest method getWithEncodedQueryNameParam.

@Test
public void getWithEncodedQueryNameParam() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@QueryName(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/?p%20o%20n%20g");
    assertThat(request.body()).isNull();
}
Also used : Request(okhttp3.Request) QueryName(retrofit2.http.QueryName) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 4 with QueryName

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

the class RequestBuilderTest method getWithQueryNameParamPrimitiveArray.

@Test
public void getWithQueryNameParamPrimitiveArray() {
    class Example {

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

Example 5 with QueryName

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

the class RequestBuilderTest method getWithQueryNameParamArray.

@Test
public void getWithQueryNameParamArray() {
    class Example {

        // 
        @GET("/foo/bar/")
        Call<ResponseBody> method(@QueryName Object[] keys) {
            return null;
        }
    }
    Object[] values = { 1, 2, null, "three", "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/?1&2&three&1");
    assertThat(request.body()).isNull();
}
Also used : Request(okhttp3.Request) QueryName(retrofit2.http.QueryName) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

Request (okhttp3.Request)6 ResponseBody (okhttp3.ResponseBody)6 Test (org.junit.Test)6 QueryName (retrofit2.http.QueryName)6 List (java.util.List)1