11 | */
12 | package retrofit;
13 |
--------------------------------------------------------------------------------
/retrofit-converters/wire/README.md:
--------------------------------------------------------------------------------
1 | Wire Converter
2 | ==============
3 |
4 | A `Converter` which uses [Wire][1] for protocol buffer-compatible serialization.
5 |
6 | A default `Wire` instance will be created or one can be configured and passed to the
7 | `WireConverter` construction to further control the serialization.
8 |
9 |
10 | [1]: https://github.com/square/wire
11 |
--------------------------------------------------------------------------------
/retrofit-converters/jackson/README.md:
--------------------------------------------------------------------------------
1 | Jackson Converter
2 | =================
3 |
4 | A `Converter` which uses [Jackson][1] for serialization to and from JSON.
5 |
6 | A default `ObjectMapper` instance will be created or one can be configured and passed to the
7 | `JacksonConverter` construction to further control the serialization.
8 |
9 |
10 | [1]: http://wiki.fasterxml.com/JacksonHome
11 |
--------------------------------------------------------------------------------
/retrofit/src/test/java/retrofit/mime/MimeHelper.java:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Square, Inc.
2 | package retrofit.mime;
3 |
4 | import java.util.List;
5 |
6 | public class MimeHelper {
7 | public static List getParts(MultipartTypedOutput output) {
8 | try {
9 | return output.getParts();
10 | } catch (Exception e) {
11 | throw new RuntimeException(e);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/Endpoint.java:
--------------------------------------------------------------------------------
1 | package retrofit;
2 |
3 | /**
4 | * Represents an API endpoint URL and associated name. Callers should always consult the instance
5 | * for the latest values rather than caching the returned values.
6 | *
7 | * @author Matt Hickman (mhickman@palantir.com)
8 | */
9 | public interface Endpoint {
10 |
11 | /** The base API URL. */
12 | String getUrl();
13 |
14 | /** A name for differentiating between multiple API URLs. */
15 | String getName();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/retrofit-converters/README.md:
--------------------------------------------------------------------------------
1 | Retrofit Converters
2 | ===================
3 |
4 | Retrofit ships with a default converter for JSON that uses Gson but the library is content-format
5 | agnostic. The child modules contained herein are additional converters for other popular formats.
6 |
7 | To use, supply an instance of your desired converter when building your `RestAdapter` instance.
8 |
9 | ```java
10 | RestAdapter restAdapter = new RestAdapter.Builder()
11 | .setEndpoint("https://api.example.com")
12 | .setConverter(new ProtoConverter())
13 | .build();
14 | ```
15 |
--------------------------------------------------------------------------------
/retrofit-converters/simplexml/README.md:
--------------------------------------------------------------------------------
1 | Simple XML Converter
2 | ====================
3 |
4 | A `Converter` which uses [Simple][1] for XML serialization.
5 |
6 | A default `Serializer` instance will be created or one can be configured and passed to the
7 | `SimpleXMLConverter` construction to further control the serialization.
8 |
9 |
10 | Android
11 | -------
12 |
13 | Simple depends on artifacts which are already provided by the Android platform. When specifying as
14 | a Maven or Gradle dependency, exclude the following transitive dependencies: `stax:stax-api`,
15 | `stax:stax`, and `xpp3:xpp3`.
16 |
17 |
18 |
19 | [1]: http://simple.sourceforge.net/
20 |
--------------------------------------------------------------------------------
/retrofit-mock/src/main/java/retrofit/MockHttpRetrofitError.java:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Square, Inc.
2 | package retrofit;
3 |
4 | import java.lang.reflect.Type;
5 | import retrofit.client.Response;
6 |
7 | class MockHttpRetrofitError extends RetrofitError {
8 | private final Object body;
9 |
10 | MockHttpRetrofitError(String message, String url, Response response, Object body,
11 | Type responseType) {
12 | super(message, url, response, null, responseType, false, null);
13 | this.body = body;
14 | }
15 |
16 | @Override public Object getBody() {
17 | return body;
18 | }
19 |
20 | @Override public Object getBodyAs(Type type) {
21 | return body;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/retrofit/src/test/java/retrofit/EndpointsTest.java:
--------------------------------------------------------------------------------
1 | // Copyright 2014 Square, Inc.
2 | package retrofit;
3 |
4 | import org.junit.Test;
5 |
6 | import static org.assertj.core.api.Assertions.assertThat;
7 |
8 | public class EndpointsTest {
9 | @Test public void endpointOnly() {
10 | Endpoint endpoint = Endpoints.newFixedEndpoint("http://example.com");
11 | assertThat(endpoint.getUrl()).isEqualTo("http://example.com");
12 | }
13 |
14 | @Test public void endpointAndName() {
15 | Endpoint endpoint = Endpoints.newFixedEndpoint("http://example.com", "production");
16 | assertThat(endpoint.getUrl()).isEqualTo("http://example.com");
17 | assertThat(endpoint.getName()).isEqualTo("production");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/retrofit-converters/protobuf-nano/README.md:
--------------------------------------------------------------------------------
1 | Google Nano Protocol Buffer Converter
2 | =====================================
3 |
4 | A `Converter` which uses [Nano Protocol Buffer][1] binary serialization.
5 |
6 | To build this module, you will need to [install][2] the Android external\_protobuf module.
7 |
8 | To use the converter, depend on the `nano` classifier:
9 |
10 | ```xml
11 |
12 | com.squareup.retrofit
13 | retrofit-converters
14 | nano
15 |
16 | ```
17 |
18 | [1]: https://github.com/android/platform_external_protobuf/tree/master/java/src/main/java/com/google/protobuf/nano
19 | [2]: https://github.com/android/platform_external_protobuf/blob/master/java/README.txt
20 |
--------------------------------------------------------------------------------
/retrofit/src/test/java/retrofit/mime/TypedByteArrayTest.java:
--------------------------------------------------------------------------------
1 | // Copyright 2010 Square, Inc.
2 | package retrofit.mime;
3 |
4 | import org.junit.Test;
5 |
6 | import static org.assertj.core.api.Assertions.assertThat;
7 |
8 | public class TypedByteArrayTest {
9 | private static final String GIF = "image/gif";
10 |
11 | @Test public void objectEquals() {
12 | TypedByteArray a1 = new TypedByteArray(GIF, new byte[] { 10, 20 });
13 | TypedByteArray a2 = new TypedByteArray(GIF, new byte[] { 10, 20 });
14 | TypedByteArray b = new TypedByteArray(GIF, new byte[] { 8, 12 });
15 |
16 | assertThat(a1).isEqualTo(a2);
17 | assertThat(a1.hashCode()).isEqualTo(a2.hashCode());
18 | assertThat(a1).isNotEqualTo(b);
19 | assertThat(a1.hashCode()).isNotEqualTo(b.hashCode());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing
2 | ============
3 |
4 | If you would like to contribute code to Retrofit you can do so through GitHub by
5 | forking the repository and sending a pull request.
6 |
7 | When submitting code, please make every effort to follow existing conventions
8 | and style in order to keep the code as readable as possible. Please also make
9 | sure your code compiles by running `mvn clean verify`. Checkstyle failures
10 | during compilation indicate errors in your style and can be viewed in the
11 | `checkstyle-result.xml` file.
12 |
13 | Before your code can be accepted into the project you must also sign the
14 | [Individual Contributor License Agreement (CLA)][1].
15 |
16 |
17 | [1]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1
18 |
--------------------------------------------------------------------------------
/retrofit-samples/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | com.squareup.retrofit
8 | parent
9 | 1.6.2-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | com.squareup.retrofit.samples
14 | parent
15 | Samples
16 | pom
17 |
18 |
19 | github-client
20 | mock-github-client
21 |
22 |
23 |
--------------------------------------------------------------------------------
/retrofit-samples/github-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | com.squareup.retrofit.samples
8 | parent
9 | 1.6.2-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | github-client
14 | Sample: GitHub Client
15 |
16 |
17 |
18 | com.squareup.retrofit
19 | retrofit
20 | ${project.version}
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/android/AndroidLog.java:
--------------------------------------------------------------------------------
1 | package retrofit.android;
2 |
3 | import android.util.Log;
4 | import retrofit.RestAdapter;
5 |
6 | /** A {@link RestAdapter.Log logger} for Android. */
7 | public class AndroidLog implements RestAdapter.Log {
8 | private static final int LOG_CHUNK_SIZE = 4000;
9 |
10 | private final String tag;
11 |
12 | public AndroidLog(String tag) {
13 | this.tag = tag;
14 | }
15 |
16 | @Override public final void log(String message) {
17 | for (int i = 0, len = message.length(); i < len; i += LOG_CHUNK_SIZE) {
18 | int end = Math.min(len, i + LOG_CHUNK_SIZE);
19 | logChunk(message.substring(i, end));
20 | }
21 | }
22 |
23 | /**
24 | * Called one or more times for each call to {@link #log(String)}. The length of {@code chunk}
25 | * will be no more than 4000 characters to support Android's {@link Log} class.
26 | */
27 | public void logChunk(String chunk) {
28 | Log.d(getTag(), chunk);
29 | }
30 |
31 | public String getTag() {
32 | return tag;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/deploy_website.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -ex
4 |
5 | REPO="git@github.com:square/retrofit.git"
6 | GROUP_ID="com.squareup.retrofit"
7 | ARTIFACT_ID="retrofit"
8 |
9 | DIR=temp-clone
10 |
11 | # Delete any existing temporary website clone
12 | rm -rf $DIR
13 |
14 | # Clone the current repo into temp folder
15 | git clone $REPO $DIR
16 |
17 | # Move working directory into temp folder
18 | cd $DIR
19 |
20 | # Checkout and track the gh-pages branch
21 | git checkout -t origin/gh-pages
22 |
23 | # Delete everything
24 | rm -rf *
25 |
26 | # Copy website files from real repo
27 | cp -R ../website/* .
28 |
29 | # Download the latest javadoc
30 | curl -L "http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=$GROUP_ID&a=$ARTIFACT_ID&v=LATEST&c=javadoc" > javadoc.zip
31 | mkdir javadoc
32 | unzip javadoc.zip -d javadoc
33 | rm javadoc.zip
34 |
35 | # Stage all files in git and create a commit
36 | git add .
37 | git add -u
38 | git commit -m "Website at $(date)"
39 |
40 | # Push the new files up to GitHub
41 | git push origin gh-pages
42 |
43 | # Delete our temp folder
44 | cd ..
45 | rm -rf $DIR
46 |
--------------------------------------------------------------------------------
/retrofit-samples/mock-github-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 | 4.0.0
9 |
10 |
11 | com.squareup.retrofit.samples
12 | parent
13 | 1.6.2-SNAPSHOT
14 | ../pom.xml
15 |
16 |
17 | mock-github-client
18 | Sample: Mock GitHub Client
19 |
20 |
21 |
22 | com.squareup.retrofit
23 | retrofit
24 | ${project.version}
25 |
26 |
27 | com.squareup.retrofit
28 | retrofit-mock
29 | ${project.version}
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/android/MainThreadExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.android;
17 |
18 | import android.os.Handler;
19 | import android.os.Looper;
20 |
21 | import java.util.concurrent.Executor;
22 |
23 | /** Executor that runs tasks on Android's main thread. */
24 | public final class MainThreadExecutor implements Executor {
25 | private final Handler handler = new Handler(Looper.getMainLooper());
26 |
27 | @Override public void execute(Runnable r) {
28 | handler.post(r);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/Endpoints.java:
--------------------------------------------------------------------------------
1 | package retrofit;
2 |
3 | /**
4 | * Static factory methods for creating {@link Endpoint} instances.
5 | *
6 | * @author Matt Hickman (mhickman@palantir.com)
7 | */
8 | public final class Endpoints {
9 | private static final String DEFAULT_NAME = "default";
10 |
11 | private Endpoints() {
12 | }
13 |
14 | /** Create a server with the provided URL. */
15 | public static Endpoint newFixedEndpoint(String url) {
16 | return new FixedEndpoint(url, DEFAULT_NAME);
17 | }
18 |
19 | /** Create an endpoint with the provided URL and name. */
20 | public static Endpoint newFixedEndpoint(String url, String name) {
21 | return new FixedEndpoint(url, name);
22 | }
23 |
24 | private static class FixedEndpoint implements Endpoint {
25 | private final String apiUrl;
26 | private final String name;
27 |
28 | FixedEndpoint(String apiUrl, String name) {
29 | this.apiUrl = apiUrl;
30 | this.name = name;
31 | }
32 |
33 | @Override public String getUrl() {
34 | return apiUrl;
35 | }
36 |
37 | @Override public String getName() {
38 | return name;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/RestMethod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | @Documented
26 | @Target(ANNOTATION_TYPE)
27 | @Retention(RUNTIME)
28 | public @interface RestMethod {
29 | String value();
30 | boolean hasBody() default false;
31 | }
32 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/GET.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /** Make a GET request to a REST path relative to base URL. */
26 | @Documented
27 | @Target(METHOD)
28 | @Retention(RUNTIME)
29 | @RestMethod("GET")
30 | public @interface GET {
31 | String value();
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/HEAD.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /** Make a HEAD request to a REST path relative to base URL. */
26 | @Documented
27 | @Target(METHOD)
28 | @Retention(RUNTIME)
29 | @RestMethod("HEAD")
30 | public @interface HEAD {
31 | String value();
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/DELETE.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /** Make a DELETE request to a REST path relative to base URL. */
26 | @Documented
27 | @Target(METHOD)
28 | @Retention(RUNTIME)
29 | @RestMethod("DELETE")
30 | public @interface DELETE {
31 | String value();
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/test/java/retrofit/TestingUtils.java:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Square, Inc.
2 | package retrofit;
3 |
4 | import java.io.IOException;
5 | import java.lang.reflect.Method;
6 | import java.util.Map;
7 | import retrofit.mime.MultipartTypedOutput;
8 | import retrofit.mime.TypedOutput;
9 |
10 | import static org.assertj.core.api.Assertions.assertThat;
11 |
12 | public abstract class TestingUtils {
13 | public static Method getMethod(Class c, String name) {
14 | for (Method method : c.getDeclaredMethods()) {
15 | if (method.getName().equals(name)) {
16 | return method;
17 | }
18 | }
19 | throw new IllegalArgumentException("Unknown method '" + name + "' on " + c);
20 | }
21 |
22 | public static TypedOutput createMultipart(Map parts) {
23 | MultipartTypedOutput typedOutput = new MultipartTypedOutput();
24 | for (Map.Entry part : parts.entrySet()) {
25 | typedOutput.addPart(part.getKey(), part.getValue());
26 | }
27 | return typedOutput;
28 | }
29 |
30 | public static void assertBytes(byte[] bytes, String expected) throws IOException {
31 | assertThat(new String(bytes, "UTF-8")).isEqualTo(expected);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/PUT.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /** Make a PUT request to a REST path relative to base URL. */
26 | @Documented
27 | @Target(METHOD)
28 | @Retention(RUNTIME)
29 | @RestMethod(value = "PUT", hasBody = true)
30 | public @interface PUT {
31 | String value();
32 | }
33 |
--------------------------------------------------------------------------------
/website/static/app-theme.css:
--------------------------------------------------------------------------------
1 | /* http://www.colorhexa.com/48b982 */
2 |
3 | /*** Primary ***/
4 |
5 | header,
6 | #subtitle,
7 | a.dl {
8 | background-color: #48b983;
9 | }
10 |
11 | .content-nav li.active a,
12 | .content-nav li.active a:hover {
13 | border-left-color: #48b983;
14 | }
15 |
16 | /*** One step left on the monochromatic scale ***/
17 |
18 | header menu li a:hover,
19 | a.dl:hover {
20 | background-color: #40a776;
21 | }
22 | a {
23 | color: #40a776;
24 | }
25 |
26 | /*** Three steps left on the monochromatic scale ***/
27 |
28 | a:hover {
29 | color: #32835c;
30 | }
31 |
32 |
33 | /****************************************************************\
34 | **** Syntax highlighting styles ********************************
35 | \****************************************************************/
36 |
37 | .pln { color: #000; }
38 | .str { color: #32835b; }
39 | .kwd { color: #666; }
40 | .com { color: #800; }
41 | .typ { color: #222; }
42 | .lit { color: #666; }
43 | .pun { color: #888; }
44 | .opn { color: #888; }
45 | .clo { color: #888; }
46 | .tag { color: #32835b; }
47 | .atn { color: #606; }
48 | .atv { color: #080; }
49 | .dec { color: #606; }
50 | .var { color: #606; }
51 | .fun { color: #f00; }
52 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/POST.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /** Make a POST request to a REST path relative to base URL. */
26 | @Documented
27 | @Target(METHOD)
28 | @Retention(RUNTIME)
29 | @RestMethod(value = "POST", hasBody = true)
30 | public @interface POST {
31 | String value();
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/PATCH.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /** Make a PATCH request to a REST path relative to base URL. */
26 | @Documented
27 | @Target(METHOD)
28 | @Retention(RUNTIME)
29 | @RestMethod(value = "PATCH", hasBody = true)
30 | public @interface PATCH {
31 | String value();
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/converter/ConversionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.converter;
17 |
18 | /** Indicate that conversion was unable to complete successfully. */
19 | @SuppressWarnings("UnusedDeclaration")
20 | public class ConversionException extends Exception {
21 | public ConversionException(String message) {
22 | super(message);
23 | }
24 |
25 | public ConversionException(String message, Throwable throwable) {
26 | super(message, throwable);
27 | }
28 |
29 | public ConversionException(Throwable throwable) {
30 | super(throwable);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/ResponseCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit;
17 |
18 | import retrofit.client.Response;
19 |
20 | /**
21 | * An extension of {@link Callback} which returns only {@link Response} object
22 | * in {@link Callback#success(Object, retrofit.client.Response)} method.
23 | */
24 | public abstract class ResponseCallback implements Callback {
25 |
26 | @Override public void success(Response response, Response response2) {
27 | success(response);
28 | }
29 |
30 | /** Successful HTTP response. */
31 | public abstract void success(Response response);
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/Multipart.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Denotes that the request body is multi-part. Parts should be declared as parameters and
27 | * annotated with {@link Part @Part}.
28 | */
29 | @Documented
30 | @Target(METHOD)
31 | @Retention(RUNTIME)
32 | public @interface Multipart {
33 | }
34 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/ResponseWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit;
17 |
18 | import retrofit.client.Response;
19 |
20 | /**
21 | * A wrapper that holds the {@link Response} and {@link retrofit.converter.Converter} response to
22 | * be used by the {@link CallbackRunnable} for success method calls on {@link Callback}.
23 | *
24 | * @author JJ Ford (jj.n.ford@gmail.com)
25 | */
26 | final class ResponseWrapper {
27 | final Response response;
28 | final Object responseBody;
29 |
30 | ResponseWrapper(Response response, Object responseBody) {
31 | this.response = response;
32 | this.responseBody = responseBody;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/Streaming.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Treat the response body on methods returning {@link retrofit.client.Response Response} as is,
27 | * i.e. without converting {@link retrofit.client.Response#getBody() getBody()} to {@code byte[]}.
28 | */
29 | @Documented
30 | @Target(METHOD)
31 | @Retention(RUNTIME)
32 | public @interface Streaming {
33 | }
34 |
--------------------------------------------------------------------------------
/retrofit-converters/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | com.squareup.retrofit
8 | parent
9 | 1.6.2-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | retrofit-converters
14 | Converters
15 | pom
16 |
17 |
18 | protobuf
19 | jackson
20 | wire
21 | simplexml
22 |
23 |
24 |
25 |
26 | nano
27 |
28 | protobuf-nano
29 |
30 |
31 |
32 |
33 | maven-jar-plugin
34 |
35 | nano
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/retrofit-mock/src/main/java/retrofit/MockTypedInput.java:
--------------------------------------------------------------------------------
1 | // Copyright 2013 Square, Inc.
2 | package retrofit;
3 |
4 | import java.io.ByteArrayInputStream;
5 | import java.io.ByteArrayOutputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import retrofit.converter.Converter;
9 | import retrofit.mime.TypedInput;
10 |
11 | class MockTypedInput implements TypedInput {
12 | private final Converter converter;
13 | private final Object body;
14 |
15 | private byte[] bytes;
16 |
17 | MockTypedInput(Converter converter, Object body) {
18 | this.converter = converter;
19 | this.body = body;
20 | }
21 |
22 | @Override public String mimeType() {
23 | return "application/unknown";
24 | }
25 |
26 | @Override public long length() {
27 | try {
28 | initBytes();
29 | } catch (IOException e) {
30 | throw new RuntimeException(e);
31 | }
32 | return bytes.length;
33 | }
34 |
35 | @Override public InputStream in() throws IOException {
36 | initBytes();
37 | return new ByteArrayInputStream(bytes);
38 | }
39 |
40 | private synchronized void initBytes() throws IOException {
41 | if (bytes == null) {
42 | ByteArrayOutputStream out = new ByteArrayOutputStream();
43 | converter.toBody(body).writeTo(out);
44 | bytes = out.toByteArray();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/mime/TypedOutput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.mime;
17 |
18 | import java.io.IOException;
19 | import java.io.OutputStream;
20 |
21 | /**
22 | * Binary data with an associated mime type.
23 | *
24 | * @author Bob Lee (bob@squareup.com)
25 | */
26 | public interface TypedOutput {
27 | /** Original filename.
28 | *
29 | * Used only for multipart requests, may be null. */
30 | String fileName();
31 |
32 | /** Returns the mime type. */
33 | String mimeType();
34 |
35 | /** Length in bytes or -1 if unknown. */
36 | long length();
37 |
38 | /** Writes these bytes to the given output stream. */
39 | void writeTo(OutputStream out) throws IOException;
40 | }
41 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/mime/TypedInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.mime;
17 |
18 | import java.io.IOException;
19 | import java.io.InputStream;
20 |
21 | /**
22 | * Binary data with an associated mime type.
23 | *
24 | * @author Jake Wharton (jw@squareup.com)
25 | */
26 | public interface TypedInput {
27 |
28 | /** Returns the mime type. */
29 | String mimeType();
30 |
31 | /** Length in bytes. Returns {@code -1} if length is unknown. */
32 | long length();
33 |
34 | /**
35 | * Read bytes as stream. Unless otherwise specified, this method may only be called once. It is
36 | * the responsibility of the caller to close the stream.
37 | */
38 | InputStream in() throws IOException;
39 | }
40 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Retrofit
2 | ========
3 |
4 | Type-safe REST client for Android and Java by Square, Inc.
5 |
6 | For more information please see [the website][1].
7 |
8 |
9 | Download
10 | --------
11 |
12 | Download [the latest JAR][2] or grab via Maven:
13 | ```xml
14 |
15 | com.squareup.retrofit
16 | retrofit
17 | 1.6.1
18 |
19 | ```
20 | or Gradle:
21 | ```groovy
22 | compile 'com.squareup.retrofit:retrofit:1.6.1'
23 | ```
24 |
25 |
26 |
27 | License
28 | =======
29 |
30 | Copyright 2013 Square, Inc.
31 |
32 | Licensed under the Apache License, Version 2.0 (the "License");
33 | you may not use this file except in compliance with the License.
34 | You may obtain a copy of the License at
35 |
36 | http://www.apache.org/licenses/LICENSE-2.0
37 |
38 | Unless required by applicable law or agreed to in writing, software
39 | distributed under the License is distributed on an "AS IS" BASIS,
40 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41 | See the License for the specific language governing permissions and
42 | limitations under the License.
43 |
44 |
45 | [1]: http://square.github.io/retrofit/
46 | [2]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.retrofit&a=retrofit&v=LATEST
47 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/android/AndroidApacheClient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.android;
17 |
18 | import android.net.http.AndroidHttpClient;
19 | import retrofit.client.ApacheClient;
20 |
21 | /**
22 | * Provides a {@link retrofit.client.Client} which uses the Android-specific version of
23 | * {@link org.apache.http.client.HttpClient}, {@link AndroidHttpClient}.
24 | *
25 | * If you need to provide a customized version of the {@link AndroidHttpClient} or a different
26 | * {@link org.apache.http.client.HttpClient} on Android use {@link ApacheClient} directly.
27 | */
28 | public final class AndroidApacheClient extends ApacheClient {
29 | public AndroidApacheClient() {
30 | super(AndroidHttpClient.newInstance("Retrofit"));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/mime/MimeUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.mime;
17 |
18 | import java.util.regex.Matcher;
19 | import java.util.regex.Pattern;
20 |
21 | import static java.util.regex.Pattern.CASE_INSENSITIVE;
22 |
23 | public final class MimeUtil {
24 | private static final Pattern CHARSET = Pattern.compile("\\Wcharset=([^\\s;]+)", CASE_INSENSITIVE);
25 |
26 | /** Parse the MIME type from a {@code Content-Type} header value. */
27 | public static String parseCharset(String mimeType) {
28 | Matcher match = CHARSET.matcher(mimeType);
29 | if (match.find()) {
30 | return match.group(1).replaceAll("[\"\\\\]", "");
31 | }
32 | return "UTF-8";
33 | }
34 |
35 | private MimeUtil() {
36 | // No instances.
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/retrofit/src/test/java/retrofit/mime/MimeUtilTest.java:
--------------------------------------------------------------------------------
1 | // Copyright 2012 Square, Inc.
2 | package retrofit.mime;
3 |
4 | import org.junit.Test;
5 |
6 | import static org.assertj.core.api.Assertions.assertThat;
7 | import static retrofit.mime.MimeUtil.parseCharset;
8 |
9 | public class MimeUtilTest {
10 | @Test public void charsetParsing() {
11 | assertThat(parseCharset("text/plain;charset=utf-8")).isEqualToIgnoringCase("UTF-8");
12 | assertThat(parseCharset("text/plain; charset=utf-8")).isEqualToIgnoringCase("UTF-8");
13 | assertThat(parseCharset("text/plain; charset=utf-8")).isEqualToIgnoringCase("UTF-8");
14 | assertThat(parseCharset("text/plain; \tcharset=utf-8")).isEqualToIgnoringCase("UTF-8");
15 | assertThat(parseCharset("text/plain; \r\n\tcharset=utf-8")).isEqualToIgnoringCase("UTF-8");
16 | assertThat(parseCharset("text/plain; CHARSET=utf-8")).isEqualToIgnoringCase("UTF-8");
17 | assertThat(parseCharset("text/plain; charset=UTF-8")).isEqualToIgnoringCase("UTF-8");
18 | assertThat(parseCharset("text/plain; charset=\"\\u\\tf-\\8\"")).isEqualToIgnoringCase("UTF-8");
19 | assertThat(parseCharset("text/plain; charset=\"utf-8\"")).isEqualToIgnoringCase("UTF-8");
20 | assertThat(parseCharset("text/plain;charset=utf-8;other=thing")).isEqualToIgnoringCase("UTF-8");
21 | assertThat(parseCharset("text/plain; notthecharset=utf-16;")).isEqualToIgnoringCase("UTF-8");
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/Path.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.PARAMETER;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Named replacement in the URL path. Values are converted to string using
27 | * {@link String#valueOf(Object)}. Replaced values will be URL encoded.
28 | *
34 | * Path parameters may not be {@code null}.
35 | */
36 | @Documented
37 | @Retention(RUNTIME)
38 | @Target(PARAMETER)
39 | public @interface Path {
40 | String value();
41 | }
42 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/mime/TypedString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.mime;
17 |
18 | import java.io.UnsupportedEncodingException;
19 |
20 | public class TypedString extends TypedByteArray {
21 |
22 | public TypedString(String string) {
23 | super("text/plain; charset=UTF-8", convertToBytes(string));
24 | }
25 |
26 | private static byte[] convertToBytes(String string) {
27 | try {
28 | return string.getBytes("UTF-8");
29 | } catch (UnsupportedEncodingException e) {
30 | throw new RuntimeException(e);
31 | }
32 | }
33 |
34 | @Override public String toString() {
35 | try {
36 | return "TypedString[" + new String(getBytes(), "UTF-8") + "]";
37 | } catch (UnsupportedEncodingException e) {
38 | throw new AssertionError("Must be able to decode UTF-8");
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/retrofit-converters/simplexml/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | com.squareup.retrofit
8 | retrofit-converters
9 | 1.6.2-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | converter-simplexml
14 | Converter: SimpleXML
15 |
16 |
17 |
18 | com.squareup.retrofit
19 | retrofit
20 | ${project.version}
21 |
22 |
23 | org.simpleframework
24 | simple-xml
25 |
26 |
27 |
28 | junit
29 | junit
30 | test
31 |
32 |
33 | org.assertj
34 | assertj-core
35 | test
36 |
37 |
38 | com.google.guava
39 | guava
40 | test
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/retrofit-converters/jackson/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | com.squareup.retrofit
8 | retrofit-converters
9 | 1.6.2-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | converter-jackson
14 | Converter: Jackson
15 |
16 |
17 |
18 | com.squareup.retrofit
19 | retrofit
20 | ${project.version}
21 |
22 |
23 | com.fasterxml.jackson.core
24 | jackson-databind
25 |
26 |
27 |
28 | junit
29 | junit
30 | test
31 |
32 |
33 | org.assertj
34 | assertj-core
35 | test
36 |
37 |
38 | com.google.guava
39 | guava
40 | test
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/retrofit-converters/protobuf/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | com.squareup.retrofit
8 | retrofit-converters
9 | 1.6.2-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | converter-protobuf
14 | Converter: Protocol Buffers
15 |
16 |
17 |
18 | com.squareup.retrofit
19 | retrofit
20 | ${project.version}
21 |
22 |
23 | com.google.protobuf
24 | protobuf-java
25 |
26 |
27 |
28 | junit
29 | junit
30 | test
31 |
32 |
33 | org.assertj
34 | assertj-core
35 | test
36 |
37 |
38 | com.google.guava
39 | guava
40 | test
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/EncodedQueryMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.PARAMETER;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Query keys and values appended to the URL.
27 | *
28 | * Both keys and values are converted to strings using {@link String#valueOf(Object)}. Values are
29 | * not URL encoded. {@code null} values will not include the query parameter in the URL. See
30 | * {@link QueryMap @QueryMap} for URL-encoding equivalent.
31 | *
32 | * @see Query
33 | * @see QueryMap
34 | * @see EncodedQuery
35 | */
36 | @Documented
37 | @Target(PARAMETER)
38 | @Retention(RUNTIME)
39 | public @interface EncodedQueryMap {
40 | }
41 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/EncodedQuery.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.PARAMETER;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Encoded query parameter appended to the URL.
27 | *
28 | * Values are converted to strings using {@link String#valueOf(Object)}. Values are not URL
29 | * encoded. {@code null} values will not include the query parameter in the URL. See
30 | * {@link Query @Query} for URL-encoding equivalent.
31 | *
32 | * @see Query
33 | * @see QueryMap
34 | * @see EncodedQueryMap
35 | */
36 | @Documented
37 | @Target(PARAMETER)
38 | @Retention(RUNTIME)
39 | public @interface EncodedQuery {
40 | String value();
41 | }
42 |
--------------------------------------------------------------------------------
/retrofit-converters/protobuf-nano/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 4.0.0
5 |
6 |
7 | com.squareup.retrofit
8 | retrofit-converters
9 | 1.6.2-SNAPSHOT
10 | ../pom.xml
11 |
12 |
13 | converter-protobuf-nano
14 | Converter: Nano Protocol Buffers
15 |
16 |
17 |
18 | com.squareup.retrofit
19 | retrofit
20 | ${project.version}
21 |
22 |
23 | com.google.protobuf
24 | protobuf-java
25 | 2.3.0
26 |
27 |
28 | com.google.guava
29 | guava
30 |
31 |
32 |
33 | junit
34 | junit
35 | test
36 |
37 |
38 | org.assertj
39 | assertj-core
40 | test
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/FormUrlEncoded.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Denotes that the request body will use form URL encoding. Fields should be declared as
27 | * parameters and annotated with {@link Field @Field}.
28 | *
29 | * Requests made with this annotation will have {@code application/x-www-form-urlencoded} MIME
30 | * type. Field names and values will be UTF-8 encoded before being URI-encoded in accordance to
31 | * RFC-3986.
32 | */
33 | @Documented
34 | @Target(METHOD)
35 | @Retention(RUNTIME)
36 | public @interface FormUrlEncoded {
37 | }
38 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/EncodedPath.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.PARAMETER;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Named replacement in the URL path. Values are converted to string using
27 | * {@link String#valueOf(Object)}. Values are used literally without URL encoding. See
28 | * {@link retrofit.http.Path @Path} for URL encoding equivalent.
29 | *
33 | * Header parameters may be {@code null} which will omit them from the request.
34 | *
35 | * Note: Headers do not overwrite each other. All headers with the same name will
36 | * be included in the request.
37 | *
38 | * @author Adrian Cole (adrianc@netflix.com)
39 | */
40 | @Documented
41 | @Retention(RUNTIME)
42 | @Target(PARAMETER)
43 | public @interface Header {
44 | String value();
45 | }
46 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/Headers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.METHOD;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Adds headers literally supplied in the {@code value}.
27 | *
41 | * Note: Headers do not overwrite each other. All headers with the same name will
42 | * be included in the request.
43 | *
44 | * @author Adrian Cole (adrianc@netflix.com)
45 | */
46 | @Documented
47 | @Target(METHOD)
48 | @Retention(RUNTIME)
49 | public @interface Headers {
50 | String[] value();
51 | }
52 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/http/FieldMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit.http;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.Target;
21 |
22 | import static java.lang.annotation.ElementType.PARAMETER;
23 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
24 |
25 | /**
26 | * Named key/value pairs for a form-encoded request.
27 | *
28 | * Field values may be {@code null} which will omit them from the request body.
29 | *
37 | * Calling with {@code foo.things(ImmutableMap.of("foo", "bar", "kit", "kat")} yields a request
38 | * body of {@code foo=bar&kit=kat}.
39 | *
40 | * @see FormUrlEncoded
41 | * @see Field
42 | */
43 | @Documented
44 | @Target(PARAMETER)
45 | @Retention(RUNTIME)
46 | public @interface FieldMap {
47 | }
48 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/RequestInterceptor.java:
--------------------------------------------------------------------------------
1 | package retrofit;
2 |
3 | /** Intercept every request before it is executed in order to add additional data. */
4 | public interface RequestInterceptor {
5 | /** Called for every request. Add data using methods on the supplied {@link RequestFacade}. */
6 | void intercept(RequestFacade request);
7 |
8 | interface RequestFacade {
9 | /** Add a header to the request. This will not replace any existing headers. */
10 | void addHeader(String name, String value);
11 |
12 | /**
13 | * Add a path parameter replacement. This works exactly like a {@link retrofit.http.Path
14 | * @Path}-annotated method argument.
15 | */
16 | void addPathParam(String name, String value);
17 |
18 | /**
19 | * Add a path parameter replacement without first URI encoding. This works exactly like a
20 | * {@link retrofit.http.EncodedPath @EncodedPath}-annotated method argument.
21 | */
22 | void addEncodedPathParam(String name, String value);
23 |
24 | /** Add an additional query parameter. This will not replace any existing query parameters. */
25 | void addQueryParam(String name, String value);
26 |
27 | /**
28 | * Add an additional query parameter without first URI encoding. This will not replace any
29 | * existing query parameters.
30 | */
31 | void addEncodedQueryParam(String name, String value);
32 | }
33 |
34 | /** A {@link RequestInterceptor} which does no modification of requests. */
35 | RequestInterceptor NONE = new RequestInterceptor() {
36 | @Override public void intercept(RequestFacade request) {
37 | // Do nothing.
38 | }
39 | };
40 | }
41 |
--------------------------------------------------------------------------------
/retrofit/src/main/java/retrofit/Callback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package retrofit;
17 |
18 | import retrofit.client.Response;
19 |
20 | /**
21 | * Communicates responses from a server or offline requests. One and only one method will be
22 | * invoked in response to a given request.
23 | *
24 | * Callback methods are executed using the {@link RestAdapter} callback executor. When none is
25 | * specified, the following defaults are used:
26 | *
27 | *
Android: Callbacks are executed on the application's main (UI) thread.
28 | *
JVM: Callbacks are executed on the background thread which performed the request.
29 | *
30 | *
31 | * @param expected response type
32 | * @see RestAdapter.Builder#setExecutors
33 | */
34 | public interface Callback {
35 |
36 | /** Successful HTTP response. */
37 | void success(T t, Response response);
38 |
39 | /**
40 | * Unsuccessful HTTP response due to network failure, non-2XX status code, or unexpected
41 | * exception.
42 | */
43 | void failure(RetrofitError error);
44 | }
45 |
--------------------------------------------------------------------------------
/website/static/jquery-maven-artifact.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | * jQuery Maven Artifact Plugin
3 | *
4 | * Version: 1.0.1
5 | * Author: Jake Wharton
6 | * License: Apache 2.0
7 | */
8 | (function($){function downloadUrl(groupId,artifactId,version,type){var groupPath=groupId.replace(/\./g,"/");return"http://repo1.maven.org/maven2/"+groupPath+"/"+artifactId+"/"+version+"/"+artifactId+"-"+version+type}$.fn.artifactVersion=function(groupId,artifactId,callback){if(typeof groupId!=="string"||typeof artifactId!=="string"){console.log("Error: groupId and artifactId are required.");return}if(typeof callback==="undefined"){console.log("Error: callback function required.");return}var url='http://search.maven.org/solrsearch/select/?q=g:"'+groupId+'"+AND+a:"'+artifactId+'"&wt=json&json.wrf=?';$.getJSON(url,function(response){var versions=response.response.docs;if(versions.length==0){return}var version=versions[0].latestVersion;var versionUrl=downloadUrl(groupId,artifactId,version,".jar");callback(version,versionUrl)})};$.fn.artifactVersions=function(groupId,artifactId,callback){if(typeof groupId!=="string"||typeof artifactId!=="string"){console.log("Error: groupId and artifactId are required.");return}if(typeof callback==="undefined"){console.log("Error: callback function required.");return}var url='http://search.maven.org/solrsearch/select/?q=g:"'+groupId+'"+AND+a:"'+artifactId+'"&wt=json&rows=10&core=gav&json.wrf=?';$.getJSON(url,function(response){var versions=response.response.docs;if(versions.length==0){return}versions.sort(function(o1,o2){return o1.v>o2.v?-1:1});var newVersions=[];for(var i=0;i
28 | * Both keys and values are converted to strings using {@link String#valueOf(Object)}. Values are
29 | * URL encoded and {@code null} will not include the query parameter in the URL.
30 | *