Pure Scala library for interaction with Avatax APIs.
Project is split into following modules:
- core - Zero-dependency project - Scala ADT of data transfer objects. Based on docs & official sdk.
- client - akka-http + play-json client for AvaTax
- play-json - formats and derivation for AvaTax data types
Add following to your build.sbt
resolvers in Global += Resolver.url("upstartcommerce", url("https://upstartcommerce.bintray.com/generic"))(Resolver.ivyStylePatterns)
libraryDependencies += "org.upstartcommerce" %% "avataxsdk-client" % "0.0.8" // or whatever latest version is
// or if you want ONLY data model
// libraryDependencies += "org.upstartcommerce" %% "avataxsdk-core" % "0.0.8"
Basic usage is:
implicit val sys: ActorSystem = ActorSystem()
implicit val mat: ActorMaterializer = ActorMaterializer()
val client = AvataxClient(...)
/** request a result */
val valid = client.taxRates.byPostalCode("US", "35802")
val invalid = client.taxRates.byPostalCode("USUS", "123123123123")
val req:Future[Either[ErrorInfo, TaxRateModel]] = invalid().map(Right.apply).recover {
case AvataxException(ErrorResult(Some(e))) => Left(e)
}
/** stream by batch sizes of 50 */
val streamReq = client.definitions.listCurrencies(FiltrableQueryOptions().withTop(50)).stream
streamReq.runForeach(x => println(x))
See example
sub project for more examples.
There is a good reference for data model here
Please avoid blocking (awaiting) on futures from this api.
First full compilation will take a long time (+-10minutes) due to huge amount of api surface area - data types available, for which json has to be derived. Followup incremental compilations should be fast.
Currently, client is hardcoded to both akka-http and play-json. Especially with json we may swap it down the line (it's a separate module already).