Search in sources :

Example 11 with Query

use of retrofit2.http.Query 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 12 with Query

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

the class RequestBuilderTest method getWithPathAndQueryQuestionMarkParam.

@Test
public void getWithPathAndQueryQuestionMarkParam() {
    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%3F/?kit=kat?");
    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 13 with Query

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

the class RequestBuilderTest method getWithEncodedQueryParamMap.

@Test
public void getWithEncodedQueryParamMap() {
    class Example {

        //
        @GET("/foo/bar/")
        Call<ResponseBody> method(@QueryMap(encoded = true) Map<String, Object> query) {
            return null;
        }
    }
    Map<String, Object> params = new LinkedHashMap<>();
    params.put("kit", "k%20t");
    params.put("pi%20ng", "p%20g");
    Request request = buildRequest(Example.class, params);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?kit=k%20t&pi%20ng=p%20g");
    assertThat(request.body()).isNull();
}
Also used : QueryMap(retrofit2.http.QueryMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 14 with Query

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

the class RequestBuilderTest method getWithQueryParamArray.

@Test
public void getWithQueryParamArray() {
    class Example {

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

Example 15 with Query

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

the class RequestBuilderTest method getWithQueryUrlAndParam.

@Test
public void getWithQueryUrlAndParam() {
    class Example {

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

Aggregations

ResponseBody (okhttp3.ResponseBody)18 Request (okhttp3.Request)16 Test (org.junit.Test)16 Query (retrofit2.http.Query)14 Path (retrofit2.http.Path)4 List (java.util.List)3 Retrofit (retrofit2.Retrofit)3 QueryTroubleshootingParameters (com.microsoft.azure.management.network.QueryTroubleshootingParameters)2 ServiceResponse (com.microsoft.rest.ServiceResponse)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Response (retrofit2.Response)2 FieldMap (retrofit2.http.FieldMap)2 HeaderMap (retrofit2.http.HeaderMap)2 PartMap (retrofit2.http.PartMap)2 QueryMap (retrofit2.http.QueryMap)2 ContentUris (android.content.ContentUris)1 Context (android.content.Context)1 Intent (android.content.Intent)1