Search in sources :

Example 41 with GET

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

the class RequestBuilderTest method getWithHttpUrl.

@Test
public void getWithHttpUrl() {
    class Example {

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

Example 42 with GET

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

the class RequestBuilderTest method getWithStringUrlAbsolute.

@Test
public void getWithStringUrlAbsolute() {
    class Example {

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

Example 43 with GET

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

the class RequestBuilderTest method headerMapSupportsSubclasses.

@Test
public void headerMapSupportsSubclasses() {
    class Foo extends HashMap<String, String> {
    }
    class Example {

        @GET("/search")
        Call<ResponseBody> method(@HeaderMap Foo headers) {
            return null;
        }
    }
    Foo headers = new Foo();
    headers.put("Accept", "text/plain");
    Request request = buildRequest(Example.class, headers);
    assertThat(request.url().toString()).isEqualTo("http://example.com/search");
    assertThat(request.headers().size()).isEqualTo(1);
    assertThat(request.header("Accept")).isEqualTo("text/plain");
}
Also used : HeaderMap(retrofit2.http.HeaderMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 44 with GET

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

the class RequestBuilderTest method getWithJavaUriUrl.

@Test
public void getWithJavaUriUrl() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url URI url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, URI.create("foo/bar/"));
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    assertThat(request.body()).isNull();
}
Also used : Request(okhttp3.Request) URI(java.net.URI) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 45 with GET

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

the class RetrofitTest method customCallAdapter.

@Test
public void customCallAdapter() {
    class GreetingCallAdapterFactory extends CallAdapter.Factory {

        @Override
        public CallAdapter<Object, String> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
            if (getRawType(returnType) != String.class) {
                return null;
            }
            return new CallAdapter<Object, String>() {

                @Override
                public Type responseType() {
                    return String.class;
                }

                @Override
                public String adapt(Call<Object> call) {
                    return "Hi!";
                }
            };
        }
    }
    Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(new ToStringConverterFactory()).addCallAdapterFactory(new GreetingCallAdapterFactory()).build();
    StringService example = retrofit.create(StringService.class);
    assertThat(example.get()).isEqualTo("Hi!");
}
Also used : MediaType(okhttp3.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ToStringConverterFactory(retrofit2.helpers.ToStringConverterFactory) NonMatchingCallAdapterFactory(retrofit2.helpers.NonMatchingCallAdapterFactory) DelegatingCallAdapterFactory(retrofit2.helpers.DelegatingCallAdapterFactory) NonMatchingConverterFactory(retrofit2.helpers.NonMatchingConverterFactory) ToStringConverterFactory(retrofit2.helpers.ToStringConverterFactory) 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