Barge
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.
Installation
gem install barge
Ruby 1.9 and up is required. See the .travis.yml file for a list of supported rubies.
Initialize
= Barge::Client.new(access_token: 'token')
or
= Barge::Client.new do |config|
config.access_token = 'token'
end
Resources
General
Hashie::Mash
Hashie::Mash is used so that attributes can be accessed using dot notation:
droplet = .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.
#success?
You can use #success?
to check if a successful HTTP status code was returned:
.droplet.create().success? # => true
#response
Barge uses Faraday. You can use #response
to get to the response
object:
.droplet.show(droplet_id).response # => Faraday::Response
Pagination
For paginated resources, a maximum of 200 objects are returned by default (the maximum allowed by the API).
Limit objects per page and/or get a specific page
.image.all(per_page: 10, page: 2)
Check if a response is paginated
.action.all.paginated? # => true
.region.all.paginated? # => false
Get the previous page number
.image.all(per_page: 5, page: 2).prev_page # => 1
Get the next page number
.image.all(per_page: 5, page: 2).next_page # => 3
Get the last page number
.image.all(per_page: 5, page: 2).last_page # => 8
Action
Show all actions
.action.all
Show action
.action.show(action_id)
Droplet
Create droplet
.droplet.create()
See the API documentation for options.
Show all droplets
.droplet.all
Show droplet
.droplet.show(droplet_id)
Show droplet backups
.droplet.backups(droplet_id)
Show droplet kernels
.droplet.kernels(droplet_id)
Show droplet snapshots
.droplet.snapshots(droplet_id)
Create snapshot
.droplet.snapshot(droplet_id, name: 'image name')
Destroy droplet
.droplet.destroy(droplet_id)
Rename droplet
.droplet.rename(droplet_id, name: 'new name')
Reboot droplet
.droplet.reboot(droplet_id)
Shutdown droplet
.droplet.shutdown(droplet_id)
Power off droplet
.droplet.power_off(droplet_id)
Power cycle droplet
.droplet.power_cycle(droplet_id)
Power on droplet
.droplet.power_on(droplet_id)
Resize droplet
.droplet.resize(droplet_id, size: 'size slug')
Where size slug is for example 1024mb
.
Rebuild droplet
.droplet.rebuild(droplet_id, image: image_id)
Restore droplet
.droplet.restore(droplet_id, image: image_id)
Reset a droplet's password
.droplet.password_reset(droplet_id)
Change a droplet's kernel
.droplet.change_kernel(droplet_id, kernel: kernel_id)
Enable IPv6 for a droplet
.droplet.enable_ipv6(droplet_id)
Disable backups for a droplet
.droplet.disable_backups(droplet_id)
Enable private networking for a droplet
.droplet.enable_private_networking(droplet_id)
Show droplet actions
.droplet.actions(droplet_id)
Show droplet action
.droplet.show_action(droplet_id, action_id)
Image
Show all images
.image.all
Show image
By ID:
.image.show(image_id)
By image slug (public images):
.image.show('image slug')
Where image slug is for example ubuntu-13-10-x64
.
Update image
.image.update(image_id, )
See the API documentation for options.
Destroy image
.image.destroy(image_id)
Transfer image
.image.transfer(image_id, region: 'region slug')
Where region slug is for example sfo1
.
Show image action
.image.show_action(image_id, action_id)
Domain
Create domain
.domain.create()
See the API documentation for options.
Show all domains
.domain.all
Show domain
.domain.show(domain_name)
Destroy domain
.domain.destroy(domain_name)
Create domain record
.domain.create_record(domain_name, )
See the API documentation for options.
Show all domain records
.domain.records
Show domain record
.domain.show_record(domain_name, record_id)
Update domain record
.domain.update_record(domain_name, record_id, )
Destroy domain record
.domain.destroy_record(domain_name, record_id)
Key
Create key
.key.create()
See the API documentation for options.
Show all keys
.key.all
Show key
.key.show(key_id_or_fingerprint)
Update key
.key.update(key_id_or_fingerprint, )
See the API documentation for options.
Destroy key
.key.destroy(key_id)
Region
Show all regions
.region.all
Size
Show all sizes
.size.all