aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-07-24 17:46:34 +0200
committeradamw <adam@warski.org>2017-07-24 17:46:34 +0200
commit8e2e4d0e93c33b61ec7aae3edb992400f77d51a3 (patch)
tree269aad3e397145b39956038229dc5ee28e3547a9
parent0299feaebb4b72bbcfc62af23ced1f297cf26294 (diff)
downloadsttp-8e2e4d0e93c33b61ec7aae3edb992400f77d51a3.tar.gz
sttp-8e2e4d0e93c33b61ec7aae3edb992400f77d51a3.tar.bz2
sttp-8e2e4d0e93c33b61ec7aae3edb992400f77d51a3.zip
Splitting the model package into files, adding Xlint to compiler options
-rw-r--r--akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala3
-rw-r--r--build.sbt2
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/RequestT.scala2
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/model/Method.scala14
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/model/RequestBody.scala21
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala41
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/model/package.scala81
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/package.scala9
8 files changed, 87 insertions, 86 deletions
diff --git a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala
index f0262fc..e4b2bf6 100644
--- a/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala
+++ b/akka-http-handler/src/main/scala/com/softwaremill/sttp/akkahttp/AkkaHttpSttpHandler.scala
@@ -2,7 +2,7 @@ package com.softwaremill.sttp.akkahttp
import java.io.UnsupportedEncodingException
-import akka.actor.{ActorSystem, Terminated}
+import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.coding.{Deflate, Gzip, NoCoding}
import akka.http.scaladsl.model.HttpHeader.ParsingResult
@@ -174,7 +174,6 @@ class AkkaHttpSttpHandler private (actorSystem: ActorSystem,
}
override def close(): Unit = {
- implicit val ec = this.ec
if (terminateActorSystemOnClose) actorSystem.terminate()
}
diff --git a/build.sbt b/build.sbt
index d2d3dc7..803c072 100644
--- a/build.sbt
+++ b/build.sbt
@@ -3,7 +3,7 @@ val commonSettings = Seq(
version := "0.0.2",
scalaVersion := "2.12.2",
crossScalaVersions := Seq(scalaVersion.value, "2.11.8"),
- scalacOptions ++= Seq("-unchecked", "-deprecation"),
+ scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-Xlint"),
scalafmtOnCompile := true,
scalafmtVersion := "1.0.0",
releaseEarlyWith := SonatypePublisher,
diff --git a/core/src/main/scala/com/softwaremill/sttp/RequestT.scala b/core/src/main/scala/com/softwaremill/sttp/RequestT.scala
index be257dd..1aa8770 100644
--- a/core/src/main/scala/com/softwaremill/sttp/RequestT.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/RequestT.scala
@@ -10,6 +10,8 @@ import com.softwaremill.sttp.model._
import scala.collection.immutable.Seq
+import scala.language.higherKinds
+
/**
* @tparam U Specifies if the method & uri are specified. By default can be
* either:
diff --git a/core/src/main/scala/com/softwaremill/sttp/model/Method.scala b/core/src/main/scala/com/softwaremill/sttp/model/Method.scala
new file mode 100644
index 0000000..6f2ea68
--- /dev/null
+++ b/core/src/main/scala/com/softwaremill/sttp/model/Method.scala
@@ -0,0 +1,14 @@
+package com.softwaremill.sttp.model
+
+case class Method(m: String) extends AnyVal
+object Method {
+ val GET = Method("GET")
+ val HEAD = Method("HEAD")
+ val POST = Method("POST")
+ val PUT = Method("PUT")
+ val DELETE = Method("DELETE")
+ val OPTIONS = Method("OPTIONS")
+ val PATCH = Method("PATCH")
+ val CONNECT = Method("CONNECT")
+ val TRACE = Method("TRACE")
+}
diff --git a/core/src/main/scala/com/softwaremill/sttp/model/RequestBody.scala b/core/src/main/scala/com/softwaremill/sttp/model/RequestBody.scala
new file mode 100644
index 0000000..0c737f0
--- /dev/null
+++ b/core/src/main/scala/com/softwaremill/sttp/model/RequestBody.scala
@@ -0,0 +1,21 @@
+package com.softwaremill.sttp.model
+
+import java.io.InputStream
+import java.nio.ByteBuffer
+import java.nio.file.Path
+
+import com.softwaremill.sttp.BodySerializer
+
+sealed trait RequestBody[+S]
+case object NoBody extends RequestBody[Nothing]
+case class SerializableBody[T](f: BodySerializer[T], t: T)
+ extends RequestBody[Nothing]
+
+sealed trait BasicRequestBody extends RequestBody[Nothing]
+case class StringBody(s: String, encoding: String) extends BasicRequestBody
+case class ByteArrayBody(b: Array[Byte]) extends BasicRequestBody
+case class ByteBufferBody(b: ByteBuffer) extends BasicRequestBody
+case class InputStreamBody(b: InputStream) extends BasicRequestBody
+case class PathBody(f: Path) extends BasicRequestBody
+
+case class StreamBody[S](s: S) extends RequestBody[S]
diff --git a/core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala b/core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala
new file mode 100644
index 0000000..4724292
--- /dev/null
+++ b/core/src/main/scala/com/softwaremill/sttp/model/ResponseAs.scala
@@ -0,0 +1,41 @@
+package com.softwaremill.sttp.model
+
+import java.net.URLDecoder
+
+import scala.collection.immutable.Seq
+
+/**
+ * @tparam T Target type as which the response will be read.
+ * @tparam S If `T` is a stream, the type of the stream. Otherwise, `Nothing`.
+ */
+sealed trait ResponseAs[T, +S] {
+ def map[T2](f: T => T2): ResponseAs[T2, S] =
+ MappedResponseAs[T, T2, S](this, f)
+}
+
+case object IgnoreResponse extends ResponseAs[Unit, Nothing]
+case class ResponseAsString(encoding: String)
+ extends ResponseAs[String, Nothing]
+case object ResponseAsByteArray extends ResponseAs[Array[Byte], Nothing]
+case class ResponseAsParams(encoding: String)
+ extends ResponseAs[Seq[(String, String)], Nothing] {
+
+ private[sttp] def parse(s: String): Seq[(String, String)] = {
+ s.split("&")
+ .toList
+ .flatMap(kv =>
+ kv.split("=", 2) match {
+ case Array(k, v) =>
+ Some(
+ (URLDecoder.decode(k, encoding), URLDecoder.decode(v, encoding)))
+ case _ => None
+ })
+ }
+}
+case class ResponseAsStream[T, S]()(implicit val responseIsStream: S =:= T)
+ extends ResponseAs[T, S]
+case class MappedResponseAs[T, T2, S](raw: ResponseAs[T, S], g: T => T2)
+ extends ResponseAs[T2, S] {
+ override def map[T3](f: T2 => T3): ResponseAs[T3, S] =
+ MappedResponseAs[T, T3, S](raw, g andThen f)
+}
diff --git a/core/src/main/scala/com/softwaremill/sttp/model/package.scala b/core/src/main/scala/com/softwaremill/sttp/model/package.scala
deleted file mode 100644
index e0b4048..0000000
--- a/core/src/main/scala/com/softwaremill/sttp/model/package.scala
+++ /dev/null
@@ -1,81 +0,0 @@
-package com.softwaremill.sttp
-
-import java.io.InputStream
-import java.net.URLDecoder
-import java.nio.ByteBuffer
-import java.nio.file.Path
-
-import scala.language.higherKinds
-import scala.collection.immutable.Seq
-
-package object model {
- case class Method(m: String) extends AnyVal
- object Method {
- val GET = Method("GET")
- val HEAD = Method("HEAD")
- val POST = Method("POST")
- val PUT = Method("PUT")
- val DELETE = Method("DELETE")
- val OPTIONS = Method("OPTIONS")
- val PATCH = Method("PATCH")
- val CONNECT = Method("CONNECT")
- val TRACE = Method("TRACE")
- }
-
- /**
- * Provide an implicit value of this type to serialize arbitrary classes into a request body.
- * Handlers might also provide special logic for serializer instances which they define (e.g. to handle streaming).
- */
- type BodySerializer[B] = B => BasicRequestBody
-
- sealed trait RequestBody[+S]
- case object NoBody extends RequestBody[Nothing]
- case class SerializableBody[T](f: BodySerializer[T], t: T)
- extends RequestBody[Nothing]
-
- sealed trait BasicRequestBody extends RequestBody[Nothing]
- case class StringBody(s: String, encoding: String) extends BasicRequestBody
- case class ByteArrayBody(b: Array[Byte]) extends BasicRequestBody
- case class ByteBufferBody(b: ByteBuffer) extends BasicRequestBody
- case class InputStreamBody(b: InputStream) extends BasicRequestBody
- case class PathBody(f: Path) extends BasicRequestBody
-
- case class StreamBody[S](s: S) extends RequestBody[S]
-
- /**
- * @tparam T Target type as which the response will be read.
- * @tparam S If `T` is a stream, the type of the stream. Otherwise, `Nothing`.
- */
- sealed trait ResponseAs[T, +S] {
- def map[T2](f: T => T2): ResponseAs[T2, S] =
- MappedResponseAs[T, T2, S](this, f)
- }
-
- case object IgnoreResponse extends ResponseAs[Unit, Nothing]
- case class ResponseAsString(encoding: String)
- extends ResponseAs[String, Nothing]
- case object ResponseAsByteArray extends ResponseAs[Array[Byte], Nothing]
- case class ResponseAsParams(encoding: String)
- extends ResponseAs[Seq[(String, String)], Nothing] {
-
- private[sttp] def parse(s: String): Seq[(String, String)] = {
- s.split("&")
- .toList
- .flatMap(kv =>
- kv.split("=", 2) match {
- case Array(k, v) =>
- Some(
- (URLDecoder.decode(k, encoding),
- URLDecoder.decode(v, encoding)))
- case _ => None
- })
- }
- }
- case class ResponseAsStream[T, S]()(implicit val responseIsStream: S =:= T)
- extends ResponseAs[T, S]
- case class MappedResponseAs[T, T2, S](raw: ResponseAs[T, S], g: T => T2)
- extends ResponseAs[T2, S] {
- override def map[T3](f: T2 => T3): ResponseAs[T3, S] =
- MappedResponseAs[T, T3, S](raw, g andThen f)
- }
-}
diff --git a/core/src/main/scala/com/softwaremill/sttp/package.scala b/core/src/main/scala/com/softwaremill/sttp/package.scala
index ccc79ac..5e7b13c 100644
--- a/core/src/main/scala/com/softwaremill/sttp/package.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/package.scala
@@ -1,10 +1,9 @@
package com.softwaremill
import java.io.{File, InputStream}
-import java.net.{URI, URLEncoder}
+import java.net.URI
import java.nio.ByteBuffer
import java.nio.file.Path
-import java.util.Base64
import com.softwaremill.sttp.model._
@@ -24,6 +23,12 @@ package object sttp {
".get(...), .post(...) etc. to obtain a non-partial request.")
private[sttp] type IsIdInRequest[U[_]] = U[Unit] =:= Id[Unit]
+ /**
+ * Provide an implicit value of this type to serialize arbitrary classes into a request body.
+ * Handlers might also provide special logic for serializer instances which they define (e.g. to handle streaming).
+ */
+ type BodySerializer[B] = B => BasicRequestBody
+
// constants
private[sttp] val ContentTypeHeader = "Content-Type"