Skip to content

Instantly share code, notes, and snippets.

Last active April 9, 2018 18:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save EdgeCaseBerg/6d5d787e25f078795b855a1bb0220fda to your computer and use it in GitHub Desktop.
How to use Vimeo API from Scala
scalaVersion := "2.11.7"
scalacOptions := Seq("-deprecation")
libraryDependencies ++= List(
"com.vimeo.networking" % "vimeo-networking" % "1.1.1"
resolvers += Resolver.jcenterRepo
import com.vimeo.networking._
import com.vimeo.networking.model._
import com.vimeo.networking.model.error.VimeoError;
import com.vimeo.networking.callbacks._
import scala.concurrent.{Future, Promise}
import scala.reflect.ClassTag
import scala.reflect._
import okhttp3.CacheControl
/* This is how we get nice Future's from the Callbacks Vimeo-networking uses */
object RetrofitCallAdapter {
def apply[T: ClassTag](f: ModelCallback[T] => Unit): Future[T] = {
val p = Promise[T]()
val mc = new ModelCallback[T](classTag[T].runtimeClass) {
def success(t: T) = {
def failure(error: VimeoError) = {
val accessCode = "XXXXX"
/* Assuming you want a cache, this is how you set it up */
val configuration = (new Configuration.Builder(accessCode)).setCacheDirectory(new File("cache-dir-you-want"))
/* An actual call */
val uri = ""
val futureVideo = RetrofitCallAdapter[Video] { mc =>
// You'll want to make your own cache config so you don't always go out to network and pass it instead of FORCE_NETWORK
VimeoClient.getInstance().fetchContent(uri, CacheControl.FORCE_NETWORK, mc)
/*Some calling code might look like this: */
import // congrats, you have Future[Int]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment