Most people think of Google as 'just' a search company, but in recent years it's started to provide free versions of applications that were previously only available as standalone desktop programs.
The number of people using Google for email, scheduling, word processing and creating spreadsheets is ever-increasing, but websites are just one way of accessing all these applications.
Behind the scenes, most of what's available from Google through web pages is also available via programming.
What are web services?
Web services are akin to very simple websites – sites that are designed to be used by computers instead of humans.
Imagine that you write a script that calls a web service. The script makes a 'request' to the service by sending information (usually in XML) to a web address. The service usually responds with some XML text instead of returning a HTML web page.
For example, a search engine might allow you to send it some search terms and respond to those with an XML file that lists the names and locations of web pages matching your criteria.
That's a simple case, but as websites have grown more powerful and similar to desktop applications, web services have begun to offer a longer list of features. They've grown to the point that many of them are now serving a similar function to the role macro languages such as VBA once served in Microsoft Office and other products.
The example application we're going to build here connects two different sets of web services together. One is from the BBC, the other from Google.
The BBC offers a lot of its listing information for free via web services. If you have a TV card in your PC that is able to automatically pick up programme details, it may well be using one of these BBC services.
Google exposes almost everything it does as web services. It's part of its plan to become the container for all information on the planet, and Google has shrewdly given users as much access as possible to the data and applications that it hosts.
By connecting these two web services, we're able to solve a hypothetical problem: you want to watch documentaries about the countryside, but whenever you turn on the TV, you're unable to find what you want and end up watching something else. This TV scheduling project stops this from happening.
You can filter the BBC's listings for just the things you want, then post an event for each programme on Google Calendar to remind you when to tune in for the shows.
The first set of web services we'll look at is run on the BBC's Backstage website. This is an experimental system that was launched three years ago, and it makes a lot of BBC data available in the hope that people come up with interesting and innovative ways of using it. All of the documentation for the Backstage web services can be found here: www.tinyurl.com/2af4vw.
The script that handles the BBC service is called 'bbc_progs.rb'. Although there are plenty of services on offer, we're only going to use three of them. First of all, we'll call 'bbc.genre.getMembers'. If you send this service the code for a particular genre of programme (such as documentaries), it returns an XML description of all programmes of that type currently listed on its database.
Next, we're going to call 'bbc.programme.getLocations'. This returns a set of addresses where you're able to watch or listen to the programme on the web. In reality, the addresses returned don't always work – most of the radio links are fine, but the majority of the TV links are wrong. It seems likely that, over time, more TV will be streamed on the web, so we'll record them here just in case.