@@ -5,6 +5,7 @@ import com.azavea.stac4s.{StacCollection, StacItem}
55import cats .effect .{ConcurrentEffect , Resource , Sync }
66import cats .syntax .apply ._
77import cats .syntax .either ._
8+ import cats .syntax .flatMap ._
89import cats .syntax .functor ._
910import eu .timepit .refined .types .string .NonEmptyString
1011import io .chrisdavenport .log4cats .Logger
@@ -54,6 +55,26 @@ case class Http4sStacClient[F[_]: Sync: Logger](
5455 client
5556 .expect(getRequest.withUri(baseUri.withPath(s " /collections/ $collectionId/items/ $itemId" )))
5657 .map(_.as[Option [StacItem ]].bimap(_ => None , identity).merge)
58+
59+ def itemCreate (collectionId : NonEmptyString , item : StacItem ): F [StacItem ] =
60+ logger.trace(s " createItem: $collectionId, $item" ) *>
61+ client
62+ .expect(
63+ postRequest
64+ .withUri(baseUri.withPath(s " /collections/ $collectionId/items " ))
65+ .withEntity(item.asJson.noSpaces)
66+ )
67+ .flatMap { json => Sync [F ].fromEither(json.as[StacItem ].leftMap(_.getCause)) }
68+
69+ def collectionCreate (collection : StacCollection ): F [StacCollection ] =
70+ logger.trace(s " createCollection: $collection" ) *>
71+ client
72+ .expect(
73+ postRequest
74+ .withUri(baseUri.withPath(s " /collections/ " ))
75+ .withEntity(collection.asJson.noSpaces)
76+ )
77+ .flatMap { json => Sync [F ].fromEither(json.as[StacCollection ].leftMap(_.getCause)) }
5778}
5879
5980object Http4sStacClient {
0 commit comments