Skip to content

Commit

Permalink
Updates freestyle Build (#499)
Browse files Browse the repository at this point in the history
* Updates build

* Migrates hammock integration according to the latest version

* Releases freestyle 0.5.2
  • Loading branch information
juanpedromoreno authored Jan 10, 2018
1 parent c53d51e commit 1dbf75b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ lazy val core = module("core")
.crossDepSettings(
commonDeps ++ Seq(
%("cats-free"),
%("iota-core", "0.3.4"),
%("iota-core"),
%("simulacrum"),
%("shapeless") % "test",
%("cats-laws") % "test",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/main/tut/docs/http/hammock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import cats.effect.{Sync, IO}
import _root_.hammock._
import _root_.hammock.Uri._
import _root_.hammock.hi._
import _root_.hammock.jvm.free.Interpreter
import _root_.hammock.jvm.Interpreter
```

Expand Down Expand Up @@ -71,7 +71,7 @@ Also, you can lift any arbitrary `HttpRequestIO[F]` program to

```tut
implicit val interp = Interpreter[IO]
val response = Hammock.getWithOpts(Uri.unsafeParse("https://jsonplaceholder.typicode.com/posts/1"), Opts.default)
val response = Hammock.getWithOpts(Uri.unsafeParse("https://jsonplaceholder.typicode.com/posts/1"), Opts.empty)
HammockM[HammockM.Op].run(response).interpret[IO].unsafeRunSync
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package freestyle.free
package http

import _root_.hammock._
import _root_.hammock.free.algebra._
import _root_.hammock.free._
import cats.{MonadError, ~>}
import cats.effect.Sync
import cats.free.Free
Expand All @@ -32,11 +30,11 @@ object client {
def options(uri: Uri, headers: Map[String, String]): FS[HttpResponse]
def get(uri: Uri, headers: Map[String, String]): FS[HttpResponse]
def head(uri: Uri, headers: Map[String, String]): FS[HttpResponse]
def post(uri: Uri, headers: Map[String, String], body: Option[String]): FS[HttpResponse]
def put(uri: Uri, headers: Map[String, String], body: Option[String]): FS[HttpResponse]
def post(uri: Uri, headers: Map[String, String], body: Option[Entity]): FS[HttpResponse]
def put(uri: Uri, headers: Map[String, String], body: Option[Entity]): FS[HttpResponse]
def delete(uri: Uri, headers: Map[String, String]): FS[HttpResponse]
def trace(uri: Uri, headers: Map[String, String]): FS[HttpResponse]
def run[A](req: HttpRequestIO[A]): FS[A]
def run[A](req: Free[HttpF, A]): FS[A]
}

trait Implicits {
Expand All @@ -45,16 +43,16 @@ object client {
def options(uri: Uri, headers: Map[String, String]): M[HttpResponse] = Ops.options(uri, headers) foldMap I.trans
def get(uri: Uri, headers: Map[String, String]): M[HttpResponse] = Ops.get(uri, headers) foldMap I.trans
def head(uri: Uri, headers: Map[String, String]): M[HttpResponse] = Ops.head(uri, headers) foldMap I.trans
def post(uri: Uri, headers: Map[String, String], body: Option[String]): M[HttpResponse] = Ops.post(uri, headers, body) foldMap I.trans
def put(uri: Uri, headers: Map[String, String], body: Option[String]): M[HttpResponse] = Ops.put(uri, headers, body) foldMap I.trans
def post(uri: Uri, headers: Map[String, String], body: Option[Entity]): M[HttpResponse] = Ops.post(uri, headers, body) foldMap I.trans
def put(uri: Uri, headers: Map[String, String], body: Option[Entity]): M[HttpResponse] = Ops.put(uri, headers, body) foldMap I.trans
def delete(uri: Uri, headers: Map[String, String]): M[HttpResponse] = Ops.delete(uri, headers) foldMap I.trans
def trace(uri: Uri, headers: Map[String, String]): M[HttpResponse] = Ops.trace(uri, headers) foldMap I.trans
def run[A](req: HttpRequestIO[A]): M[A] = req foldMap I.trans
def run[A](req: Free[HttpF, A]): M[A] = req foldMap I.trans
}

implicit def freeSLiftHammock[F[_]: HammockM]: FreeSLift[F, HttpRequestIO] =
new FreeSLift[F, HttpRequestIO] {
def liftFSPar[A](hio: HttpRequestIO[A]): FreeS.Par[F, A] = HammockM[F].run(hio)
implicit def freeSLiftHammock[F[_]: HammockM]: FreeSLift[F, Free[HttpF, ?]] =
new FreeSLift[F, Free[HttpF, ?]] {
def liftFSPar[A](hio: Free[HttpF, A]): FreeS.Par[F, A] = HammockM[F].run(hio)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import cats.implicits._
import cats.effect._
import org.scalatest._
import _root_.hammock._
import _root_.hammock.free._
import _root_.hammock.free.algebra._

import freestyle.free.implicits._
import freestyle.free.http.client._
Expand All @@ -37,22 +35,22 @@ class ClientTests extends WordSpec with Matchers {

implicit val interp = new InterpTrans[IO] {

def trans(implicit S: Sync[IO]): HttpRequestF ~> IO = new (HttpRequestF ~> IO) {
def apply[A](req: HttpRequestF[A]): IO[A] = req match {
case req@Options(uri, headers) => doReq(req, Method.OPTIONS)(S)
case req@Get(uri, headers) => doReq(req, Method.GET)(S)
case req@Head(uri, headers) => doReq(req, Method.HEAD)(S)
case req@Post(uri, headers, body) => doReq(req, Method.POST)(S)
case req@Put(uri, headers, body) => doReq(req, Method.PUT)(S)
case req@Delete(uri, headers) => doReq(req, Method.DELETE)(S)
case req@Trace(uri, headers) => doReq(req, Method.TRACE)(S)
def trans(implicit S: Sync[IO]): HttpF ~> IO = new (HttpF ~> IO) {
def apply[A](req: HttpF[A]): IO[A] = req match {
case req@Options(uri) => doReq(uri, Method.OPTIONS)(S)
case req@Get(uri) => doReq(uri, Method.GET)(S)
case req@Head(uri) => doReq(uri, Method.HEAD)(S)
case req@Post(uri) => doReq(uri, Method.POST)(S)
case req@Put(uri) => doReq(uri, Method.PUT)(S)
case req@Delete(uri) => doReq(uri, Method.DELETE)(S)
case req@Trace(uri) => doReq(uri, Method.TRACE)(S)
}
}
}


private def doReq[F[_]](req: HttpRequestF[HttpResponse], method: Method)(implicit S: Sync[F]): F[HttpResponse] = S.catchNonFatal {
HttpResponse(Status.OK, Map(), s"got a $method request to ${req.uri.show}")
private def doReq[F[_]](req: HttpRequest, method: Method)(implicit S: Sync[F]): F[HttpResponse] = S.catchNonFatal {
HttpResponse(Status.OK, Map(), Entity.StringEntity(s"got a $method request to ${req.uri.show}"))
}

"Hammock integration" should {
Expand All @@ -66,16 +64,16 @@ class ClientTests extends WordSpec with Matchers {
("post", app.hammock.post(uri, headers, body)),
("put", app.hammock.put(uri, headers, body)),
("delete", app.hammock.delete(uri, headers)),
("trace", app.hammock.trace(uri, headers))) map {
("trace", app.hammock.trace(uri, headers))) foreach {
case (method, op) =>
s"allow the use of $method requests" in {
val program = for {
_ <- app.nonHammock.x
a <- op
content <- FreeS.pure(HttpResponse.content.get(a))
content <- FreeS.pure(HttpResponse.entity.get(a))
} yield content

program.interpret[IO].unsafeRunSync shouldEqual s"got a ${method.toUpperCase} request to ${uri.show}"
program.interpret[IO].unsafeRunSync shouldEqual Entity.StringEntity(s"got a ${method.toUpperCase} request to ${uri.show}")
}
}

Expand All @@ -84,30 +82,30 @@ class ClientTests extends WordSpec with Matchers {
val program = for {
a <- app.nonHammock.x
b <- app.hammock.run(Ops.get(Uri.unsafeParse("http://test.com"), Map()))
c <- FreeS.pure(HttpResponse.content.get(b))
} yield c
content <- FreeS.pure(HttpResponse.entity.get(b))
} yield content

program.interpret[IO].unsafeRunSync shouldEqual s"got a GET request to ${uri.show}"
program.interpret[IO].unsafeRunSync shouldEqual Entity.StringEntity(s"got a GET request to ${uri.show}")
}

"allow a HttpRequestIO program to be lifted to FreeS" in {
val program = for {
a <- app.nonHammock.x
b <- Ops.get(Uri.unsafeParse("http://test.com"), Map()).liftFS[App.Op]
c <- FreeS.pure(HttpResponse.content.get(b))
} yield c
content <- FreeS.pure(HttpResponse.entity.get(b))
} yield content

program.interpret[IO].unsafeRunSync shouldEqual s"got a GET request to ${uri.show}"
program.interpret[IO].unsafeRunSync shouldEqual Entity.StringEntity(s"got a GET request to ${uri.show}")
}

"allow a HttpRequestIO program to be lifted to FreeS.Par" in {
val program = for {
a <- app.nonHammock.x
b <- Ops.get(Uri.unsafeParse("http://test.com"), Map()).liftFSPar[App.Op].freeS
c <- FreeS.pure(HttpResponse.content.get(b))
} yield c
content <- FreeS.pure(HttpResponse.entity.get(b))
} yield content

program.interpret[IO].unsafeRunSync shouldEqual s"got a GET request to ${uri.show}"
program.interpret[IO].unsafeRunSync shouldEqual Entity.StringEntity(s"got a GET request to ${uri.show}")
}

}
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolvers += Resolver.sonatypeRepo("releases")

addSbtPlugin("io.frees" % "sbt-freestyle" % "0.3.14")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.0")
addSbtPlugin("io.frees" % "sbt-freestyle" % "0.3.15")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.1")
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.5.2-SNAPSHOT"
version in ThisBuild := "0.5.2"

0 comments on commit 1dbf75b

Please sign in to comment.