Lampros - Weird Bricks

Accessing the API through Ruby

02 January, 2015 |

So I'm using more and more and I figured it'd be nice to be able to access their API using Ruby.

At the moment they have Bash scripts to access their API (unfortunately the Bash scripts also have some Perl requirements) and a PHP example - so here's a little piece of code that allows you to list your instances using the API through Ruby.

In the future as time allows I hope to implement the rest of the functions and release the whole thing as a gem.

To get this running on a FreeBSD 10 instance:

1. Install Ruby 2.0 and the required gems:

env ASSUME_ALWAYS_YES=YES pkg install ruby ruby20-gems rubygem-uuidtools rubygem-rest-client

2. Get the code:

fetch --no-verify-peer

3. Edit the file 'script.rb' and replace the 'ACSAccessKeyId' and 'api_private_key ' with your Access key and Private key.

4. Run it:

ruby script.rb

You'll get the list of your running servers formatted in JSON.