Ruby API wrapper for the Linode API
Create an API object from the LinodeAPI::Raw class, by providing it with either an API key or username and password:
require 'linodeapi'
api_one = LinodeAPI::Raw.new(apikey: 'YOUR_KEY_HERE')
api_two = LinodeAPI::Raw.new(username: 'akerl', password: 'cyberpond')
The Raw API object is a faithful representation of Linode's API spec, parsed directly from the upstream source at runtime. Calls can be made using the methods shown in Linode's API docs:
# cat list.rb
require 'linodeapi'
api = LinodeAPI::Raw.new(apikey: 'KEY')
result = api.linode.list
puts "#{result.size} Linodes found: #{result.map(&:label).join(', ')}"
p result.first
# ruby list.rb
6 Linodes found: miro, olhado, quara, grego, ela, quim
#<OpenStruct alert_cpu_enabled=0, alert_bwin_enabled=0, alert_bwquota_enabled=0, alert_diskio_threshold=1000, backupwindow=4, watchdog=1, distributionvendor="Arch", datacenterid=6, status=1, alert_diskio_enabled=0, create_dt="2014-07-30 20:09:12.0", totalhd=49152, alert_bwquota_threshold=80, totalram=2048, alert_bwin_threshold=5, linodeid=591319, alert_bwout_threshold=5, alert_bwout_enabled=0, backupsenabled=0, alert_cpu_threshold=90, planid=2, backupweeklyday=0, label="miro", lpm_displaygroup="cluster", totalxfer=3000>
Arguments passed in are named just like in the docs:
api.linode.ip.list(linodeid: 591319)
The library will raise an exception if you exclude a required parameter:
api.linode.create
# ArgumentError: linode.create requires planid
The LinodeAPI::Retryable class automatically handles 429 errors (really, any HTTP error that is accompanied by a Retry-After header).
This class behaves identially to the LinodeAPI::Raw class, with 2 additional parameters at creation: max_retries
sets the total number of requests it will attempt per call and max_delay
sets the maximum delay between attempts. They default to 3 tries and 60 seconds, respectively.
gem install linodeapi
linodeapi is released under the MIT License. See the bundled LICENSE file for details.