Well, this road was longer than I expected. In this article, we'll literally just staple the work from the previous articles to finish off the project.
AJAX is a powerful technique that allows you to make HTTP requests from an HTML page without having to reload the entire page. The results can even be inserted into any point of the page that you'd like, allowing you to make very dynamic web applications that behave like real applications, instead of static web pages. In this article, we'll look at how to implement an AJAX web interface with jQuery and Sinatra.
Sinatra is hands down one of the most useful libraries in Ruby for smaller web applications. Rails is great, but it's... huge. Sinatra is small, Sinatra is fast, and it takes just minutes to learn. We'll look at creating web applications in Sinatra running on jRuby.
Great, now we know how to get to the Win32 API. Now, on to sending keystrokes using the Win32 API. Easy, right? Not really. It's not that hard, but it's not as easy as you'd think it would be. We have to use a Win32 API function that needs a callback, and we don't know how to deal with that quite yet. Then we need to iterate over all windows, find the one we want and then send the keystroke. But hey, we get there in the end.
The Win32 API is how you talk to Windows. Even if you're using something like C#, underneath it's still using the Win32 API to access Windows. So, we'll use Win32 directly from JRuby using FFI, the Foreign Function Interface. No real progress is made on the project in this article, but there are a few key concept of FFI to wrap your mind around before we continue on.
Robot is an automation class that's part of AWT (part of Java's GUI toolkit) that can be used for some basic automation tasks. It's generally not flexible enough to be used seriously for the types of things we want to do, but it is quick and depending on your needs it may be suitable.
What is Sinatra? I'm sure most of you are familiar with Rails, but using Rails on a small project is like hiring a well driller to dig a post hole. Sure, it gets the job done, but there's so much setup and other things to worry about and what you really needed was a post hole digger. Sinatra is a post hole digger, just enough tool to do the job, it takes just minutes to learn how to use and it stays out of your way.
If you're a Ruby coder, I'm sure you know how to install Ruby. However, installing JRuby is a bit different, and the interface with Java is something you won't be accustomed to. This article gives you a quick synopsis of installing JRuby and using Java from JRuby.
Over the coming weeks we'll be implementing a project using Sinatra and JRuby. So, first we'll look at a previous article: Why Use JRuby?