-
Notifications
You must be signed in to change notification settings - Fork 9
Сlient module #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Сlient module #140
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
7d1c22b
Add a client module
pomadchin c6562af
Add Query from Franklin
pomadchin 7630412
Upd up to the main branch
pomadchin 31a0bf0
Add item and collection creation endpoints
pomadchin c732bae
Move to sttp client to have some layer of abstraction over the client…
pomadchin be07703
Add ClientJS
pomadchin 739912d
Formatting
pomadchin 7a275a2
Generate STAC Client specs
pomadchin ed8fda8
Code cleanup
pomadchin 46d9c57
Configure sbt
pomadchin 0469396
Close sttp client in tests
pomadchin 8821a2f
Tune CircleCI
pomadchin f060644
Tune SBT
pomadchin c44cffc
Move StacClient into a shared dir
pomadchin 1d8a5f8
Add more tests
pomadchin 0647db7
Remove log4cats from specs
pomadchin 2733d69
Move BaseSttpStacClient into shared folder
pomadchin 7377a3f
Try to limit JS mem usage
pomadchin 990ad20
Remove unnecessary dep
pomadchin d587f46
Make JS tests more tiny
pomadchin fdee543
Give 2g to the JVM
pomadchin 7f6abce
polygons => multipolygons
pomadchin 1d83880
Address review comments
pomadchin baa5c6c
Simplify and unify client specs
pomadchin 30123e3
Add convenient types
pomadchin 6d2ab01
Consolidate tests
pomadchin c708009
Rename BasetSttpClient => SttpStacClientF; modify pagination token co…
pomadchin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
modules/client/js/src/main/scala/com/azavea/stac4s/api/client/SearchFilters.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.azavea.stac4s.api.client | ||
jisantuc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import com.azavea.stac4s.Bbox | ||
| import com.azavea.stac4s.api.client.utils.ClientCodecs | ||
| import com.azavea.stac4s.geometry.Geometry | ||
| import com.azavea.stac4s.types.TemporalExtent | ||
|
|
||
| import eu.timepit.refined.types.numeric.NonNegInt | ||
| import io.circe._ | ||
| import io.circe.generic.semiauto._ | ||
| import io.circe.refined._ | ||
|
|
||
| case class SearchFilters( | ||
| bbox: Option[Bbox] = None, | ||
| datetime: Option[TemporalExtent] = None, | ||
| intersects: Option[Geometry] = None, | ||
| collections: List[String] = Nil, | ||
| items: List[String] = Nil, | ||
| limit: Option[NonNegInt] = None, | ||
| query: Map[String, List[Query]] = Map.empty, | ||
| next: Option[PaginationToken] = None | ||
| ) | ||
|
|
||
| object SearchFilters extends ClientCodecs { | ||
|
|
||
| implicit val searchFilterDecoder: Decoder[SearchFilters] = { c => | ||
| for { | ||
| bbox <- c.downField("bbox").as[Option[Bbox]] | ||
| datetime <- c.downField("datetime").as[Option[TemporalExtent]] | ||
| intersects <- c.downField("intersects").as[Option[Geometry]] | ||
| collectionsOption <- c.downField("collections").as[Option[List[String]]] | ||
| itemsOption <- c.downField("items").as[Option[List[String]]] | ||
| limit <- c.downField("limit").as[Option[NonNegInt]] | ||
| query <- c.get[Option[Map[String, List[Query]]]]("query") | ||
| paginationToken <- c.get[Option[PaginationToken]]("next") | ||
| } yield { | ||
| SearchFilters( | ||
| bbox, | ||
| datetime, | ||
| intersects, | ||
| collectionsOption.getOrElse(Nil), | ||
| itemsOption.getOrElse(Nil), | ||
| limit, | ||
| query getOrElse Map.empty, | ||
| paginationToken | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| implicit val searchFilterEncoder: Encoder[SearchFilters] = deriveEncoder | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
modules/client/js/src/main/scala/com/azavea/stac4s/api/client/SttpStacClient.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.azavea.stac4s.api.client | ||
|
|
||
| import cats.MonadError | ||
| import sttp.client3.SttpBackend | ||
| import sttp.model.Uri | ||
|
|
||
| object SttpStacClient { | ||
|
|
||
| def apply[F[_]: MonadError[*[_], Throwable]]( | ||
| client: SttpBackend[F, Any], | ||
| baseUri: Uri | ||
| ): BaseSttpStacClient.Aux[F, SearchFilters] = | ||
| BaseSttpStacClient.instance[F, SearchFilters](client, baseUri) | ||
| } |
111 changes: 111 additions & 0 deletions
111
modules/client/js/src/test/scala/com/azavea/stac4s/api/client/StacClientSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package com.azavea.stac4s.api.client | ||
|
|
||
| import com.azavea.stac4s.testing.JsInstances | ||
|
|
||
| import cats.syntax.either._ | ||
| import eu.timepit.refined.types.all.NonEmptyString | ||
| import io.circe.JsonObject | ||
| import io.circe.syntax._ | ||
| import org.scalatest.BeforeAndAfterAll | ||
| import org.scalatest.funspec.AnyFunSpec | ||
| import org.scalatest.matchers.should.Matchers | ||
| import sttp.client3.testing.SttpBackendStub | ||
| import sttp.client3.{Response, UriContext} | ||
| import sttp.model.Method | ||
| import sttp.monad.EitherMonad | ||
|
|
||
| class StacClientSpec extends AnyFunSpec with Matchers with JsInstances with BeforeAndAfterAll { | ||
|
|
||
| lazy val backend = | ||
| SttpBackendStub(EitherMonad) | ||
| .whenRequestMatches(_.uri.path == Seq("search")) | ||
| .thenRespondF { _ => | ||
| Response | ||
| .ok(arbItemCollectionShort.arbitrary.sample.asJson.asRight) | ||
| .asRight | ||
| } | ||
| .whenRequestMatches { | ||
| case req if req.method == Method.GET => req.uri.path == Seq("collections") | ||
| case _ => false | ||
| } | ||
| .thenRespondF { _ => | ||
| Response | ||
| .ok(JsonObject("collections" -> arbCollectionShort.arbitrary.sample.toList.asJson).asJson.asRight) | ||
pomadchin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .asRight | ||
| } | ||
| .whenRequestMatches { | ||
| case req if req.method == Method.GET => req.uri.path == Seq("collections", "collection_id", "items") | ||
| case _ => false | ||
| } | ||
| .thenRespondF { _ => | ||
| Response | ||
| .ok(arbItemCollectionShort.arbitrary.sample.asJson.asRight) | ||
| .asRight | ||
| } | ||
| .whenRequestMatches(_.uri.path == Seq("collections", "collection_id", "items", "item_id")) | ||
| .thenRespondF { _ => | ||
| Response | ||
| .ok(arbItemShort.arbitrary.sample.asRight) | ||
| .asRight | ||
| } | ||
| .whenRequestMatches { | ||
| case req if req.method == Method.POST => req.uri.path == Seq("collections", "collection_id", "items") | ||
| case _ => false | ||
| } | ||
| .thenRespondF { _ => | ||
| Response | ||
| .ok(arbItemShort.arbitrary.sample.get.asRight) | ||
| .asRight | ||
| } | ||
| .whenRequestMatches { | ||
| case req if req.method == Method.POST => req.uri.path == Seq("collections") | ||
| case _ => false | ||
| } | ||
| .thenRespondF { _ => | ||
| Response | ||
| .ok(arbCollectionShort.arbitrary.sample.get.asRight) | ||
| .asRight | ||
| } | ||
|
|
||
| describe("StacClientSpec") { | ||
| it("search") { | ||
| SttpStacClient(backend, uri"http://localhost:9090").search | ||
| .valueOr(throw _) | ||
| .size should be > 0 | ||
| } | ||
|
|
||
| it("collections") { | ||
| SttpStacClient(backend, uri"http://localhost:9090").collections | ||
| .valueOr(throw _) | ||
| .size should be > 0 | ||
| } | ||
|
|
||
| it("items") { | ||
| SttpStacClient(backend, uri"http://localhost:9090") | ||
| .items(NonEmptyString.unsafeFrom("collection_id")) | ||
| .valueOr(throw _) | ||
| .size should be > 0 | ||
| } | ||
|
|
||
| it("item") { | ||
| SttpStacClient(backend, uri"http://localhost:9090") | ||
| .item(NonEmptyString.unsafeFrom("collection_id"), NonEmptyString.unsafeFrom("item_id")) | ||
| .valueOr(throw _) | ||
| .size should be > 0 | ||
| } | ||
|
|
||
| it("itemCreate") { | ||
| SttpStacClient(backend, uri"http://localhost:9090") | ||
| .itemCreate(NonEmptyString.unsafeFrom("collection_id"), arbItemShort.arbitrary.sample.get) | ||
| .map(_.id should not be empty) | ||
| } | ||
|
|
||
| it("collectionCreate") { | ||
| SttpStacClient(backend, uri"http://localhost:9090") | ||
| .collectionCreate(arbCollectionShort.arbitrary.sample.get) | ||
| .map(_.id should not be empty) | ||
| } | ||
| } | ||
|
|
||
| override def afterAll(): Unit = backend.close().valueOr(throw _) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.