Scala and PlayJava clients for the JVM SDK
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
commercetools-play-2_2-java-client/src
commercetools-play-2_3-java-client/src
commercetools-play-2_4-java-client/src
commercetools-play-2_5-java-client/src
commercetools-scala-client/src
commercetools-scala-models/src
project
.gitignore
.sbtrc
.travis.yml
LICENSE
README.md
build.sbt
sbt
version.sbt

README.md

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)