Skip to content

Commit

Permalink
New reformatter
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jul 19, 2017
1 parent b67b479 commit f6ab8cd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class AkkaHttpSttpHandler(actorSystem: ActorSystem)
}

private def methodToAkka(m: Method): HttpMethod = m match {
case Method.GET => HttpMethods.GET
case Method.HEAD => HttpMethods.HEAD
case Method.POST => HttpMethods.POST
case Method.PUT => HttpMethods.PUT
case Method.DELETE => HttpMethods.DELETE
case Method.GET => HttpMethods.GET
case Method.HEAD => HttpMethods.HEAD
case Method.POST => HttpMethods.POST
case Method.PUT => HttpMethods.PUT
case Method.DELETE => HttpMethods.DELETE
case Method.OPTIONS => HttpMethods.OPTIONS
case Method.PATCH => HttpMethods.PATCH
case Method.PATCH => HttpMethods.PATCH
case Method.CONNECT => HttpMethods.CONNECT
case Method.TRACE => HttpMethods.TRACE
case _ => HttpMethod.custom(m.m)
case Method.TRACE => HttpMethods.TRACE
case _ => HttpMethod.custom(m.m)
}

private def bodyFromAkka[T](rr: ResponseAs[T, S],
Expand Down Expand Up @@ -119,13 +119,13 @@ class AkkaHttpSttpHandler(actorSystem: ActorSystem)
.map(hc => ContentType.apply(ct.mediaType, () => hc))
.getOrElse(ct)
ar.withEntity(ctWithEncoding, b.getBytes(encoding))
case ByteArrayBody(b) => ar.withEntity(b)
case ByteArrayBody(b) => ar.withEntity(b)
case ByteBufferBody(b) => ar.withEntity(ByteString(b))
case InputStreamBody(b) =>
ar.withEntity(
HttpEntity(ct, StreamConverters.fromInputStream(() => b)))
case PathBody(b) => ar.withEntity(ct, b)
case StreamBody(s) => ar.withEntity(HttpEntity(ct, s))
case PathBody(b) => ar.withEntity(ct, b)
case StreamBody(s) => ar.withEntity(HttpEntity(ct, s))
case SerializableBody(f, t) => doSet(f(t))
}

