Ruby library for version 2 of DigitalOcean's API.
Please note that version 2 of DigitalOcean's API is in beta, and is still being developed. Everything is subject to change.
gem install barge
Ruby 1.9 and up is required. See the .travis.yml file for a list of supported rubies.
barge = Barge::Client.new(access_token: 'token')
or
barge = Barge::Client.new do |config|
config.access_token = 'token'
end
Hashie::Mash is used so that attributes can be accessed using dot notation:
droplet = barge.droplet.show(droplet_id)
droplet.droplet.name # => "foo"
droplet.droplet.image.id # => 123
droplet.droplet.size!.slug # => "512mb"
Notice that size!
and not size
was used. This is because size
already is
a method, and Hashie::Mash will not override it. You can also use square
brackets:
droplet[:droplet][:size][:slug] # => "512mb"
droplet['droplet']['size']['slug'] # => "512mb"
See the API documentation on responses if you are wondering
why attributes are contained within a droplet
key. This might change when
pagination is fully implemented so you can say for instance droplet.name
instead.
You can use #success?
to check if a successful HTTP status code was returned:
barge.droplet.create(options).success? # => true
Barge uses Faraday. You can use #response
to get to the response
object:
barge.droplet.show(droplet_id).response # => Faraday::Response
For paginated resources, a maximum of 200 objects are returned by default (the maximum allowed by the API).
barge.image.all(per_page: 10, page: 2)
barge.action.all.paginated? # => true
barge.region.all.paginated? # => false
barge.image.all(per_page: 5, page: 2).prev_page # => 1
barge.image.all(per_page: 5, page: 2).next_page # => 3
barge.image.all(per_page: 5, page: 2).last_page # => 8
barge.action.all
barge.action.show(action_id)
barge.droplet.create(options)
See the API documentation for options.
barge.droplet.all
barge.droplet.show(droplet_id)
barge.droplet.backups(droplet_id)
barge.droplet.kernels(droplet_id)
barge.droplet.snapshots(droplet_id)
barge.droplet.snapshot(droplet_id, name: 'image name')
barge.droplet.destroy(droplet_id)
barge.droplet.rename(droplet_id, name: 'new name')
barge.droplet.reboot(droplet_id)
barge.droplet.shutdown(droplet_id)
barge.droplet.power_off(droplet_id)
barge.droplet.power_cycle(droplet_id)
barge.droplet.power_on(droplet_id)
barge.droplet.resize(droplet_id, size: 'size slug')
Where size slug is for example 1024mb
.
barge.droplet.rebuild(droplet_id, image: image_id)
barge.droplet.restore(droplet_id, image: image_id)
barge.droplet.password_reset(droplet_id)
barge.droplet.change_kernel(droplet_id, kernel: kernel_id)
barge.droplet.enable_ipv6(droplet_id)
barge.droplet.disable_backups(droplet_id)
barge.droplet.enable_private_networking(droplet_id)
barge.droplet.actions(droplet_id)
barge.droplet.show_action(droplet_id, action_id)
barge.image.all
By ID:
barge.image.show(image_id)
By image slug (public images):
barge.image.show('image slug')
Where image slug is for example ubuntu-13-10-x64
.
barge.image.update(image_id, options)
See the API documentation for options.
barge.image.destroy(image_id)
barge.image.transfer(image_id, region: 'region slug')
Where region slug is for example sfo1
.
barge.image.show_action(image_id, action_id)
barge.domain.create(options)
See the API documentation for options.
barge.domain.all
barge.domain.show(domain_name)
barge.domain.destroy(domain_name)
barge.domain.create_record(domain_name, options)
See the API documentation for options.
barge.domain.records
barge.domain.show_record(domain_name, record_id)
barge.domain.update_record(domain_name, record_id, options)
barge.domain.destroy_record(domain_name, record_id)
barge.key.create(options)
See the API documentation for options.
barge.key.all
barge.key.show(key_id_or_fingerprint)
barge.key.update(key_id_or_fingerprint, options)
See the API documentation for options.
barge.key.destroy(key_id)
barge.region.all
barge.size.all