/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/natalia/foursquare/0.0.1-dev/http4s_0_20 */ package natalia.foursquare.v0.server import org.http4s.circe.decodeUri import org.http4s.circe.encodeUri import org.http4s.dsl.{io => _, _} import org.http4s.implicits._ import cats.effect._ import cats.implicits._ import natalia.foursquare.v0.models.json._ private[server] trait Matchers[F[_]] extends Http4sDsl[F] { implicit lazy val queryParamDecodeBigDecimal: org.http4s.QueryParamDecoder[BigDecimal] = org.http4s.QueryParamDecoder.fromUnsafeCast[BigDecimal](p => BigDecimal(p.value))("BigDecimal") implicit lazy val queryParamDecodeInstant: org.http4s.QueryParamDecoder[_root_.java.time.Instant] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.time.Instant](p => _root_.java.time.OffsetDateTime.parse(p.value).toInstant)("_root_.java.time.Instant") implicit lazy val queryParamDecodeLocalDate: org.http4s.QueryParamDecoder[_root_.java.time.LocalDate] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.time.LocalDate](p => _root_.java.time.LocalDate.parse(p.value))("_root_.java.time.LocalDate") implicit lazy val queryParamDecodeUUID: org.http4s.QueryParamDecoder[_root_.java.util.UUID] = org.http4s.QueryParamDecoder.fromUnsafeCast[_root_.java.util.UUID](p => _root_.java.util.UUID.fromString(p.value))("_root_.java.util.UUID") object ApiVersion { val ApiVersionMajor = { "X-Apidoc-Version-Major".ci } def apply(req: org.http4s.Message[F]): Boolean = req.headers.get(ApiVersionMajor) match { case Some(v) if v.value == "0" => true case _ => false } } object ClientIdStringMatcher extends QueryParamDecoderMatcher[String]("client_id") object ClientSecretStringMatcher extends QueryParamDecoderMatcher[String]("client_secret") object NearStringMatcher extends QueryParamDecoderMatcher[String]("near") object QueryStringMatcher extends QueryParamDecoderMatcher[String]("query") object VStringMatcher extends QueryParamDecoderMatcher[String]("v") } trait VenueRoutes[F[_]] extends Matchers[F] { implicit def circeJsonDecoder[A](implicit decoder: _root_.io.circe.Decoder[A], sync: Sync[F]) = org.http4s.circe.jsonOf[F, A] implicit def circeJsonEncoder[A](implicit encoder: _root_.io.circe.Encoder[A], sync: Sync[F]) = org.http4s.circe.jsonEncoderOf[F, A] sealed trait GetExploreResponse object GetExploreResponse { case class HTTP200(value: natalia.foursquare.v0.models.VenueExploreResponseWrapper, headers: Seq[org.http4s.Header] = Nil) extends GetExploreResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends GetExploreResponse } def getExplore( _req: org.http4s.Request[F], clientId: String, clientSecret: String, v: String, near: String, query: String ): F[GetExploreResponse] sealed trait GetByVenueIdResponse object GetByVenueIdResponse { case class HTTP200(value: natalia.foursquare.v0.models.VenueDetailsResponseWrapper, headers: Seq[org.http4s.Header] = Nil) extends GetByVenueIdResponse case class UndocumentedResponse(response: F[org.http4s.Response[F]]) extends GetByVenueIdResponse } def getByVenueId( _req: org.http4s.Request[F], venueId: String, clientId: String, clientSecret: String, v: String ): F[GetByVenueIdResponse] def apiVersionMatch(req: org.http4s.Message[F]): Boolean = ApiVersion(req) def service()(implicit sync: Sync[F]) = org.http4s.HttpRoutes.of[F] { case _req @ GET -> Root / "venues" / "explore" :? ClientIdStringMatcher(clientId) +& ClientSecretStringMatcher(clientSecret) +& VStringMatcher(v) +& NearStringMatcher(near) +& QueryStringMatcher(query) if apiVersionMatch(_req) => getExplore(_req, clientId, clientSecret, v, near, query).flatMap { case GetExploreResponse.HTTP200(value, headers) => Ok(value, headers: _*) case GetExploreResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "venues" / "explore" :? ClientIdStringMatcher(clientId) +& ClientSecretStringMatcher(clientSecret) +& VStringMatcher(v) +& NearStringMatcher(near) +& QueryStringMatcher(query) if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") case _req @ GET -> Root / "venues" / venueId :? ClientIdStringMatcher(clientId) +& ClientSecretStringMatcher(clientSecret) +& VStringMatcher(v) if apiVersionMatch(_req) => getByVenueId(_req, venueId, clientId, clientSecret, v).flatMap { case GetByVenueIdResponse.HTTP200(value, headers) => Ok(value, headers: _*) case GetByVenueIdResponse.UndocumentedResponse(response) => response } case _req @ GET -> Root / "venues" / venueId :? ClientIdStringMatcher(clientId) +& ClientSecretStringMatcher(clientSecret) +& VStringMatcher(v) if !_req.headers.get(ApiVersion.ApiVersionMajor).isDefined => BadRequest(s"Missing required request header: ${ApiVersion.ApiVersionMajor}.") } }