Expand Down
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
lazy val commonSettings = Seq(
organization := "com.softwaremill.sttp",
version := "0.1",
version := "0.0.1",
scalaVersion := "2.12.2",
crossScalaVersions := Seq(scalaVersion.value, "2.11.8"),
scalacOptions ++= Seq("-unchecked", "-deprecation"),
scalafmtOnCompile := true,
scalafmtVersion := "1.0.0-RC2",
// Sonatype OSS deployment
publishTo := {
val nexus = "https://oss.sonatype.org/"
Expand Down Expand Up @@ -32,7 +33,7 @@ lazy val commonSettings = Seq(
</developer>
</developers>
),
licenses := ("Apache2",
licenses := ("Apache-2.0",
new java.net.URL(
"http://www.apache.org/licenses/LICENSE-2.0.txt")) :: Nil,
homepage := Some(new java.net.URL("http://softwaremill.com/open-source"))
Expand Down
76 changes: 38 additions & 38 deletions core/src/main/scala/com/softwaremill/sttp/UriInterpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ object UriInterpolator {

protected def parseE_asEncodedS_skipNone(e: Any): UriBuilder = e match {
case s: String => parseS(encode(s))
case None => this
case null => this
case Some(x) => parseE(x)
case x => parseS(encode(x.toString))
case None => this
case null => this
case Some(x) => parseE(x)
case x => parseS(encode(x.toString))
}
}

Expand Down Expand Up @@ -62,10 +62,10 @@ object UriInterpolator {

e match {
case s: String => parseS(encodeIfNotInitialEndpoint(s))
case None => this
case null => this
case Some(x) => parseE(x)
case x => parseS(encodeIfNotInitialEndpoint(x.toString))
case None => this
case null => this
case Some(x) => parseE(x)
case x => parseS(encodeIfNotInitialEndpoint(x.toString))
}
}

Expand Down Expand Up @@ -144,10 +144,10 @@ object UriInterpolator {
val newFragments = s.map(_.toString).map(encode(_)).map(Some(_))
newFragments.foldLeft(this)(_.appendE(_))
case s: String => appendE(Some(encode(s)))
case None => appendE(None)
case null => appendE(None)
case Some(x) => parseE(x)
case x => appendE(Some(encode(x.toString)))
case None => appendE(None)
case null => appendE(None)
case Some(x) => parseE(x)
case x => appendE(Some(encode(x.toString)))
}

override def build: String = {
Expand Down Expand Up @@ -201,40 +201,40 @@ object UriInterpolator {

override def parseE(e: Any): UriBuilder = e match {
case m: Map[_, _] => parseSeq(m.toSeq)
case s: Seq[_] => parseSeq(s)
case s: String => appendE(Some(encodeQuery(s)))
case None => appendE(None)
case null => appendE(None)
case Some(x) => parseE(x)
case x => appendE(Some(encodeQuery(x.toString)))
case s: Seq[_] => parseSeq(s)
case s: String => appendE(Some(encodeQuery(s)))
case None => appendE(None)
case null => appendE(None)
case Some(x) => parseE(x)
case x => appendE(Some(encodeQuery(x.toString)))
}

private def parseSeq(s: Seq[_]): UriBuilder = {
val flattenedS = s.flatMap {
case (_, None) => None
case (_, None) => None
case (k, Some(v)) => Some((k, v))
case None => None
case Some(k) => Some(k)
case x => Some(x)
case None => None
case Some(k) => Some(k)
case x => Some(x)
}
val newFragments = flattenedS.map {
case ("", "") => Eq
case (k, "") => K_Eq(encodeQuery(k))
case ("", v) => Eq_V(encodeQuery(v))
case (k, v) => K_Eq_V(encodeQuery(k), encodeQuery(v))
case x => K(encodeQuery(x))
case (k, "") => K_Eq(encodeQuery(k))
case ("", v) => Eq_V(encodeQuery(v))
case (k, v) => K_Eq_V(encodeQuery(k), encodeQuery(v))
case x => K(encodeQuery(x))
}
copy(fs = fs ++ newFragments)
}

override def build: String = {
val fragments = fs.flatMap {
case Empty => None
case Empty => None
case K_Eq_V(k, v) => Some(s"$k=$v")
case K_Eq(k) => Some(s"$k=")
case K(k) => Some(s"$k")
case Eq => Some("=")
case Eq_V(v) => Some(s"=$v")
case K_Eq(k) => Some(s"$k=")
case K(k) => Some(s"$k")
case Eq => Some("=")
case Eq_V(v) => Some(s"=$v")
}

val query = if (fragments.isEmpty) "" else "?" + fragments.mkString("&")
Expand All @@ -251,8 +251,8 @@ object UriInterpolator {
else
nv.split("=", 2) match {
case Array(n, "") => K_Eq(n)
case Array(n, v) => K_Eq_V(n, v)
case Array(n) => K(n)
case Array(n, v) => K_Eq_V(n, v)
case Array(n) => K(n)
}
}

Expand All @@ -270,7 +270,7 @@ object UriInterpolator {
}

val combinedVs = mergedOpt match {
case None => fs ++ newVs // either current or new fragments are empty
case None => fs ++ newVs // either current or new fragments are empty
case Some(merged) => merged
}

Expand All @@ -285,9 +285,9 @@ object UriInterpolator {
the form k=$v). Here we have to handle: $k=$v and $k=v.
*/
(last, first) match {
case (K(k), Eq) => Vector(K_Eq(k)) // k + = => k=
case (K(k), Eq) => Vector(K_Eq(k)) // k + = => k=
case (K(k), Eq_V(v)) => Vector(K_Eq_V(k, v)) // k + =v => k=v
case (x, y) => Vector(x, y)
case (x, y) => Vector(x, y)
}
}

Expand All @@ -296,9 +296,9 @@ object UriInterpolator {
case Some(K_Eq(k)) =>
// k= + None -> remove parameter; k= + Some(v) -> k=v
vo match {
case None => copy(fs = fs.init)
case None => copy(fs = fs.init)
case Some("") => this
case Some(v) => copy(fs = fs.init :+ K_Eq_V(k, v))
case Some(v) => copy(fs = fs.init :+ K_Eq_V(k, v))
}
case _ => copy(fs = fs :+ vo.fold[QueryFragment](Empty)(K))
}
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.7")
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.8")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC5")

0 comments on commit f6ab8cd

Please sign in to comment.