Now that I have an extremely simple Heroku app up and running (see my previous post) and don’t know what to do with it, the logical next step for me was to check out Heroku’s REST API. :)
Ok, so first, let’s look up the REST API documentation…
… but wait, such an abstruse beast does not exist! - Instead, we get the Ruby sources of the Heroku REST client. That’s fine with me, except that I don’t speak Ruby so well. But never mind, this looks easy enough.
Let’s check out what to use as REST client API in Scala: Restlet, Jersey or something? - Nooo! Let’s use Dispatch. Dispatch wins the coolness competition hands down, if you ask me. You’ll see below, I hope.
Of course, I’ll use sbt for building my little project. We add the following two dependencies and are done with it:
Now let’s import all the good stuff:
I’m going to prepare a few helpers next, and then we’re ready to rumble:
Next, we can login, for example. This will return our api key, mostly (I don’t know yet what it’s good for though, seeing all the basic authentication that’s going on in the Ruby client).
< <” and “
<: <” above should really be “
<<” and “
<:<”, don’t ask me why WordPress puts in a space each time I save this post)
User? I have to define that before the above will work. It’s just a simple case class which will be filled by Lift-JSON. And when I’m already at it, I’ll define the case class for the next request here, too:
Now I can call
login and will receive something like this:
This is fun!
Let’s use the above
HerokuApp case class to request our current Heroku apps:
Uhm… - yup, that’s all there is to it. This returns a convenient list of apps I have running on Heroku:
List(HerokuApp(*my-id*,*my-app-name*,Some(cedar),None,*large-number-1*,*large-number-2*,0,0,2011/10/10 11:52:03 -0700,complete,complete))
This is great, isn’t it? - I at least had no idea that it would turn out to be so very easy to connect to Heroku from Scala.
I still don’t know what to put up on Heroku, though…