Skip to content

Pure Scala non-blocking (and streaming) client for Avatax

License

Notifications You must be signed in to change notification settings

upstart-commerce/avataxsdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Avatax Client

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 - client interface
  • client-akka - akka-http + play-json client for AvaTax
  • client-pekko - pekko-http + play-json client for AvaTax
  • play-json - formats and derivation for AvaTax data types

Installation

Add following to your build.sbt

  • akka
Global / resolvers += Resolver.url("upstartcommerce", url("https://upstartcommerce.jfrog.io/artifactory/nochannel"))(Resolver.ivyStylePatterns)

libraryDependencies += "org.upstartcommerce" %% "avataxsdk-client-akka" % "0.1.0" // or whatever latest version is
  • pekko
Global / resolvers += Resolver.url("upstartcommerce", url("https://upstartcommerce.jfrog.io/artifactory/nochannel"))(Resolver.ivyStylePatterns)

libraryDependencies += "org.upstartcommerce" %% "avataxsdk-client-pekko" % "0.1.0" // or whatever latest version is
  • core/data model only
Global / resolvers += Resolver.url("upstartcommerce", url("https://upstartcommerce.jfrog.io/artifactory/nochannel"))(Resolver.ivyStylePatterns)

libraryDependencies += "org.upstartcommerce" %% "avataxsdk-core" % "0.1.0"

Usage

Basic usage is:

  implicit val sys: ActorSystem       = ActorSystem()
  implicit val mat: Materializer      = Materializer(sys)
  val client = AkkaAvataxClient(...) // or PekkoAvataxClient

  /** 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 subproject for more examples.

There is a good reference for data model here

Please avoid blocking (awaiting) on futures from this api.

Compilation

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.

About

Pure Scala non-blocking (and streaming) client for Avatax

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages