Search in sources :

Example 16 with Url

use of retrofit2.http.Url 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 17 with Url

use of retrofit2.http.Url 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 18 with Url

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

the class RequestBuilderTest method postWithUrl.

@Test
public void postWithUrl() {
    class Example {

        @POST
        Call<ResponseBody> method(@Url String url, @Body RequestBody body) {
            return null;
        }
    }
    RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
    Request request = buildRequest(Example.class, "http://example.com/foo/bar", body);
    assertThat(request.method()).isEqualTo("POST");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar");
    assertBody(request.body(), "hi");
}
Also used : Request(okhttp3.Request) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) MultipartBody(okhttp3.MultipartBody) Body(retrofit2.http.Body) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 19 with Url

use of retrofit2.http.Url 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!");
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 20 with Url

use of retrofit2.http.Url 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)

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