Search in sources :

Example 11 with Url

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

the class DynamicBaseUrl method main.

public static void main(String... args) throws IOException {
    HostSelectionInterceptor hostSelectionInterceptor = new HostSelectionInterceptor();
    OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(hostSelectionInterceptor).build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://www.coca-cola.com/").callFactory(okHttpClient).build();
    Pop pop = retrofit.create(Pop.class);
    Response<ResponseBody> response1 = pop.robots().execute();
    System.out.println("Response from: " + response1.raw().request().url());
    System.out.println(response1.body().string());
    hostSelectionInterceptor.setHost("www.pepsi.com");
    Response<ResponseBody> response2 = pop.robots().execute();
    System.out.println("Response from: " + response2.raw().request().url());
    System.out.println(response2.body().string());
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) ResponseBody(okhttp3.ResponseBody)

Example 12 with Url

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

the class RequestBuilderAndroidTest method getWithAndroidUriUrlAbsolute.

@Test
public void getWithAndroidUriUrlAbsolute() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url Uri url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, Uri.parse("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) RequestBuilderTest.buildRequest(retrofit2.RequestBuilderTest.buildRequest) Uri(android.net.Uri) Url(retrofit2.http.Url) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 13 with Url

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

the class RequestBuilderAndroidTest method getWithAndroidUriUrl.

@Test
public void getWithAndroidUriUrl() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url Uri url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, Uri.parse("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) RequestBuilderTest.buildRequest(retrofit2.RequestBuilderTest.buildRequest) Uri(android.net.Uri) Url(retrofit2.http.Url) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 14 with Url

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

the class RequestBuilderTest method getWithStringUrl.

@Test
public void getWithStringUrl() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url String url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "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) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 15 with Url

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

the class RequestBuilderTest method getWithJavaUriUrlAbsolute.

@Test
public void getWithJavaUriUrlAbsolute() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url URI url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, URI.create("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) URI(java.net.URI) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

HttpUrl (okhttp3.HttpUrl)15 ResponseBody (okhttp3.ResponseBody)14 Request (okhttp3.Request)11 Test (org.junit.Test)10 Url (retrofit2.http.Url)10 Response (retrofit2.Response)9 OkHttpClient (okhttp3.OkHttpClient)6 Call (retrofit2.Call)6 Callback (retrofit2.Callback)6 Intent (android.content.Intent)4 View (android.view.View)3 TextView (android.widget.TextView)3 BindView (butterknife.BindView)3 Retrofit (retrofit2.Retrofit)3 ValueAnimator (android.animation.ValueAnimator)2 Application (android.app.Application)2 Context (android.content.Context)2 Uri (android.net.Uri)2 Build (android.os.Build)2 AlertDialog (android.support.v7.app.AlertDialog)2