-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename BasetSttpClient => SttpStacClientF; modify pagination token co…
…decs
- Loading branch information
Showing
9 changed files
with
42 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
2 changes: 1 addition & 1 deletion
2
modules/client/js/src/main/scala/com/azavea/stac4s/api/client/package.scala
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.azavea.stac4s.api | ||
|
||
package object client { | ||
type SttpStacClient[F[_]] = BaseSttpStacClient.Aux[F, SearchFilters] | ||
type SttpStacClient[F[_]] = SttpStacClientF.Aux[F, SearchFilters] | ||
} |
This file contains 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 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
2 changes: 1 addition & 1 deletion
2
modules/client/jvm/src/main/scala/com/azavea/stac4s/api/client/client.scala
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.azavea.stac4s.api | ||
|
||
package object client { | ||
type SttpStacClient[F[_]] = BaseSttpStacClient.Aux[F, SearchFilters] | ||
type SttpStacClient[F[_]] = SttpStacClientF.Aux[F, SearchFilters] | ||
} |
This file contains 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
32 changes: 30 additions & 2 deletions
32
modules/client/shared/src/main/scala/com/azavea/stac4s/api/client/PaginationToken.scala
This file contains 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 |
---|---|---|
@@ -1,15 +1,43 @@ | ||
package com.azavea.stac4s.api.client | ||
|
||
import cats.syntax.either._ | ||
import eu.timepit.refined.types.numeric.PosInt | ||
import io.circe | ||
import io.circe.generic.semiauto._ | ||
import io.circe.parser.parse | ||
import io.circe.refined._ | ||
import io.circe.syntax._ | ||
import io.circe.{Decoder, Encoder} | ||
|
||
import java.time.Instant | ||
import java.util.Base64 | ||
|
||
final case class PaginationToken(timestampAtLeast: Instant, serialIdGreaterThan: PosInt) | ||
|
||
/** Circe codecs should encode token into a base64 string | ||
* https://github.com/azavea/franklin/blob/f5be8ddf48661c5bc43cbd22cb7277e961641803/application/src/main/scala/com/azavea/franklin/api/schemas/package.scala#L84-L85 | ||
*/ | ||
object PaginationToken { | ||
implicit val dec: Decoder[PaginationToken] = deriveDecoder | ||
implicit val enc: Encoder[PaginationToken] = deriveEncoder | ||
val b64Encoder = Base64.getEncoder | ||
val b64Decoder = Base64.getDecoder | ||
|
||
val defaultDecoder: Decoder[PaginationToken] = deriveDecoder | ||
val defaultEncoder: Encoder[PaginationToken] = deriveEncoder | ||
|
||
def encPaginationToken(token: PaginationToken): String = b64Encoder.encodeToString( | ||
token.asJson(defaultEncoder).noSpaces.getBytes | ||
) | ||
|
||
def decPaginationToken(encoded: String): Either[circe.Error, PaginationToken] = { | ||
val jsonString = new String(b64Decoder.decode(encoded)) | ||
for { | ||
js <- parse(jsonString) | ||
decoded <- js.as[PaginationToken](defaultDecoder) | ||
} yield decoded | ||
} | ||
|
||
implicit val dec: Decoder[PaginationToken] = | ||
Decoder.decodeString.emap(str => decPaginationToken(str).leftMap(_.getMessage)) | ||
|
||
implicit val enc: Encoder[PaginationToken] = { encPaginationToken(_).asJson } | ||
} |
This file contains 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 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