forked from square/retrofit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from square/master
update fork
- Loading branch information
Showing
67 changed files
with
4,990 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Releasing | ||
======== | ||
|
||
1. Change the version in `gradle.properties` to a non-SNAPSHOT verson. | ||
2. Update the `CHANGELOG.md` for the impending release. | ||
3. Update the `README.md` with the new version. | ||
4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) | ||
5. `./gradlew clean uploadArchives`. | ||
6. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. | ||
7. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version) | ||
8. Update the `gradle.properties` to the next SNAPSHOT version. | ||
9. `git commit -am "Prepare next development version."` | ||
10. `git push && git push --tags` | ||
|
||
If step 5 or 6 fails, drop the Sonatype repo, fix the problem, commit, and start again at step 5. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
POM_ARTIFACT_ID=adapter-guava | ||
POM_NAME=Adapter: Guava | ||
POM_DESCRIPTION=A Retrofit CallAdapter for Guava's ListenableFuture. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
POM_ARTIFACT_ID=adapter-java8 | ||
POM_NAME=Adapter: Java 8 | ||
POM_DESCRIPTION=A Retrofit CallAdapter for Java 8's CompletableFuture. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
POM_ARTIFACT_ID=adapter-rxjava | ||
POM_NAME=Adapter: RxJava | ||
POM_DESCRIPTION=A Retrofit CallAdapter for RxJava's stream types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
POM_ARTIFACT_ID=adapter-rxjava2 | ||
POM_NAME=Adapter: RxJava 2 | ||
POM_DESCRIPTION=A Retrofit CallAdapter for RxJava 2's stream types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
RxJava3 Adapter | ||
============== | ||
|
||
An `Adapter` for adapting [RxJava 3.x][1] types. | ||
|
||
Available types: | ||
|
||
* `Observable<T>`, `Observable<Response<T>>`, and `Observable<Result<T>>` where `T` is the body type. | ||
* `Flowable<T>`, `Flowable<Response<T>>` and `Flowable<Result<T>>` where `T` is the body type. | ||
* `Single<T>`, `Single<Response<T>>`, and `Single<Result<T>>` where `T` is the body type. | ||
* `Maybe<T>`, `Maybe<Response<T>>`, and `Maybe<Result<T>>` where `T` is the body type. | ||
* `Completable` where response bodies are discarded. | ||
|
||
|
||
Usage | ||
----- | ||
|
||
Add `RxJava3CallAdapterFactory` as a `Call` adapter when building your `Retrofit` instance: | ||
```java | ||
Retrofit retrofit = new Retrofit.Builder() | ||
.baseUrl("https://example.com/") | ||
.addCallAdapterFactory(RxJava3CallAdapterFactory.create()) | ||
.build(); | ||
``` | ||
|
||
Your service methods can now use any of the above types as their return type. | ||
```java | ||
interface MyService { | ||
@GET("/user") | ||
Observable<User> getUser(); | ||
} | ||
``` | ||
|
||
By default, `create()` will produce reactive types which execute their HTTP requests asynchronously | ||
on a background thread. There are two other ways to control the threading on which a request | ||
occurs: | ||
|
||
* Use `createSynchronous()` and call `subscribeOn` on the returned reactive type with a `Scheduler` | ||
of your choice. | ||
* Use `createWithScheduler(Scheduler)` to supply a default subscription `Scheduler`. | ||
|
||
Download | ||
-------- | ||
|
||
Download [the latest JAR][2] or grab via [Maven][3]: | ||
```xml | ||
<dependency> | ||
<groupId>com.squareup.retrofit2</groupId> | ||
<artifactId>adapter-rxjava3</artifactId> | ||
<version>latest.version</version> | ||
</dependency> | ||
``` | ||
or [Gradle][3]: | ||
```groovy | ||
implementation 'com.squareup.retrofit2:adapter-rxjava3:latest.version' | ||
``` | ||
|
||
Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. | ||
|
||
|
||
|
||
[1]: https://github.com/ReactiveX/RxJava/tree/3.x | ||
[2]: https://search.maven.org/remote_content?g=com.squareup.retrofit2&a=adapter-rxjava3&v=LATEST | ||
[3]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.squareup.retrofit2%22%20a%3A%22adapter-rxjava3%22 | ||
[snap]: https://oss.sonatype.org/content/repositories/snapshots/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apply plugin: 'java-library' | ||
apply plugin: 'com.vanniktech.maven.publish' | ||
|
||
dependencies { | ||
api project(':retrofit') | ||
api deps.rxjava3 | ||
api deps.reactiveStreams | ||
compileOnly deps.findBugsAnnotations | ||
|
||
testImplementation deps.junit | ||
testImplementation deps.assertj | ||
testImplementation deps.guava | ||
testImplementation deps.mockwebserver | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Automatic-Module-Name': 'retrofit2.adapter.rxjava3' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POM_ARTIFACT_ID=adapter-rxjava3 | ||
POM_NAME=Adapter: RxJava 3 | ||
POM_DESCRIPTION=A Retrofit CallAdapter for RxJava 3's stream types. |
89 changes: 89 additions & 0 deletions
89
retrofit-adapters/rxjava3/src/main/java/retrofit2/adapter/rxjava3/BodyObservable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2020 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package retrofit2.adapter.rxjava3; | ||
|
||
import io.reactivex.rxjava3.core.Observable; | ||
import io.reactivex.rxjava3.core.Observer; | ||
import io.reactivex.rxjava3.disposables.Disposable; | ||
import io.reactivex.rxjava3.exceptions.CompositeException; | ||
import io.reactivex.rxjava3.exceptions.Exceptions; | ||
import io.reactivex.rxjava3.plugins.RxJavaPlugins; | ||
import retrofit2.Response; | ||
|
||
final class BodyObservable<T> extends Observable<T> { | ||
private final Observable<Response<T>> upstream; | ||
|
||
BodyObservable(Observable<Response<T>> upstream) { | ||
this.upstream = upstream; | ||
} | ||
|
||
@Override | ||
protected void subscribeActual(Observer<? super T> observer) { | ||
upstream.subscribe(new BodyObserver<>(observer)); | ||
} | ||
|
||
private static class BodyObserver<R> implements Observer<Response<R>> { | ||
private final Observer<? super R> observer; | ||
private boolean terminated; | ||
|
||
BodyObserver(Observer<? super R> observer) { | ||
this.observer = observer; | ||
} | ||
|
||
@Override | ||
public void onSubscribe(Disposable disposable) { | ||
observer.onSubscribe(disposable); | ||
} | ||
|
||
@Override | ||
public void onNext(Response<R> response) { | ||
if (response.isSuccessful()) { | ||
observer.onNext(response.body()); | ||
} else { | ||
terminated = true; | ||
Throwable t = new HttpException(response); | ||
try { | ||
observer.onError(t); | ||
} catch (Throwable inner) { | ||
Exceptions.throwIfFatal(inner); | ||
RxJavaPlugins.onError(new CompositeException(t, inner)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
if (!terminated) { | ||
observer.onComplete(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(Throwable throwable) { | ||
if (!terminated) { | ||
observer.onError(throwable); | ||
} else { | ||
// This should never happen! onNext handles and forwards errors automatically. | ||
Throwable broken = | ||
new AssertionError( | ||
"This should never happen! Report as a bug with the full stacktrace."); | ||
//noinspection UnnecessaryInitCause Two-arg AssertionError constructor is 1.7+ only. | ||
broken.initCause(throwable); | ||
RxJavaPlugins.onError(broken); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.