Skip to content

Commit

Permalink
Merge branch 'master' into ahe/update-build-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron He committed Jul 1, 2018
2 parents 078d5b1 + b803f8f commit ea3281d
Show file tree
Hide file tree
Showing 187 changed files with 576 additions and 226 deletions.
21 changes: 21 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2

jobs:
build:
docker:
- image: circleci/android:api-27-alpha
environment:
TERM: dumb
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" -Dorg.gradle.parallel=false -Dorg.gradle.daemon=true'
CIRCLE_TEST_REPORTS: test-reports
resource_class: xlarge
parallelism: 4
steps:
- checkout
- run:
name: Disable PreDexing
command: echo "disablePreDex" >> gradle.properties
- run: if [ -e ./gradlew ]; then ./gradlew dependencies;else gradle dependencies;fi
- run: ./gradlew test
- run: mkdir -p $CIRCLE_TEST_REPORTS/junit/
- run: find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;
111 changes: 61 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
Scarlet
===
[![CircleCI](https://circleci.com/gh/Tinder/Scarlet.svg?style=svg)](https://circleci.com/gh/Tinder/Scarlet)
[![Release](https://jitpack.io/v/tinder/scarlet.svg)](https://jitpack.io/#tinder/scarlet)

A Retrofit inspired WebSocket client for Kotlin, Java, and Android.

This README is still **WIP**. Please see the [tutorial][tutorial] for more information.

Tutorial
---
- [Taming WebSocket with Scarlet][tutorial]
- [A talk][slides] at [Conference for Kotliners][kotliners]

Usage
---
In this example, we are reading the realtime Bitcoin price from [Gdax WebSocket Feed][gdax-websocket-feed].
In this example, we read the realtime Bitcoin price from [Gdax WebSocket Feed][gdax-websocket-feed].
For more information, please check out the [demo app][demo-app].

Declare a WebSocket client using an interface.
Declare a WebSocket client using an interface:

~~~ kotlin
interface GdaxService {
@Receive
fun observeOnConnectionOpenedEvent(): Flowable<WebSocket.Event.OnConnectionOpen<*>>
@Send
fun sendSubscribe(subscribe: Subscribe)
@Receive
fun observeTicker(): Flowable<Ticker>
@Receive
fun observeOnConnectionOpenedEvent(): Flowable<WebSocket.Event.OnConnectionOpen<*>>
}
val gdaxService = scarlet.create<GdaxService>()
~~~

Use Scarlet to create an implementation.
Use Scarlet to create an implementation:

~~~ kotlin
val okHttpClient = OkHttpClient.Builder().build()

val scarletInstance = Scarlet.Builder()
.webSocketFactory(okHttpClient.newWebSocketFactory("wss://ws-feed.gdax.com"))
.addMessageAdapterFactory(MoshiMessageAdapter.Factory())
Expand All @@ -42,7 +40,9 @@ val scarletInstance = Scarlet.Builder()
val gdaxService = scarletInstance.create<GdaxService>()
~~~

Send a `Subscribe` message upon connection open so that the server will start streaming tickers, which contain the latest price.
Send a `Subscribe` message upon connection open and the server will start streaming tickers which contain the latest price.


~~~ kotlin
val BITCOIN_TICKER_SUBSCRIBE_MESSAGE = Subscribe(
productIds = listOf("BTC-USD"),
Expand All @@ -53,64 +53,72 @@ gdaxService.observeOnConnectionOpenedEvent()
.subscribe({
gdaxService.sendSubscribe(BITCOIN_TICKER_SUBSCRIBE_MESSAGE)
})
~~~

Start observing realtime tickers.
~~~ kotlin
gdaxService.observeTicker()
.subscribe({ ticker ->
Log.d("Bitcoin price is ${ticker.price} at ${ticker.time}")
})
~~~

### Built-in Plugins
`WebSocket.Factory`
- `OkHttpClient`
- `MockHttpServer`

`MessageAdapter.Factory`
- moshi
- gson
- protobuf

`StreamAdapter.Factory`
- RxJava2
- RxJava1

`Lifecycle`
- AndroidLifecycle

`BackoffStrategy`
- Linear
- Exponential
- ExponentialWithJitter
### Android
Scarlet is driven by a [StateMachine](https://github.com/Tinder/StateMachine).

### Android
TODO:
- `AndroidLifecycle`
<img width="600 px" src="/example/scarlet-state-machine.png"/>


### State Machine
Scarlet is driven by a [StateMachine](https://github.com/Tinder/StateMachine).
![State Diagram](./example/scarlet-state-machine.png)
TODO

Download
--------
**TODO: make the jar public**
While we are working on Bintray support, Scarlet is available via [JitPack](jitpack).

Download [the latest JAR][latest-jar] or grab via Maven:
##### Maven:
```xml
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.tinder.scarlet</groupId>
<artifactId>scarlet</artifactId>
<version>0.1.0</version>
<groupId>com.github.tinder.scarlet</groupId>
<artifactId>scarlet</artifactId>
<version>0.1.3</version>
</dependency>
```
or Gradle:

##### Gradle:
```groovy
implementation 'com.tinder.scarlet:scarlet:0.1.0'
repositories {
// ...
maven { url "https://jitpack.io" }
}
implementation 'com.github.tinder.scarlet:scarlet:0.1.2'
```

### Plug-in Roadmap
`WebSocket.Factory`
- [x] `OkHttpClient`
- [x] `MockHttpServer`

`MessageAdapter.Factory`
- [x] `moshi`
- [x] `gson`
- [x] `protobuf`
- [ ] `jackson`
- [ ] `simple-xml`

`StreamAdapter.Factory`
- [x] `RxJava2`
- [x] `RxJava1`
- [x] `Kotlin Coroutine`

`Lifecycle`
- [x] `AndroidLifecycle`

`BackoffStrategy`
- [x] `Linear`
- [x] `Exponential`
- [x] `ExponentialWithJitter`

Copyright
---
~~~
Expand Down Expand Up @@ -142,5 +150,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

[gdax-websocket-feed]: https://docs.gdax.com/#websocket-feed
[latest-jar]: https://tinder.jfrog.io/tinder/webapp/#/artifacts/browse/tree/General/libs-release-local/com/tinder/scarlet/scarlet
[demo-app]: https://github.com/Tinder/Scarlet/tree/master/demo/src/main/java/com/tinder/app
[demo-app]: /demo/src/main/java/com/tinder/app
[tutorial]: https://tech.gotinder.com/taming-websocket-with-scarlet/
[slides]: https://speakerdeck.com/zhxnlai/taming-websocket-with-scarlet
[kotliners]:https://www.conferenceforkotliners.com/
[jitpack]: https://jitpack.io/
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ ktlint {
subprojects {
apply plugin: 'org.kordamp.gradle.stats'
apply plugin: "com.jfrog.artifactory"
group = 'com.tinder.scarlet'
// group = 'com.tinder.scarlet' TODO use Bintray
group = 'com.github.tinder'

repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
~ © 2018 Match Group, LLC.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.api
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/java/com/tinder/app/echo/api/EchoService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.presenter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.target
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.echo.view
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/java/com/tinder/app/gdax/api/GdaxService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.api
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.api.model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.api.model
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/java/com/tinder/app/gdax/api/model/Ticker.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.api.model
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/java/com/tinder/app/gdax/domain/Product.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.domain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.inject
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/java/com/tinder/app/gdax/inject/GdaxScope.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.inject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.presenter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED
* © 2018 Match Group, LLC.
*/

package com.tinder.app.gdax.target
Expand Down
Loading

0 comments on commit ea3281d

Please sign in to comment.