Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

commercetools/commercetools-jvm-sdk-scala-add-ons

Repository files navigation

commercetools-jvm-sdk-scala-add-ons

SPHERE.IO icon

This repository is for in Scala implemented stuff to extend the https://github.com/commercetools/commercetools-jvm-sdk .

Search for your Scala version on Maven Central. We support 2.10.x, 2.11.x and milestones of 2.12.

Scala client

libraryDependencies += "com.commercetools.sdk.jvm.scala-add-ons" %% "commercetools-scala-client" % "version"

The Scala client wraps a SphereClient and can return Scala's Futures:

object Demo {
    def demoWithScalaClient(sphereClient: SphereClient): Unit = {
      //the client can be created by the apply method
      //of the ScalaSphereClient companion object
      val scalaSphereClient: ScalaSphereClient = ScalaSphereClient(sphereClient)


      //using the ScalaSphereClient instance apply method returns a Scala Future
      import scala.concurrent.Future
      val future: Future[PagedSearchResult[ProductProjection]] =
        scalaSphereClient(ProductProjectionSearch.ofCurrent())
      val future2: Future[PagedSearchResult[ProductProjection]] =
        //same as above with explicit apply method call
        scalaSphereClient.apply(ProductProjectionSearch.ofCurrent())


      //using the execute method returns a CompletionStage
      val completionStage: CompletionStage[PagedSearchResult[ProductProjection]] =
        scalaSphereClient.execute(ProductProjectionSearch.ofCurrent())

      //the ScalaSphereClient can be used in every SphereClient context
      val upcasted: SphereClient = scalaSphereClient
    }
}

Scala models

libraryDependencies += "com.commercetools.sdk.jvm.scala-add-ons" %% "commercetools-scala-models" % "version"

Old Scala versions do not support Java 8 lambdas which are an important part in the commercetools JVM SDK. This module provides implicit conversions to support Scala lambdas.

import io.sphere.sdk.queries.Implicits._
val query = ProductProjectionQuery.ofStaged
val queryById = query.withPredicatesScala(_.id.is("foo"))
val sortById = query.withSortScala(_.id.sort.asc)
val expandedQuery = query.plusExpansionPathsScala(_.productType)