aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-24 12:26:50 +0200
committeradamw <adam@warski.org>2017-07-24 12:26:50 +0200
commit986f6ff409b91230924508eafa7e4c077358dfed (patch)
treef665f48d6e99e8e0dd5c907638c2fda876a41641
parentccd2c4b1d53bf68e04ff1f8bca032d870494d9a8 (diff)
downloadsttp-986f6ff409b91230924508eafa7e4c077358dfed.tar.gz
sttp-986f6ff409b91230924508eafa7e4c077358dfed.tar.bz2
sttp-986f6ff409b91230924508eafa7e4c077358dfed.zip
Adding missing implicit EC to Future/AsyncHttpClient handler
-rw-r--r--README.md10
-rw-r--r--async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala23
-rw-r--r--async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala9
-rw-r--r--async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala15
-rw-r--r--tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala6
5 files changed, 44 insertions, 19 deletions
diff --git a/README.md b/README.md
index 415179a..c5ca897 100644
--- a/README.md
+++ b/README.md
@@ -274,19 +274,19 @@ dependency on `scalaz-concurrent`.
Next you'll need to add an implicit value:
```scala
-implicit val sttpHandler = new FutureAsyncHttpClientHandler()
+implicit val sttpHandler = FutureAsyncHttpClientHandler()
// or, if you're using the scalaz version:
-implicit val sttpHandler = new ScalazAsyncHttpClientHandler()
+implicit val sttpHandler = ScalazAsyncHttpClientHandler()
// or, if you're using the monix version:
-implicit val sttpHandler = new MonixAsyncHttpClientHandler()
+implicit val sttpHandler = MonixAsyncHttpClientHandler()
// or, if you'd like to use custom configuration:
-implicit val sttpHandler = new FutureAsyncHttpClientHandler(asyncHttpClientConfig)
+implicit val sttpHandler = FutureAsyncHttpClientHandler.usingConfig(asyncHttpClientConfig)
// or, if you'd like to instantiate the AsyncHttpClient yourself:
-implicit val sttpHandler = new FutureAsyncHttpClientHandler(asyncHttpClient)
+implicit val sttpHandler = FutureAsyncHttpClientHandler.usingClient(asyncHttpClient)
```
Streaming is not (yet) supported.
diff --git a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala b/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala
index 41fcf68..adc679e 100644
--- a/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala
+++ b/async-http-client-handler/future/src/main/scala/com/softwaremill/sttp/asynchttpclient/future/FutureAsyncHttpClientHandler.scala
@@ -12,12 +12,23 @@ import org.asynchttpclient.{
import scala.concurrent.{ExecutionContext, Future, Promise}
-class FutureAsyncHttpClientHandler(asyncHttpClient: AsyncHttpClient)(
- implicit ec: ExecutionContext = ExecutionContext.Implicits.global)
- extends AsyncHttpClientHandler[Future](asyncHttpClient, new FutureMonad()) {
-
- def this() = this(new DefaultAsyncHttpClient())
- def this(cfg: AsyncHttpClientConfig) = this(new DefaultAsyncHttpClient(cfg))
+class FutureAsyncHttpClientHandler private (asyncHttpClient: AsyncHttpClient)(
+ implicit ec: ExecutionContext)
+ extends AsyncHttpClientHandler[Future](asyncHttpClient, new FutureMonad())
+
+object FutureAsyncHttpClientHandler {
+ def apply()(
+ implicit ec: ExecutionContext = ExecutionContext.Implicits.global)
+ : FutureAsyncHttpClientHandler =
+ new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ def usingConfig(cfg: AsyncHttpClientConfig)(
+ implicit ec: ExecutionContext = ExecutionContext.Implicits.global)
+ : FutureAsyncHttpClientHandler =
+ new FutureAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ def usingClient(client: AsyncHttpClient)(implicit ec: ExecutionContext =
+ ExecutionContext.Implicits.global)
+ : FutureAsyncHttpClientHandler =
+ new FutureAsyncHttpClientHandler(client)
}
private[future] class FutureMonad(implicit ec: ExecutionContext)
diff --git a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala b/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala
index 30106f2..fab9c98 100644
--- a/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala
+++ b/async-http-client-handler/monix/src/main/scala/com/softwaremill/sttp/asynchttpclient/monix/MonixAsyncHttpClientHandler.scala
@@ -21,6 +21,15 @@ class MonixAsyncHttpClientHandler(asyncHttpClient: AsyncHttpClient)
def this(cfg: AsyncHttpClientConfig) = this(new DefaultAsyncHttpClient(cfg))
}
+object MonixAsyncHttpClientHandler {
+ def apply(): MonixAsyncHttpClientHandler =
+ new MonixAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ def usingConfig(cfg: AsyncHttpClientConfig): MonixAsyncHttpClientHandler =
+ new MonixAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ def usingClient(client: AsyncHttpClient): MonixAsyncHttpClientHandler =
+ new MonixAsyncHttpClientHandler(client)
+}
+
private[monix] object TaskMonad extends MonadAsyncError[Task] {
override def unit[T](t: T): Task[T] = Task.now(t)
diff --git a/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala b/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala
index 57d65c6..cb3bdef 100644
--- a/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala
+++ b/async-http-client-handler/scalaz/src/main/scala/com/softwaremill/sttp/asynchttpclient/scalaz/ScalazAsyncHttpClientHandler.scala
@@ -13,11 +13,16 @@ import org.asynchttpclient.{
import scalaz.{-\/, \/-}
import scalaz.concurrent.Task
-class ScalazAsyncHttpClientHandler(asyncHttpClient: AsyncHttpClient)
- extends AsyncHttpClientHandler[Task](asyncHttpClient, TaskMonad) {
-
- def this() = this(new DefaultAsyncHttpClient())
- def this(cfg: AsyncHttpClientConfig) = this(new DefaultAsyncHttpClient(cfg))
+class ScalazAsyncHttpClientHandler private (asyncHttpClient: AsyncHttpClient)
+ extends AsyncHttpClientHandler[Task](asyncHttpClient, TaskMonad)
+
+object ScalazAsyncHttpClientHandler {
+ def apply(): ScalazAsyncHttpClientHandler =
+ new ScalazAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ def usingConfig(cfg: AsyncHttpClientConfig): ScalazAsyncHttpClientHandler =
+ new ScalazAsyncHttpClientHandler(new DefaultAsyncHttpClient())
+ def usingClient(client: AsyncHttpClient): ScalazAsyncHttpClientHandler =
+ new ScalazAsyncHttpClientHandler(client)
}
private[scalaz] object TaskMonad extends MonadAsyncError[Task] {
diff --git a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
index 4e9c80e..00d9e6f 100644
--- a/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
+++ b/tests/src/test/scala/com/softwaremill/sttp/BasicTests.scala
@@ -119,11 +119,11 @@ class BasicTests
ForceWrappedValue.id)
runTests("Akka HTTP")(AkkaHttpSttpHandler.usingActorSystem(actorSystem),
ForceWrappedValue.future)
- runTests("Async Http Client - Future")(new FutureAsyncHttpClientHandler(),
+ runTests("Async Http Client - Future")(FutureAsyncHttpClientHandler(),
ForceWrappedValue.future)
- runTests("Async Http Client - Scalaz")(new ScalazAsyncHttpClientHandler(),
+ runTests("Async Http Client - Scalaz")(ScalazAsyncHttpClientHandler(),
ForceWrappedValue.scalazTask)
- runTests("Async Http Client - Monix")(new MonixAsyncHttpClientHandler(),
+ runTests("Async Http Client - Monix")(MonixAsyncHttpClientHandler(),
ForceWrappedValue.monixTask)
def runTests[R[_]](name: String)(