From 5a3d846bffb83e21635f56109e174f6e9603f18a Mon Sep 17 00:00:00 2001 From: Ahmad Ragab Date: Mon, 21 Aug 2023 21:10:53 -0400 Subject: [PATCH] Changes for 1.4 (#12) * initial dev branch * ignoring ci for some prs --- .github/workflows/ci.yml | 10 ++++------ .github/workflows/release.yml | 2 +- README.md | 3 ++- build.sbt | 4 +++- .../unstructured4s/Unstructured4s.scala | 7 ++++--- .../unstructured4s/Unstructured4sAlg.scala | 17 +++++++++++++++++ .../unstructured4s/examples/CatsEffectApp.scala | 2 +- .../unstructured4s/examples/ZIOApp.scala | 14 +++++++------- project/Dependencies.scala | 10 +++++----- src/main/paradox/getting-started.md | 14 ++++++++------ src/main/paradox/index.md | 4 ++-- src/main/paradox/making-requests.md | 4 ++++ src/main/paradox/responses.md | 2 +- version.sbt | 1 - 14 files changed, 59 insertions(+), 35 deletions(-) create mode 100644 core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4sAlg.scala delete mode 100644 version.sbt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa43093..c5faf9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,9 @@ name: ci on: pull_request: - types: - - assigned - - opened - - synchronize - - reopened + branches-ignore: + - main + - gh-pages concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -14,7 +12,7 @@ concurrency: jobs: ci: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 48195fc..768e960 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ permissions: jobs: publish: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 with: diff --git a/README.md b/README.md index 3003876..16bc8fb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) [![ci](https://github.com/ASRagab/unstructured4s/workflows/ci/badge.svg)](https://github.com/ASRagab/unstructured4s/actions) [![Maven Central](https://img.shields.io/maven-central/v/org.twelvehart/unstructured4s-core_3.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22org.twelvehart%22%20AND%20a:%22unstructured4s-core_3%22) -[![Scaladoc](https://javadoc.io/badge2/org.twelvehart/unstructured4s-core_3/javadoc.svg)](https://javadoc.io/doc/org.twelvehart/unstructured4s-core_3) +[![Sonatype Snapshots](https://img.shields.io/nexus/s/https/s01.oss.sonatype.org/org.twelvehart/unstructured4s-core_3.svg?label=Sonatype%20Snapshot)](https://s01.oss.sonatype.org/content/repositories/snapshots/org/twelvehart/unstructured4s-core_3) +[![Scaladoc](https://www.javadoc.io/badge/org.twelvehart/unstructured4s-core_3.svg)](https://javadoc.io/doc/org.twelvehart/unstructured4s-core_3) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) # unstructured4s diff --git a/build.sbt b/build.sbt index c51bbab..ece0b93 100644 --- a/build.sbt +++ b/build.sbt @@ -35,7 +35,9 @@ lazy val unstructured4s = (project in file(".")) uri("https://fosstodon.org/@traversable") ), Compile / paradoxProperties ++= Map( - "snip.core.base_dir" -> ((ThisBuild / baseDirectory).value / "core").getAbsolutePath + "snip.core.base_dir" -> ((ThisBuild / baseDirectory).value / "core").getAbsolutePath, + "sttp.version" -> V.sttp, + "zio_cats.version" -> V.zioCats ), paradox / sourceDirectory := sourceDirectory.value / "paradox", git.remoteRepo := scmInfo.value.get.connection.replace("scm:git:", ""), diff --git a/core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4s.scala b/core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4s.scala index aeba5e5..fbd4ec6 100644 --- a/core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4s.scala +++ b/core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4s.scala @@ -7,7 +7,8 @@ import sttp.client3.* import sttp.client3.circe.* import sttp.model.* -class Unstructured4s[F[_]: Functor, P](backend: SttpBackend[F, P], apiKey: ApiKey): +class Unstructured4s[F[_]: Functor, P](backend: SttpBackend[F, P], apiKey: ApiKey) + extends Unstructured4sAlg[F, PartitionResponse]: def partition( file: UnstructuredFile, request: Unstructured4sRequestFields = GeneralRequestFields(), @@ -55,8 +56,8 @@ class Unstructured4s[F[_]: Functor, P](backend: SttpBackend[F, P], apiKey: ApiKe end Unstructured4s object Unstructured4s: - def make[F[_]: Monad, P](backend: SttpBackend[F, P], apiKey: ApiKey): F[Unstructured4s[F, P]] = - summon[Monad[F]].pure(Unstructured4s(backend, apiKey)) + def make[F[_]: Functor, P](backend: SttpBackend[F, P], apiKey: ApiKey): Unstructured4s[F, P] = + Unstructured4s(backend, apiKey) def apiKeyHeader(apiKey: ApiKey): Header = Header("unstructured-api-key", apiKey) diff --git a/core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4sAlg.scala b/core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4sAlg.scala new file mode 100644 index 0000000..53262b7 --- /dev/null +++ b/core/src/main/scala/org/twelvehart/unstructured4s/Unstructured4sAlg.scala @@ -0,0 +1,17 @@ +package org.twelvehart.unstructured4s + +import org.twelvehart.unstructured4s.model.* +import sttp.model.* + +trait Unstructured4sAlg[F[_], A]: + def partition( + file: UnstructuredFile, + request: Unstructured4sRequestFields, + customHeaders: List[Header] + ): F[Unstructured4sResponse[A]] + + def partitionMultiple( + files: Seq[UnstructuredFile], + request: Unstructured4sRequestFields, + customHeaders: List[Header] + ): F[Unstructured4sResponse[List[A]]] diff --git a/examples/src/main/scala/org/twelvehart/unstructured4s/examples/CatsEffectApp.scala b/examples/src/main/scala/org/twelvehart/unstructured4s/examples/CatsEffectApp.scala index ef9f165..878f2a6 100644 --- a/examples/src/main/scala/org/twelvehart/unstructured4s/examples/CatsEffectApp.scala +++ b/examples/src/main/scala/org/twelvehart/unstructured4s/examples/CatsEffectApp.scala @@ -27,7 +27,7 @@ object CatsEffectApp extends IOApp.Simple: backendResource.use { backend => for apiKey <- IO.fromEither(apiKeyEnv) - client <- Unstructured4s.make(backend, ApiKey(apiKey)) + client = Unstructured4s.make(backend, ApiKey(apiKey)) file <- IO.fromEither(pdfEither) response <- client.partition(file, HiResRequestFields()) _ <- IO.println(response.result.bimap(_.getMessage, _.mkString("\n")).merge) diff --git a/examples/src/main/scala/org/twelvehart/unstructured4s/examples/ZIOApp.scala b/examples/src/main/scala/org/twelvehart/unstructured4s/examples/ZIOApp.scala index 87319cc..56b2770 100644 --- a/examples/src/main/scala/org/twelvehart/unstructured4s/examples/ZIOApp.scala +++ b/examples/src/main/scala/org/twelvehart/unstructured4s/examples/ZIOApp.scala @@ -30,13 +30,13 @@ object ZIOApp extends ZIOAppDefault: private def program: ZIO[SttpClient, Throwable, Unit] = ZIO.scoped { for - apiKey <- ZIO.fromEither(apiKeyEnv) - files <- ZIO.fromEither(filesEither) - backend <- ZIO.service[SttpClient] - unstructuredClient <- Unstructured4s.make(backend, ApiKey(apiKey)) - response <- unstructuredClient.partitionMultiple(files) - result = response.result.bimap(_.getMessage, _.mkString("\n")).merge - _ <- Console.printLine(result) + apiKey <- ZIO.fromEither(apiKeyEnv) + files <- ZIO.fromEither(filesEither) + backend <- ZIO.service[SttpClient] + unstructuredClient = Unstructured4s.make(backend, ApiKey(apiKey)) + response <- unstructuredClient.partitionMultiple(files) + result = response.result.bimap(_.getMessage, _.mkString("\n")).merge + _ <- Console.printLine(result) yield () } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 9d361e2..6faa826 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,9 +1,10 @@ import sbt.* object V { - lazy val zio = "2.0.15" - lazy val sttp = "3.9.0" - lazy val circe = "0.14.5" + lazy val zio = "2.0.15" + lazy val zioCats = "23.0.0.8" + lazy val sttp = "3.9.0" + lazy val circe = "0.14.5" } object Dependencies { @@ -26,12 +27,11 @@ object Dependencies { lazy val zioTest = "dev.zio" %% "zio-test" % V.zio lazy val zio = "dev.zio" %% "zio" % V.zio lazy val zioTestSbt = "dev.zio" %% "zio-test-sbt" % V.zio - lazy val zioCats = "dev.zio" %% "zio-interop-cats" % "23.0.0.8" + lazy val zioCats = "dev.zio" %% "zio-interop-cats" % V.zioCats lazy val zioSlf4j = "dev.zio" %% "zio-logging-slf4j" % "2.1.14" lazy val loggingFrontend = "ch.qos.logback" % "logback-classic" % "1.4.7" - lazy val core: Seq[ModuleID] = Seq( cats, catsEffect, diff --git a/src/main/paradox/getting-started.md b/src/main/paradox/getting-started.md index ee6a93f..01c8060 100644 --- a/src/main/paradox/getting-started.md +++ b/src/main/paradox/getting-started.md @@ -14,7 +14,7 @@ also be provided a separate apikey, which will override the default, when passed In addition to the `unstructured4s-core` module, you will need to provide an `sttp` backend, you can use any of the backends provided by [sttp] as long as you can provide a client with the effect capability `F[_]` that has a `Functor` instance (this will typical require some kind of -interoperability module with the `cats` typeclass hierarchy) +interoperability module with the `cats` typeclass hierarchy if you aren't using cats-effect) [sttp]: https://sttp.softwaremill.com/en/latest/backends/summary.html @@ -25,8 +25,8 @@ First obtain the necessary dependencies for sttp, here are the ones for `ZIO`: @@dependency[sbt,Maven,Gradle] { - group="com.softwaremill.sttp.client3" artifact="async-http-client-backend-zio_3" version="latest" - group2="dev.zio" artifact2="zio-interop-cats_3" version2="latest" + group="com.softwaremill.sttp.client3" artifact="async-http-client-backend-zio_3" version="$sttp.version$" + group2="dev.zio" artifact2="zio-interop-cats_3" version2="$zio_cats.version$" }
@@ -37,7 +37,7 @@ Here is the one for the `fs2` backend: @@dependency[sbt,Maven,Gradle] { group="com.softwaremill.sttp.client3" artifact="async-http-client-backend-fs2_3" - version="latest" + version="$sttp.version$" } @@ -76,7 +76,8 @@ object ZIOApp extends ZIOAppDefault { def program: ZIO[SttpClient, Throwable, Unit] = for { backend <- ZIO.service[SttpClient] - _ <- Unstructured4s.make(backend, ApiKey(apiKey)) + apiKey <- ZIO.fromEither(apiKeyEnv) + client = Unstructured4s.make(backend, ApiKey(apiKey)) } yield () } ``` @@ -110,7 +111,8 @@ object CatsEffectApp extends IOApp.Simple { override def run: IO[Unit] = backendResource.use { backend => for { - client <- Unstructured4s.make(backend, ApiKey(apiKey)) + apiKey <- IO.fromEither(apiKeyEnv) + client = Unstructured4s.make(backend, ApiKey(apiKey)) } yield () } ``` diff --git a/src/main/paradox/index.md b/src/main/paradox/index.md index 8498992..131443b 100644 --- a/src/main/paradox/index.md +++ b/src/main/paradox/index.md @@ -16,11 +16,11 @@ The library is published to [Sonatype] and [Maven Central].
-See the @link:[Unstructured4s Examples](https://github.com/ASRagab/unstructured4s/tree/main/examples/src/main/scala/org/twelvehart/unstructured4s/examples) { open=new } for an even quicker start. +See the @link:[Unstructured4s examples] { open=new } for an even quicker start. [Sonatype]: https://s01.oss.sonatype.org/content/repositories/releases/org/twelvehart/unstructured4s-core_3/ [Maven Central]: https://search.maven.org/artifact/org/twelvehart/unstructured4s-core_3 - +[Unstructured4s examples]: https://github.com/ASRagab/unstructured4s/tree/main/examples/src/main/scala/org/twelvehart/unstructured4s/examples @@@ index diff --git a/src/main/paradox/making-requests.md b/src/main/paradox/making-requests.md index 3412a43..1b3ec13 100644 --- a/src/main/paradox/making-requests.md +++ b/src/main/paradox/making-requests.md @@ -21,11 +21,15 @@ A hopefully sensible default with all necessary parameters for each is provided
+### `GeneralRequestFields` + @@snip [domain.scala]($core$/src/main/scala/org/twelvehart/unstructured4s/model/domain.scala) { #general_request_fields }
+### `HiResRequestFields` + @@snip [domain.scala]($core$/src/main/scala/org/twelvehart/unstructured4s/model/domain.scala) { #hires_request_fields }
diff --git a/src/main/paradox/responses.md b/src/main/paradox/responses.md index 855c589..2c5fa03 100644 --- a/src/main/paradox/responses.md +++ b/src/main/paradox/responses.md @@ -29,7 +29,7 @@ which depends on whether you called `partition` or `partitionMultiple` respectiv There exists an implicit conversion between this error type and `ResponseException[String, io.circe.Error]` which is error return type from `sttp` there are two kinds of `Unstructured4sError`s -* `JsonParsingError` - This is returned when the response from the [Unstructured] is not valid json. +* `JsonParsingError` - This is returned when the response from [Unstructured] is not valid json. * `HttpResponseError` - This is returned when the response is not `200 OK`. diff --git a/version.sbt b/version.sbt deleted file mode 100644 index 8b13789..0000000 --- a/version.sbt +++ /dev/null @@ -1 +0,0 @@ -