├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── .yardopts ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Gemfile ├── Guardfile ├── LICENSE ├── README.md ├── Rakefile ├── barge.gemspec ├── lib ├── barge.rb └── barge │ ├── client.rb │ ├── resource.rb │ ├── resource │ ├── account.rb │ ├── action.rb │ ├── base.rb │ ├── domain.rb │ ├── droplet.rb │ ├── floating_ip.rb │ ├── image.rb │ ├── key.rb │ ├── region.rb │ └── size.rb │ ├── response.rb │ └── version.rb └── spec ├── barge ├── client_spec.rb ├── resource │ ├── account_spec.rb │ ├── action_spec.rb │ ├── base_spec.rb │ ├── domain_spec.rb │ ├── droplet_spec.rb │ ├── floating_ip_spec.rb │ ├── image_spec.rb │ ├── key_spec.rb │ ├── region_spec.rb │ └── size_spec.rb ├── response_spec.rb └── version_spec.rb ├── barge_spec.rb ├── fixtures ├── account │ └── show.json ├── actions │ ├── all.json │ └── show.json ├── domains │ ├── all.json │ ├── create.json │ ├── create_record.json │ ├── records.json │ ├── show.json │ ├── show_record.json │ └── update_record.json ├── droplets │ ├── actions.json │ ├── all.json │ ├── backups.json │ ├── change_kernel.json │ ├── create.json │ ├── disable_backups.json │ ├── enable_ipv6.json │ ├── enable_private_networking.json │ ├── kernels.json │ ├── password_reset.json │ ├── power_cycle.json │ ├── power_off.json │ ├── power_on.json │ ├── reboot.json │ ├── rebuild.json │ ├── rename.json │ ├── resize.json │ ├── restore.json │ ├── show.json │ ├── show_action.json │ ├── shutdown.json │ ├── snapshot.json │ └── snapshots.json ├── floating_ips │ ├── all.json │ ├── assign.json │ ├── create.json │ ├── show.json │ └── unassign.json ├── images │ ├── all.json │ ├── show.json │ ├── show_action.json │ ├── transfer.json │ └── update.json ├── keys │ ├── all.json │ ├── create.json │ ├── show.json │ └── update.json ├── regions │ └── all.json └── sizes │ └── all.json ├── spec_helper.rb └── support ├── shared_contexts.rb ├── shared_examples.rb └── spec_helpers.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle 2 | /.rbx 3 | /.yardoc 4 | /Gemfile.lock 5 | /coverage 6 | /doc 7 | /pkg 8 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --order rand 3 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | Include: 3 | - Gemfile 4 | - Guardfile 5 | - Rakefile 6 | - barge.gemspec 7 | 8 | Documentation: 9 | Enabled: false 10 | 11 | Encoding: 12 | Enabled: false 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 1.9.3 4 | - 2.0.0 5 | - 2.1 6 | - 2.2 7 | - jruby 8 | - rbx-2 9 | - ruby-head 10 | matrix: 11 | allow_failures: 12 | - rvm: rbx-2 13 | - rvm: ruby-head 14 | fast_finish: true 15 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | - 2 | [A-Z][A-Z]* 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2015-11-22 - 0.12.0 2 | ------------------- 3 | 4 | * [Add floating_ip resource](https://github.com/blom/barge/commit/fd5f960b17ae1509ba697616c6a7c9d2e544807a) 5 | * [Make #faraday public](https://github.com/blom/barge/commit/660dd56ea4ad71d7d62a86ee442d87c77a3f712a) 6 | 7 | 2014-11-23 - 0.11.0 8 | ------------------- 9 | 10 | * [Fix character set issue](https://github.com/blom/barge/commit/07144026bbe3702791dffcbad2675e84fc0b358f) 11 | * [Drop support for Ruby 1.9.2](https://github.com/blom/barge/commit/5ce2a854f023f72268677129d51615bb28874dd7) 12 | * [Add request_options to Barge::Client](https://github.com/blom/barge/commit/a56396bbf9fd177a7159c3b9d822be685f11295a) 13 | * [Add account resource](https://github.com/blom/barge/commit/d1eee34ff52e141539389bac5f0d1914c3cb3c7e) 14 | 15 | 2014-08-03 - 0.10.0 16 | ------------------- 17 | 18 | * [Use option hashes everywhere for attributes](https://github.com/blom/barge/commit/731d7b9af6a4a69d29531166b2e3c793a14b2d5d) 19 | 20 | 2014-07-27 - 0.9.0 21 | ------------------ 22 | 23 | * [Add Droplet#snapshot](https://github.com/blom/barge/commit/7651ea6e142f2f096835a097428576084b773b24) 24 | 25 | 2014-07-18 - 0.8.0 26 | ------------------ 27 | 28 | * [Add basic pagination support](https://github.com/blom/barge/compare/8dd84d2...7dc6208) 29 | 30 | 2014-07-03 - 0.7.0 31 | ------------------ 32 | 33 | * [Add Droplet#enable_private_networking](https://github.com/blom/barge/commit/b6ebb9364abf0303f4f20c2e8560663f1e2bc97b) 34 | * [Add Droplet#disable_backups](https://github.com/blom/barge/commit/aebb0fe8d8a656475d59eb836b8d3dff8b12f99b) 35 | * [Add Droplet#enable_ipv6](https://github.com/blom/barge/commit/c6cff2754f0aa48d3c735b2f9411b91a8d4ae810) 36 | * [Add Droplet#change_kernel](https://github.com/blom/barge/commit/4f84d00a7f71c00eebb51239131efc796d2ab8a2) 37 | 38 | 2014-07-01 - 0.6.0 39 | ------------------ 40 | 41 | * [Add Key#update](https://github.com/blom/barge/commit/bccd671e68ce42194577350fb6addf78ca9a46b2) 42 | 43 | 2014-06-29 - 0.5.0 44 | ------------------ 45 | 46 | * [Increase per_page](https://github.com/blom/barge/commit/fb5ef4d34aba9c2a6513411e8bbf85e80009f9c7) 47 | * [Add Droplet#kernels](https://github.com/blom/barge/commit/6f0543af777707ff59c8fbcc8c421079cb4bd8d1) 48 | * [Add Droplet#actions](https://github.com/blom/barge/commit/6e3a2f8da909c703095dce71d9d4fee495c40315) 49 | 50 | 2014-06-28 - 0.4.0 51 | ------------------ 52 | 53 | * [Add action resource](https://github.com/blom/barge/commit/5fac0be55860d96831d0c0aecd5d4de9f04217dd) 54 | 55 | 2014-06-10 - 0.3.0 56 | ------------------ 57 | 58 | * [Add Droplet#snapshots](https://github.com/blom/barge/commit/2f06fd03617f750388e6457d82abbb789ba397b0) 59 | * [Add Droplet#backups](https://github.com/blom/barge/commit/7962e6d365d0ed699b037b50c0fe8ce461944630) 60 | 61 | 2014-06-08 - 0.2.0 62 | ------------------ 63 | 64 | * [Add Image#show_action](https://github.com/blom/barge/commit/7fb754f02d4f997a2f811ce62876bcb1f3292e9a) 65 | * [Add Droplet#show_action](https://github.com/blom/barge/commit/ce1db15a98bc72c844c39fbbf8f1f5c753e340af) 66 | 67 | 2014-06-07 - 0.1.0 68 | ------------------ 69 | 70 | Initial release. 71 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | 1. **Topic branch**. Work in a dedicated topic branch. Rebase against master 5 | before submitting your pull request if master has changed. 6 | 7 | 2. **Commit message format**. See [this][format] and use present tense (*Add 8 | feature*, not *Added feature*). 9 | 10 | 3. **Squash commits**. Squash related commits together. If there is no good 11 | reason to have separate commits for something, combine them. 12 | 13 | 4. **Passing tests**. Run `bundle exec rake`. This will run RuboCop and RSpec. 14 | 15 | 5. **Code coverage**. `bundle exec rake coverage` should report 100% coverage. 16 | 17 | Thank you! 18 | 19 | [format]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 20 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | 4 | gem 'coveralls', require: false 5 | gem 'guard' 6 | gem 'guard-rspec' 7 | gem 'rake' 8 | gem 'rspec' 9 | gem 'rubocop', '~> 0.34.0' 10 | gem 'simplecov' 11 | gem 'webmock', require: false 12 | gem 'yard' 13 | 14 | platforms :jruby do 15 | gem 'kramdown' 16 | end 17 | 18 | platforms :rbx do 19 | gem 'rubysl' 20 | end 21 | 22 | platforms :ruby do 23 | gem 'github-markup' 24 | gem 'redcarpet' 25 | end 26 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | guard :rspec, cmd: 'bundle exec rspec' do 2 | watch(%r{\Aspec/.+_spec\.rb\z}) 3 | watch(%r{\Alib/(.+)\.rb\z}) { |_, match| "spec/#{match}_spec.rb" } 4 | watch('spec/spec_helper.rb') { 'spec' } 5 | watch(%r{\Aspec/fixtures/(.+)/.*\.json\z}) do |_, match| 6 | "spec/barge/resource/#{match.chop}_spec.rb" 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Ørjan Blom 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Barge 2 | ===== 3 | 4 | [![Gem Version](https://img.shields.io/gem/v/barge.svg)][gem] 5 | [![Build Status](https://img.shields.io/travis/blom/barge/master.svg)][travis] 6 | [![Coverage Status](https://img.shields.io/coveralls/blom/barge.svg)][coveralls] 7 | [![Code Climate](https://img.shields.io/codeclimate/github/blom/barge.svg)][codeclimate] 8 | [![Dependency Status](https://img.shields.io/gemnasium/blom/barge.svg)][gemnasium] 9 | 10 | [gem]: https://rubygems.org/gems/barge 11 | [travis]: https://travis-ci.org/blom/barge 12 | [coveralls]: https://coveralls.io/r/blom/barge 13 | [codeclimate]: https://codeclimate.com/github/blom/barge 14 | [gemnasium]: https://gemnasium.com/blom/barge 15 | 16 | Ruby library for [version 2 of DigitalOcean's 17 | API](https://developers.digitalocean.com/documentation/v2/). 18 | 19 | ### Installation 20 | 21 | ``` sh 22 | gem install barge 23 | ``` 24 | 25 | Ruby 1.9.3 and up is required. See the [.travis.yml](.travis.yml) file for a 26 | list of supported rubies. 27 | 28 | ### Initialize 29 | 30 | ``` ruby 31 | barge = Barge::Client.new(access_token: 'token') 32 | ``` 33 | 34 | *or* 35 | 36 | ``` ruby 37 | barge = Barge::Client.new do |config| 38 | config.access_token = 'token' 39 | end 40 | ``` 41 | 42 | Resources 43 | ========= 44 | 45 | General 46 | ------- 47 | 48 | ### Hashie::Mash 49 | 50 | [Hashie::Mash](https://github.com/intridea/hashie) is used so that attributes 51 | can be accessed using dot notation: 52 | 53 | ``` ruby 54 | droplet = barge.droplet.show(droplet_id) 55 | droplet.droplet.name # => "foo" 56 | droplet.droplet.image.id # => 123 57 | droplet.droplet.size!.slug # => "512mb" 58 | ``` 59 | 60 | Notice that `size!` and not `size` was used. This is because `size` already is 61 | a method, and Hashie::Mash will not override it. You can also use square 62 | brackets: 63 | 64 | ``` ruby 65 | droplet[:droplet][:size][:slug] # => "512mb" 66 | droplet['droplet']['size']['slug'] # => "512mb" 67 | ``` 68 | 69 | See the [API documentation on responses][api-responses] if you are wondering 70 | why attributes are contained within a `droplet` key. 71 | 72 | [api-responses]: https://developers.digitalocean.com/documentation/v2/#responses 73 | 74 | ### #success? 75 | 76 | You can use `#success?` to check if a successful HTTP status code was returned: 77 | 78 | ``` ruby 79 | barge.droplet.create(options).success? # => true 80 | ``` 81 | 82 | ### #response 83 | 84 | Barge uses [Faraday][faraday]. You can use `#response` to get to the [response 85 | object][faraday-response]: 86 | 87 | ``` ruby 88 | barge.droplet.show(droplet_id).response # => Faraday::Response 89 | ``` 90 | 91 | [faraday]: https://github.com/lostisland/faraday 92 | [faraday-response]: http://rubydoc.info/gems/faraday/Faraday/Response 93 | 94 | Pagination 95 | ---------- 96 | 97 | For [paginated resources][api-links], a maximum of 200 objects are returned by 98 | default (the maximum allowed by the API). 99 | 100 | ### Limit objects per page and/or get a specific page 101 | 102 | ``` ruby 103 | barge.image.all(per_page: 10, page: 2) 104 | ``` 105 | 106 | [api-links]: https://developers.digitalocean.com/documentation/v2/#links 107 | 108 | ### Check if a response is paginated 109 | 110 | ``` ruby 111 | barge.action.all.paginated? # => true 112 | barge.region.all.paginated? # => false 113 | ``` 114 | 115 | ### Get the previous page number 116 | 117 | ``` ruby 118 | barge.image.all(per_page: 5, page: 2).prev_page # => 1 119 | ``` 120 | 121 | ### Get the next page number 122 | 123 | ``` ruby 124 | barge.image.all(per_page: 5, page: 2).next_page # => 3 125 | ``` 126 | 127 | ### Get the last page number 128 | 129 | ``` ruby 130 | barge.image.all(per_page: 5, page: 2).last_page # => 8 131 | ``` 132 | 133 | Account 134 | ------- 135 | 136 | ### Show account information 137 | 138 | ``` ruby 139 | barge.account.show 140 | ``` 141 | 142 | Action 143 | ------ 144 | 145 | ### Show all actions 146 | 147 | ``` ruby 148 | barge.action.all 149 | ``` 150 | 151 | ### Show action 152 | 153 | ``` ruby 154 | barge.action.show(action_id) 155 | ``` 156 | 157 | Droplet 158 | ------- 159 | 160 | ### Create droplet 161 | 162 | ``` ruby 163 | barge.droplet.create(options) 164 | ``` 165 | 166 | See the [API documentation][droplet-create] for options. 167 | 168 | [droplet-create]: https://developers.digitalocean.com/documentation/v2/#create-a-new-droplet 169 | 170 | ### Show all droplets 171 | 172 | ``` ruby 173 | barge.droplet.all 174 | ``` 175 | 176 | ### Show droplet 177 | 178 | ``` ruby 179 | barge.droplet.show(droplet_id) 180 | ``` 181 | 182 | ### Show droplet backups 183 | 184 | ``` ruby 185 | barge.droplet.backups(droplet_id) 186 | ``` 187 | 188 | ### Show droplet kernels 189 | 190 | ``` ruby 191 | barge.droplet.kernels(droplet_id) 192 | ``` 193 | 194 | ### Show droplet snapshots 195 | 196 | ``` ruby 197 | barge.droplet.snapshots(droplet_id) 198 | ``` 199 | 200 | ### Create snapshot 201 | 202 | ``` ruby 203 | barge.droplet.snapshot(droplet_id, name: 'image name') 204 | ``` 205 | 206 | ### Destroy droplet 207 | 208 | ``` ruby 209 | barge.droplet.destroy(droplet_id) 210 | ``` 211 | 212 | ### Rename droplet 213 | 214 | ``` ruby 215 | barge.droplet.rename(droplet_id, name: 'new name') 216 | ``` 217 | 218 | ### Reboot droplet 219 | 220 | ``` ruby 221 | barge.droplet.reboot(droplet_id) 222 | ``` 223 | 224 | ### Shutdown droplet 225 | 226 | ``` ruby 227 | barge.droplet.shutdown(droplet_id) 228 | ``` 229 | 230 | ### Power off droplet 231 | 232 | ``` ruby 233 | barge.droplet.power_off(droplet_id) 234 | ``` 235 | 236 | ### Power cycle droplet 237 | 238 | ``` ruby 239 | barge.droplet.power_cycle(droplet_id) 240 | ``` 241 | 242 | ### Power on droplet 243 | 244 | ``` ruby 245 | barge.droplet.power_on(droplet_id) 246 | ``` 247 | 248 | ### Resize droplet 249 | 250 | ``` ruby 251 | barge.droplet.resize(droplet_id, size: 'size slug') 252 | ``` 253 | 254 | Where *size slug* is for example `1024mb`. 255 | 256 | ### Rebuild droplet 257 | 258 | ``` ruby 259 | barge.droplet.rebuild(droplet_id, image: image_id) 260 | ``` 261 | 262 | ### Restore droplet 263 | 264 | ``` ruby 265 | barge.droplet.restore(droplet_id, image: image_id) 266 | ``` 267 | 268 | ### Reset a droplet's password 269 | 270 | ``` ruby 271 | barge.droplet.password_reset(droplet_id) 272 | ``` 273 | 274 | ### Change a droplet's kernel 275 | 276 | ``` ruby 277 | barge.droplet.change_kernel(droplet_id, kernel: kernel_id) 278 | ``` 279 | 280 | ### Enable IPv6 for a droplet 281 | 282 | ``` ruby 283 | barge.droplet.enable_ipv6(droplet_id) 284 | ``` 285 | 286 | ### Disable backups for a droplet 287 | 288 | ``` ruby 289 | barge.droplet.disable_backups(droplet_id) 290 | ``` 291 | 292 | ### Enable private networking for a droplet 293 | 294 | ``` ruby 295 | barge.droplet.enable_private_networking(droplet_id) 296 | ``` 297 | 298 | ### Show droplet actions 299 | 300 | ``` ruby 301 | barge.droplet.actions(droplet_id) 302 | ``` 303 | 304 | ### Show droplet action 305 | 306 | ``` ruby 307 | barge.droplet.show_action(droplet_id, action_id) 308 | ``` 309 | 310 | Image 311 | ----- 312 | 313 | ### Show all images 314 | 315 | ``` ruby 316 | barge.image.all 317 | barge.image.all(private: true) 318 | barge.image.all(type: :application) 319 | barge.image.all(type: :distribution) 320 | ``` 321 | 322 | ### Show image 323 | 324 | By ID: 325 | 326 | ``` ruby 327 | barge.image.show(image_id) 328 | ``` 329 | 330 | By image slug (public images): 331 | 332 | ``` ruby 333 | barge.image.show('image slug') 334 | ``` 335 | 336 | Where *image slug* is for example `ubuntu-13-10-x64`. 337 | 338 | ### Update image 339 | 340 | ``` ruby 341 | barge.image.update(image_id, options) 342 | ``` 343 | 344 | See the [API documentation][image-update] for options. 345 | 346 | [image-update]: https://developers.digitalocean.com/documentation/v2/#update-an-image 347 | 348 | ### Destroy image 349 | 350 | ``` ruby 351 | barge.image.destroy(image_id) 352 | ``` 353 | 354 | ### Transfer image 355 | 356 | ``` ruby 357 | barge.image.transfer(image_id, region: 'region slug') 358 | ``` 359 | 360 | Where *region slug* is for example `sfo1`. 361 | 362 | ### Show image action 363 | 364 | ``` ruby 365 | barge.image.show_action(image_id, action_id) 366 | ``` 367 | 368 | Domain 369 | ------ 370 | 371 | ### Create domain 372 | 373 | ``` ruby 374 | barge.domain.create(options) 375 | ``` 376 | 377 | See the [API documentation][domain-create] for options. 378 | 379 | [domain-create]: https://developers.digitalocean.com/documentation/v2/#create-a-new-domain 380 | 381 | ### Show all domains 382 | 383 | ``` ruby 384 | barge.domain.all 385 | ``` 386 | 387 | ### Show domain 388 | 389 | ``` ruby 390 | barge.domain.show(domain_name) 391 | ``` 392 | 393 | ### Destroy domain 394 | 395 | ``` ruby 396 | barge.domain.destroy(domain_name) 397 | ``` 398 | 399 | ### Create domain record 400 | 401 | ``` ruby 402 | barge.domain.create_record(domain_name, options) 403 | ``` 404 | 405 | See the [API documentation][domain-create-record] for options. 406 | 407 | [domain-create-record]: https://developers.digitalocean.com/documentation/v2/#create-a-new-domain-record 408 | 409 | ### Show all domain records 410 | 411 | ``` ruby 412 | barge.domain.records 413 | ``` 414 | 415 | ### Show domain record 416 | 417 | ``` ruby 418 | barge.domain.show_record(domain_name, record_id) 419 | ``` 420 | 421 | ### Update domain record 422 | 423 | ``` ruby 424 | barge.domain.update_record(domain_name, record_id, options) 425 | ``` 426 | 427 | ### Destroy domain record 428 | 429 | ``` ruby 430 | barge.domain.destroy_record(domain_name, record_id) 431 | ``` 432 | 433 | Key 434 | --- 435 | 436 | ### Create key 437 | 438 | ``` ruby 439 | barge.key.create(options) 440 | ``` 441 | 442 | See the [API documentation][key-create] for options. 443 | 444 | [key-create]: https://developers.digitalocean.com/documentation/v2/#create-a-new-key 445 | 446 | ### Show all keys 447 | 448 | ``` ruby 449 | barge.key.all 450 | ``` 451 | 452 | ### Show key 453 | 454 | ``` ruby 455 | barge.key.show(key_id_or_fingerprint) 456 | ``` 457 | 458 | ### Update key 459 | 460 | ``` ruby 461 | barge.key.update(key_id_or_fingerprint, options) 462 | ``` 463 | 464 | See the [API documentation][key-update] for options. 465 | 466 | [key-update]: https://developers.digitalocean.com/documentation/v2/#update-a-key 467 | 468 | ### Destroy key 469 | 470 | ``` ruby 471 | barge.key.destroy(key_id) 472 | ``` 473 | 474 | Region 475 | ------ 476 | 477 | ### Show all regions 478 | 479 | ``` ruby 480 | barge.region.all 481 | ``` 482 | 483 | Size 484 | ---- 485 | 486 | ### Show all sizes 487 | 488 | ``` ruby 489 | barge.size.all 490 | ``` 491 | 492 | Floating IP 493 | ----------- 494 | 495 | ### Show all floating IPs 496 | 497 | ``` ruby 498 | barge.floating_ip.all 499 | ``` 500 | 501 | ### Create floating IP 502 | 503 | ``` ruby 504 | barge.floating_ip.create(droplet_id: droplet_id) 505 | barge.floating_ip.create(region: region) 506 | ``` 507 | 508 | ### Show floating IP 509 | 510 | ``` ruby 511 | barge.floating_ip.show(ip_address) 512 | ``` 513 | 514 | ### Destroy floating IP 515 | 516 | ``` ruby 517 | barge.floating_ip.destroy(ip_address) 518 | ``` 519 | 520 | ### Assign a floating IP to a droplet 521 | 522 | ``` ruby 523 | barge.floating_ip.assign(ip_address, droplet_id: droplet_id) 524 | ``` 525 | 526 | ### Unassign a floating IP 527 | 528 | ``` ruby 529 | barge.floating_ip.unassign(ip_address) 530 | ``` 531 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rake/clean' 3 | require 'rspec/core/rake_task' 4 | require 'rubocop/rake_task' 5 | require 'yard' 6 | 7 | task default: [:rubocop, :spec] 8 | 9 | CLOBBER.include %w(.rbx .yardoc coverage doc pkg) 10 | 11 | RSpec::Core::RakeTask.new 12 | RuboCop::RakeTask.new 13 | YARD::Rake::YardocTask.new 14 | 15 | desc 'Generate coverage data' 16 | task :coverage do 17 | ENV['SIMPLECOV'] = 'true' 18 | Rake::Task['spec'].invoke 19 | end 20 | -------------------------------------------------------------------------------- /barge.gemspec: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | require File.expand_path '../lib/barge/version', __FILE__ 3 | 4 | Gem::Specification.new do |spec| 5 | spec.name = 'barge' 6 | spec.version = Barge::Version 7 | spec.summary = 'Ruby library for DigitalOcean' 8 | spec.description = "Ruby library for version 2 of DigitalOcean's API" 9 | spec.license = 'MIT' 10 | spec.authors = ['Ørjan Blom'] 11 | spec.email = %w(blom@blom.tv) 12 | spec.homepage = 'https://github.com/blom/barge' 13 | 14 | spec.files = `git ls-files -z`.split("\x0").keep_if do |file| 15 | file.match(/\A(lib|[A-Z]{2})/) 16 | end 17 | 18 | spec.required_ruby_version = '>= 1.9.3' 19 | 20 | spec.add_dependency 'faraday', '~> 0.9' 21 | spec.add_dependency 'faraday_middleware', '~> 0.10' 22 | spec.add_dependency 'hashie', '~> 3.4' 23 | end 24 | -------------------------------------------------------------------------------- /lib/barge.rb: -------------------------------------------------------------------------------- 1 | require 'hashie' 2 | 3 | require 'barge/client' 4 | require 'barge/resource' 5 | require 'barge/response' 6 | require 'barge/version' 7 | 8 | module Barge 9 | end 10 | -------------------------------------------------------------------------------- /lib/barge/client.rb: -------------------------------------------------------------------------------- 1 | require 'faraday' 2 | require 'faraday_middleware' 3 | 4 | module Barge 5 | class Client 6 | attr_accessor :access_token 7 | attr_accessor :request_options 8 | 9 | DEFAULT_OPTIONS = {} 10 | DIGITAL_OCEAN_URL = 'https://api.digitalocean.com/v2' 11 | TIMEOUTS = 10 12 | 13 | def initialize(options = DEFAULT_OPTIONS) 14 | self.access_token = options.fetch(:access_token, nil) 15 | self.request_options = 16 | { open_timeout: TIMEOUTS, timeout: TIMEOUTS } 17 | .merge(options.fetch(:request_options, {})) 18 | yield(self) if block_given? 19 | fail ArgumentError, 'missing access_token' unless access_token 20 | end 21 | 22 | def account 23 | @account ||= Resource::Account.new(faraday) 24 | end 25 | 26 | def action 27 | @action ||= Resource::Action.new(faraday) 28 | end 29 | 30 | def domain 31 | @domain ||= Resource::Domain.new(faraday) 32 | end 33 | 34 | def droplet 35 | @droplet ||= Resource::Droplet.new(faraday) 36 | end 37 | 38 | def image 39 | @image ||= Resource::Image.new(faraday) 40 | end 41 | 42 | def key 43 | @key ||= Resource::Key.new(faraday) 44 | end 45 | 46 | def region 47 | @region ||= Resource::Region.new(faraday) 48 | end 49 | 50 | def size 51 | @size ||= Resource::Size.new(faraday) 52 | end 53 | 54 | def floating_ip 55 | @floating_ip ||= Resource::FloatingIP.new(faraday) 56 | end 57 | 58 | def faraday 59 | @faraday ||= Faraday.new faraday_options do |f| 60 | f.adapter :net_http 61 | 62 | f.request :json 63 | 64 | f.response :follow_redirects 65 | f.response :mashify 66 | f.response :json 67 | 68 | f.options.merge! request_options 69 | end 70 | end 71 | 72 | private 73 | 74 | def faraday_options 75 | { 76 | headers: { 77 | authorization: "Bearer #{access_token}", 78 | content_type: 'application/json' 79 | }, 80 | url: DIGITAL_OCEAN_URL 81 | } 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /lib/barge/resource.rb: -------------------------------------------------------------------------------- 1 | require 'barge/resource/base' 2 | 3 | require 'barge/resource/account' 4 | require 'barge/resource/action' 5 | require 'barge/resource/domain' 6 | require 'barge/resource/droplet' 7 | require 'barge/resource/floating_ip' 8 | require 'barge/resource/image' 9 | require 'barge/resource/key' 10 | require 'barge/resource/region' 11 | require 'barge/resource/size' 12 | 13 | module Barge 14 | module Resource 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/barge/resource/account.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Account 4 | include Resource::Base 5 | 6 | def show 7 | get('account') 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/barge/resource/action.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Action 4 | include Resource::Base 5 | 6 | def all(options = {}) 7 | get('actions', options) 8 | end 9 | 10 | def show(action_id) 11 | get("actions/#{action_id}") 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/barge/resource/base.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | module Base 4 | attr_reader :faraday 5 | 6 | PER_PAGE = 200 7 | 8 | def initialize(faraday) 9 | @faraday = faraday 10 | end 11 | 12 | private 13 | 14 | [:delete, :get, :head, :post, :put].each do |verb| 15 | define_method verb do |*args| 16 | request(__method__, *args) 17 | end 18 | end 19 | 20 | def request(verb, path, options = {}) 21 | options = { per_page: PER_PAGE }.merge(options) if verb == :get 22 | Response.new faraday.public_send(verb, path, options) 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/barge/resource/domain.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Domain 4 | include Resource::Base 5 | 6 | def create(options) 7 | post('domains', options.to_json) 8 | end 9 | 10 | def all(options = {}) 11 | get('domains', options) 12 | end 13 | 14 | def show(domain_name) 15 | get("domains/#{domain_name}") 16 | end 17 | 18 | def destroy(domain_name) 19 | delete("domains/#{domain_name}") 20 | end 21 | 22 | def create_record(domain_name, options) 23 | post("domains/#{domain_name}/records", options.to_json) 24 | end 25 | 26 | def records(domain_name, options = {}) 27 | get("domains/#{domain_name}/records", options) 28 | end 29 | 30 | def show_record(domain_name, record_id) 31 | get("domains/#{domain_name}/records/#{record_id}") 32 | end 33 | 34 | def update_record(domain_name, record_id, options) 35 | put("domains/#{domain_name}/records/#{record_id}", options.to_json) 36 | end 37 | 38 | def destroy_record(domain_name, record_id) 39 | delete("domains/#{domain_name}/records/#{record_id}") 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/barge/resource/droplet.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Droplet 4 | include Resource::Base 5 | 6 | def create(options) 7 | post('droplets', options.to_json) 8 | end 9 | 10 | def all(options = {}) 11 | get('droplets', options) 12 | end 13 | 14 | def show(droplet_id) 15 | get("droplets/#{droplet_id}") 16 | end 17 | 18 | def backups(droplet_id) 19 | get("droplets/#{droplet_id}/backups") 20 | end 21 | 22 | def kernels(droplet_id) 23 | get("droplets/#{droplet_id}/kernels") 24 | end 25 | 26 | def snapshots(droplet_id) 27 | get("droplets/#{droplet_id}/snapshots") 28 | end 29 | 30 | def destroy(droplet_id) 31 | delete("droplets/#{droplet_id}") 32 | end 33 | 34 | def rename(droplet_id, options) 35 | action(droplet_id, __method__, options) 36 | end 37 | 38 | def snapshot(droplet_id, options) 39 | action(droplet_id, __method__, options) 40 | end 41 | 42 | def reboot(droplet_id) 43 | action(droplet_id, __method__) 44 | end 45 | 46 | def shutdown(droplet_id) 47 | action(droplet_id, __method__) 48 | end 49 | 50 | def power_off(droplet_id) 51 | action(droplet_id, __method__) 52 | end 53 | 54 | def power_cycle(droplet_id) 55 | action(droplet_id, __method__) 56 | end 57 | 58 | def power_on(droplet_id) 59 | action(droplet_id, __method__) 60 | end 61 | 62 | def resize(droplet_id, options) 63 | action(droplet_id, __method__, options) 64 | end 65 | 66 | def rebuild(droplet_id, options) 67 | action(droplet_id, __method__, options) 68 | end 69 | 70 | def restore(droplet_id, options) 71 | action(droplet_id, __method__, options) 72 | end 73 | 74 | def password_reset(droplet_id) 75 | action(droplet_id, __method__) 76 | end 77 | 78 | def change_kernel(droplet_id, options) 79 | action(droplet_id, __method__, options) 80 | end 81 | 82 | def enable_ipv6(droplet_id) 83 | action(droplet_id, __method__) 84 | end 85 | 86 | def disable_backups(droplet_id) 87 | action(droplet_id, __method__) 88 | end 89 | 90 | def enable_private_networking(droplet_id) 91 | action(droplet_id, __method__) 92 | end 93 | 94 | def actions(droplet_id) 95 | get("droplets/#{droplet_id}/actions") 96 | end 97 | 98 | def show_action(droplet_id, action_id) 99 | get("droplets/#{droplet_id}/actions/#{action_id}") 100 | end 101 | 102 | private 103 | 104 | def action(droplet_id, type, params = {}) 105 | post("droplets/#{droplet_id}/actions", 106 | { type: type }.merge(params).to_json) 107 | end 108 | end 109 | end 110 | end 111 | -------------------------------------------------------------------------------- /lib/barge/resource/floating_ip.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class FloatingIP 4 | include Resource::Base 5 | 6 | def all(options = {}) 7 | get('floating_ips', options) 8 | end 9 | 10 | def create(options) 11 | post('floating_ips', options.to_json) 12 | end 13 | 14 | def show(ip_address) 15 | get("floating_ips/#{ip_address}") 16 | end 17 | 18 | def destroy(ip_address) 19 | delete("floating_ips/#{ip_address}") 20 | end 21 | 22 | def assign(ip_address, options) 23 | action(ip_address, __method__, options) 24 | end 25 | 26 | def unassign(ip_address) 27 | action(ip_address, __method__) 28 | end 29 | 30 | private 31 | 32 | def action(ip_address, type, params = {}) 33 | post("floating_ips/#{ip_address}/actions", 34 | { type: type }.merge(params).to_json) 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/barge/resource/image.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Image 4 | include Resource::Base 5 | 6 | def all(options = {}) 7 | get('images', options) 8 | end 9 | 10 | def show(image_id) 11 | get("images/#{image_id}") 12 | end 13 | 14 | def update(image_id, options) 15 | put("images/#{image_id}", options.to_json) 16 | end 17 | 18 | def destroy(image_id) 19 | delete("images/#{image_id}") 20 | end 21 | 22 | def transfer(image_id, options) 23 | action(image_id, __method__, options) 24 | end 25 | 26 | def show_action(image_id, action_id) 27 | get("images/#{image_id}/actions/#{action_id}") 28 | end 29 | 30 | private 31 | 32 | def action(image_id, type, params = {}) 33 | post("images/#{image_id}/actions", 34 | { type: type }.merge(params).to_json) 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/barge/resource/key.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Key 4 | include Resource::Base 5 | 6 | def create(options) 7 | post('account/keys', options.to_json) 8 | end 9 | 10 | def all 11 | get('account/keys') 12 | end 13 | 14 | def show(key_id) 15 | get("account/keys/#{key_id}") 16 | end 17 | 18 | def update(key_id, options) 19 | put("account/keys/#{key_id}", options.to_json) 20 | end 21 | 22 | def destroy(key_id) 23 | delete("account/keys/#{key_id}") 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/barge/resource/region.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Region 4 | include Resource::Base 5 | 6 | def all 7 | get('regions') 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/barge/resource/size.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | module Resource 3 | class Size 4 | include Resource::Base 5 | 6 | def all 7 | get('sizes') 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/barge/response.rb: -------------------------------------------------------------------------------- 1 | require 'forwardable' 2 | 3 | module Barge 4 | class Response < Hashie::Mash 5 | extend Forwardable 6 | 7 | attr_reader :response 8 | def_delegator :response, :success?, :success? 9 | 10 | def initialize(faraday_response) 11 | @response = faraday_response 12 | super(faraday_response.body) 13 | end 14 | 15 | def paginated? 16 | !(links && links.pages).nil? 17 | end 18 | 19 | def prev_page 20 | extract_page(:prev) 21 | end 22 | 23 | def next_page 24 | extract_page(:next) 25 | end 26 | 27 | def last_page 28 | extract_page(:last) 29 | end 30 | 31 | private 32 | 33 | def extract_page(key) 34 | return unless paginated? && links.pages.key?(key) 35 | Integer links.pages[key][/page=(\d+)/, 1] 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/barge/version.rb: -------------------------------------------------------------------------------- 1 | module Barge 2 | class Version 3 | MAJOR = 0 4 | MINOR = 12 5 | PATCH = 0 6 | 7 | def self.to_s 8 | [MAJOR, MINOR, PATCH].join '.' 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/barge/client_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Client do 4 | let(:token) { 'some_token' } 5 | 6 | describe '#access_token' do 7 | it 'can be set using a hash' do 8 | barge = described_class.new(access_token: token) 9 | expect(barge.access_token).to eq(token) 10 | end 11 | 12 | it 'can be set using a block' do 13 | barge = described_class.new { |c| c.access_token = token } 14 | expect(barge.access_token).to eq(token) 15 | end 16 | 17 | context 'when none is given' do 18 | specify do 19 | expect { described_class.new } 20 | .to raise_error(ArgumentError, 'missing access_token') 21 | end 22 | end 23 | end 24 | 25 | describe '#request_options' do 26 | let(:request_options) { { open_timeout: 100, timeout: 200 } } 27 | 28 | it 'can be set using a hash' do 29 | barge = described_class.new( 30 | access_token: token, 31 | request_options: request_options 32 | ) 33 | expect(barge.request_options).to eq request_options 34 | end 35 | 36 | it 'can be set using a block' do 37 | barge = described_class.new do |c| 38 | c.access_token = token 39 | c.request_options = request_options 40 | end 41 | expect(barge.request_options).to eq request_options 42 | end 43 | 44 | context 'when left out' do 45 | describe 'open_timeout' do 46 | it 'defaults to 10' do 47 | barge = described_class.new(access_token: token) 48 | expect(barge.send(:faraday).options.open_timeout).to eq 10 49 | end 50 | end 51 | 52 | describe 'timeout' do 53 | it 'defaults to 10' do 54 | barge = described_class.new(access_token: token) 55 | expect(barge.send(:faraday).options.timeout).to eq 10 56 | end 57 | end 58 | end 59 | 60 | context 'when only open_timeout is set' do 61 | describe 'timeout' do 62 | it 'defaults to 10' do 63 | barge = described_class.new( 64 | access_token: token, 65 | request_options: { open_timeout: 20 } 66 | ) 67 | expect(barge.send(:faraday).options.timeout).to eq 10 68 | end 69 | end 70 | end 71 | 72 | context 'when only timeout is set' do 73 | describe 'open_timeout' do 74 | it 'defaults to 10' do 75 | barge = described_class.new( 76 | access_token: token, 77 | request_options: { timeout: 20 } 78 | ) 79 | expect(barge.send(:faraday).options.open_timeout).to eq 10 80 | end 81 | end 82 | end 83 | 84 | it "is used to set faraday's request options" do 85 | barge = described_class.new do |c| 86 | c.access_token = token 87 | c.request_options = request_options 88 | end 89 | expect(barge.send(:faraday).options.open_timeout).to be 100 90 | expect(barge.send(:faraday).options.timeout).to be 200 91 | end 92 | end 93 | 94 | describe '#faraday' do 95 | it 'is a Faraday::Connection object' do 96 | barge = described_class.new(access_token: token) 97 | expect(barge.faraday).to be_a Faraday::Connection 98 | end 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /spec/barge/resource/account_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Account do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#show' do 8 | it 'returns information about the account' do 9 | stubbed_request = 10 | stub_request!(:get, '/account') 11 | .to_return(body: fixture('account/show'), status: 200) 12 | expect(account.show.account.droplet_limit).to be 25 13 | expect(stubbed_request).to have_been_requested 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/barge/resource/action_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Action do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#all' do 8 | it 'lists all actions' do 9 | stubbed_request = 10 | stub_request!(:get, '/actions') 11 | .to_return(body: fixture('actions/all'), status: 200) 12 | expect(action.all.actions) 13 | .to include a_hash_including(status: 'in-progress') 14 | expect(stubbed_request).to have_been_requested 15 | end 16 | 17 | it 'accepts an options hash' do 18 | stubbed_request = 19 | stub_request!(:get, '/actions?per_page=5&page=2') 20 | .to_return(body: fixture('actions/all'), status: 200) 21 | expect(action.all(per_page: 5, page: 2).actions) 22 | .to include a_hash_including(status: 'in-progress') 23 | expect(stubbed_request).to have_been_requested 24 | end 25 | end 26 | 27 | describe '#show' do 28 | it 'shows information about a specific action' do 29 | stubbed_request = 30 | stub_request!(:get, '/actions/10') 31 | .to_return(body: fixture('actions/show'), status: 200) 32 | expect(action.show(10).action).to include resource_type: 'backend' 33 | expect(stubbed_request).to have_been_requested 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /spec/barge/resource/base_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | module Barge 4 | module Resource 5 | class Dummy 6 | include Barge::Resource::Base 7 | 8 | def dummy 9 | get('dummy') 10 | end 11 | end 12 | end 13 | end 14 | 15 | describe Barge::Resource::Base do 16 | include_context 'resource' 17 | 18 | context 'using a dummy resource' do 19 | let(:dummy) { Barge::Resource::Dummy.new(barge.send(:faraday)) } 20 | 21 | describe '#request' do 22 | before { stub_request!(:get, '/dummy').to_return(status: 200) } 23 | let(:result) { dummy.dummy } 24 | 25 | describe '#response' do 26 | specify { expect(result.response).to be_instance_of Faraday::Response } 27 | 28 | describe '#status' do 29 | specify { expect(result.response.status).to be 200 } 30 | end 31 | end 32 | 33 | describe '#success?' do 34 | it 'delegates to #response' do 35 | expect(result.response).to receive(:success?) 36 | result.success? 37 | end 38 | end 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /spec/barge/resource/domain_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Domain do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#create' do 8 | it 'creates a domain' do 9 | stubbed_request = 10 | stub_request!(:post, '/domains') 11 | .to_return(body: fixture('domains/create'), status: 201) 12 | options = { name: 'example.com', ip_address: '1.2.3.4' } 13 | expect(domain.create(options).domain.name).to eq 'example.com' 14 | expect(stubbed_request.with(body: options.to_json)) 15 | .to have_been_requested 16 | end 17 | end 18 | 19 | describe '#all' do 20 | it 'lists all domains' do 21 | stubbed_request = 22 | stub_request!(:get, '/domains') 23 | .to_return(body: fixture('domains/all'), status: 200) 24 | expect(domain.all.domains).to include a_hash_including('ttl' => 1800) 25 | expect(stubbed_request).to have_been_requested 26 | end 27 | 28 | it 'accepts an options hash' do 29 | stubbed_request = 30 | stub_request!(:get, '/domains?per_page=4&page=8') 31 | .to_return(body: fixture('domains/all'), status: 200) 32 | expect(domain.all(per_page: 4, page: 8).domains) 33 | .to include a_hash_including('ttl' => 1800) 34 | expect(stubbed_request).to have_been_requested 35 | end 36 | end 37 | 38 | describe '#show' do 39 | it 'shows a domain' do 40 | stubbed_request = 41 | stub_request!(:get, '/domains/example.com') 42 | .to_return(body: fixture('domains/show'), status: 200) 43 | expect(domain.show('example.com').domain.zone_file) 44 | .to eq 'Example zone file text...' 45 | expect(stubbed_request).to have_been_requested 46 | end 47 | end 48 | 49 | describe '#destroy' do 50 | it 'destroys a domain' do 51 | stubbed_request = 52 | stub_request!(:delete, '/domains/example.com') 53 | .to_return(status: 204) 54 | expect(domain.destroy('example.com').success?).to be true 55 | expect(stubbed_request).to have_been_requested 56 | end 57 | end 58 | 59 | describe '#create_record' do 60 | it 'creates a record' do 61 | stubbed_request = 62 | stub_request!(:post, '/domains/example.com/records') 63 | .to_return(body: fixture('domains/create_record'), status: 201) 64 | options = { name: 'test', data: '1.2.3.4', type: 'A' } 65 | expect(domain.create_record('example.com', options).domain_record.type) 66 | .to eq 'AAAA' 67 | expect(stubbed_request.with(body: options.to_json)) 68 | .to have_been_requested 69 | end 70 | end 71 | 72 | describe '#records' do 73 | it 'lists all domains records' do 74 | stubbed_request = 75 | stub_request!(:get, '/domains/example.com/records') 76 | .to_return(body: fixture('domains/records'), status: 200) 77 | expect(domain.records('example.com').domain_records) 78 | .to include a_hash_including(data: '8.8.8.8') 79 | expect(stubbed_request).to have_been_requested 80 | end 81 | 82 | it 'accepts an options hash' do 83 | stubbed_request = 84 | stub_request!(:get, '/domains/example.com/records?per_page=1&page=2') 85 | .to_return(body: fixture('domains/records'), status: 200) 86 | expect(domain.records('example.com', per_page: 1, page: 2) 87 | .domain_records).to include a_hash_including(data: '8.8.8.8') 88 | expect(stubbed_request).to have_been_requested 89 | end 90 | end 91 | 92 | describe '#show_record' do 93 | it 'shows a record' do 94 | stubbed_request = 95 | stub_request!(:get, '/domains/example.com/records/5') 96 | .to_return(body: fixture('domains/show_record'), status: 200) 97 | expect(domain.show_record('example.com', 5).domain_record.type) 98 | .to eq 'CNAME' 99 | expect(stubbed_request).to have_been_requested 100 | end 101 | end 102 | 103 | describe '#update_record' do 104 | it 'updates a record' do 105 | stubbed_request = 106 | stub_request!(:put, '/domains/example.com/records/10') 107 | .to_return(body: fixture('domains/update_record'), status: 200) 108 | options = { name: 'new_name' } 109 | expect(domain.update_record('example.com', 10, options).domain_record.id) 110 | .to be 26 111 | expect(stubbed_request.with(body: options.to_json)) 112 | .to have_been_requested 113 | end 114 | end 115 | 116 | describe '#destroy_record' do 117 | it 'destroys a record' do 118 | stubbed_request = 119 | stub_request!(:delete, '/domains/example.com/records/20') 120 | .to_return(status: 204) 121 | expect(domain.destroy_record('example.com', 20).success?).to be true 122 | expect(stubbed_request).to have_been_requested 123 | end 124 | end 125 | end 126 | -------------------------------------------------------------------------------- /spec/barge/resource/droplet_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Droplet do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#create' do 8 | it 'creates a droplet' do 9 | stubbed_request = 10 | stub_request!(:post, '/droplets') 11 | .to_return(body: fixture('droplets/create'), status: 202) 12 | options = { name: 'x', image: 123 } 13 | expect(droplet.create(options).droplet.id).to be 24 14 | expect(stubbed_request.with(body: options.to_json)) 15 | .to have_been_requested 16 | end 17 | end 18 | 19 | describe '#all' do 20 | it 'lists all droplets' do 21 | stubbed_request = 22 | stub_request!(:get, '/droplets') 23 | .to_return(body: fixture('droplets/all'), status: 200) 24 | expect(droplet.all.droplets) 25 | .to include a_hash_including(name: 'test.example.com') 26 | expect(stubbed_request).to have_been_requested 27 | end 28 | 29 | it 'accepts an options hash' do 30 | stubbed_request = 31 | stub_request!(:get, '/droplets?per_page=3&page=5') 32 | .to_return(body: fixture('droplets/all'), status: 200) 33 | expect(droplet.all(per_page: 3, page: 5).droplets) 34 | .to include a_hash_including(name: 'test.example.com') 35 | expect(stubbed_request).to have_been_requested 36 | end 37 | end 38 | 39 | describe '#show' do 40 | it 'returns information about a specific droplet' do 41 | stubbed_request = 42 | stub_request!(:get, '/droplets/10') 43 | .to_return(body: fixture('droplets/show'), status: 200) 44 | expect(droplet.show(10).droplet.name).to eq 'test.example.com' 45 | expect(stubbed_request).to have_been_requested 46 | end 47 | end 48 | 49 | describe '#backups' do 50 | it 'shows droplet backups' do 51 | stubbed_request = 52 | stub_request!(:get, '/droplets/33/backups') 53 | .to_return(body: fixture('droplets/backups'), status: 200) 54 | expect(droplet.backups(33).backups) 55 | .to include a_hash_including(distribution: 'ubuntu') 56 | expect(stubbed_request).to have_been_requested 57 | end 58 | end 59 | 60 | describe '#kernels' do 61 | it 'shows available kernels' do 62 | stubbed_request = 63 | stub_request!(:get, '/droplets/52/kernels') 64 | .to_return(body: fixture('droplets/kernels'), status: 200) 65 | expect(droplet.kernels(52).kernels) 66 | .to include a_hash_including(version: '3.13.0-24-generic') 67 | expect(stubbed_request).to have_been_requested 68 | end 69 | end 70 | 71 | describe '#snapshots' do 72 | it 'shows droplet snapshots' do 73 | stubbed_request = 74 | stub_request!(:get, '/droplets/34/snapshots') 75 | .to_return(body: fixture('droplets/snapshots'), status: 200) 76 | expect(droplet.snapshots(34).snapshots) 77 | .to include a_hash_including(distribution: 'ubuntu') 78 | expect(stubbed_request).to have_been_requested 79 | end 80 | end 81 | 82 | describe '#destroy' do 83 | it 'destroys a droplet' do 84 | stubbed_request = 85 | stub_request!(:delete, '/droplets/11').to_return(status: 202) 86 | expect(droplet.destroy(11).success?).to be true 87 | expect(stubbed_request).to have_been_requested 88 | end 89 | end 90 | 91 | describe '#rename' do 92 | it 'renames a droplet' do 93 | stubbed_request = 94 | stub_request!(:post, '/droplets/12/actions') 95 | .to_return(body: fixture('droplets/rename'), status: 200) 96 | expect(droplet.rename(12, name: 'new_name').action.type).to eq 'rename' 97 | expect(stubbed_request 98 | .with(body: { type: :rename, name: :new_name }.to_json)) 99 | .to have_been_requested 100 | end 101 | end 102 | 103 | describe '#snapshot' do 104 | it 'create a snapshot of a droplet' do 105 | stubbed_request = 106 | stub_request!(:post, '/droplets/36/actions') 107 | .to_return(body: fixture('droplets/snapshot'), status: 200) 108 | expect(droplet.snapshot(36, name: 'image_name').action.type) 109 | .to eq 'snapshot' 110 | expect(stubbed_request 111 | .with(body: { type: :snapshot, name: :image_name }.to_json)) 112 | .to have_been_requested 113 | end 114 | end 115 | 116 | describe '#reboot' do 117 | it 'reboots a droplet' do 118 | stubbed_request = 119 | stub_request!(:post, '/droplets/13/actions') 120 | .to_return(body: fixture('droplets/reboot'), status: 200) 121 | expect(droplet.reboot(13).action.type).to eq 'reboot' 122 | expect(stubbed_request 123 | .with(body: { type: :reboot }.to_json)).to have_been_requested 124 | end 125 | end 126 | 127 | describe '#shutdown' do 128 | it 'shuts down a droplet' do 129 | stubbed_request = 130 | stub_request!(:post, '/droplets/20/actions') 131 | .to_return(body: fixture('droplets/shutdown'), status: 200) 132 | expect(droplet.shutdown(20).action.type).to eq 'shutdown' 133 | expect(stubbed_request 134 | .with(body: { type: :shutdown }.to_json)).to have_been_requested 135 | end 136 | end 137 | 138 | describe '#power_off' do 139 | it 'powers off a droplet' do 140 | stubbed_request = 141 | stub_request!(:post, '/droplets/14/actions') 142 | .to_return(body: fixture('droplets/power_off'), status: 200) 143 | expect(droplet.power_off(14).action.type).to eq 'power_off' 144 | expect(stubbed_request 145 | .with(body: { type: :power_off }.to_json)).to have_been_requested 146 | end 147 | end 148 | 149 | describe '#power_cycle' do 150 | it 'powers cycles a droplet' do 151 | stubbed_request = 152 | stub_request!(:post, '/droplets/15/actions') 153 | .to_return(body: fixture('droplets/power_cycle'), status: 200) 154 | expect(droplet.power_cycle(15).action.type).to eq 'power_cycle' 155 | expect(stubbed_request 156 | .with(body: { type: :power_cycle }.to_json)).to have_been_requested 157 | end 158 | end 159 | 160 | describe '#power_on' do 161 | it 'powers on a droplet' do 162 | stubbed_request = 163 | stub_request!(:post, '/droplets/15/actions') 164 | .to_return(body: fixture('droplets/power_on'), status: 200) 165 | expect(droplet.power_on(15).action.type).to eq 'power_on' 166 | expect(stubbed_request 167 | .with(body: { type: :power_on }.to_json)).to have_been_requested 168 | end 169 | end 170 | 171 | describe '#resize' do 172 | it 'resizes a droplet' do 173 | stubbed_request = 174 | stub_request!(:post, '/droplets/17/actions') 175 | .to_return(body: fixture('droplets/resize'), status: 200) 176 | expect(droplet.resize(17, size: '1024m').action.type).to eq 'resize' 177 | expect(stubbed_request 178 | .with(body: { type: :resize, size: '1024m' }.to_json)) 179 | .to have_been_requested 180 | end 181 | end 182 | 183 | describe '#rebuild' do 184 | it 'rebuilds a droplet' do 185 | stubbed_request = 186 | stub_request!(:post, '/droplets/18/actions') 187 | .to_return(body: fixture('droplets/rebuild'), status: 200) 188 | expect(droplet.rebuild(18, image: 100).action.type).to eq 'rebuild' 189 | expect(stubbed_request 190 | .with(body: { type: :rebuild, image: 100 }.to_json)) 191 | .to have_been_requested 192 | end 193 | end 194 | 195 | describe '#restore' do 196 | it 'restores a droplet' do 197 | stubbed_request = 198 | stub_request!(:post, '/droplets/19/actions') 199 | .to_return(body: fixture('droplets/restore'), status: 200) 200 | expect(droplet.restore(19, image: 101).action.type).to eq 'restore' 201 | expect(stubbed_request 202 | .with(body: { type: :restore, image: 101 }.to_json)) 203 | .to have_been_requested 204 | end 205 | end 206 | 207 | describe '#password_reset' do 208 | it "resets a droplet's password" do 209 | stubbed_request = 210 | stub_request!(:post, '/droplets/21/actions') 211 | .to_return(body: fixture('droplets/password_reset'), status: 200) 212 | expect(droplet.password_reset(21).action.type).to eq 'password_reset' 213 | expect(stubbed_request 214 | .with(body: { type: :password_reset }.to_json)).to have_been_requested 215 | end 216 | end 217 | 218 | describe '#change_kernel' do 219 | it 'changes the kernel' do 220 | stubbed_request = 221 | stub_request!(:post, '/droplets/219/actions') 222 | .to_return(body: fixture('droplets/change_kernel'), status: 200) 223 | expect(droplet.change_kernel(219, kernel: 313).action) 224 | .to include type: 'change_kernel' 225 | expect(stubbed_request 226 | .with(body: { type: :change_kernel, kernel: 313 }.to_json)) 227 | .to have_been_requested 228 | end 229 | end 230 | 231 | describe '#enable_ipv6' do 232 | it 'enables IPv6' do 233 | stubbed_request = 234 | stub_request!(:post, '/droplets/220/actions') 235 | .to_return(body: fixture('droplets/enable_ipv6'), status: 200) 236 | expect(droplet.enable_ipv6(220).action).to include type: 'enable_ipv6' 237 | expect(stubbed_request.with(body: { type: :enable_ipv6 }.to_json)) 238 | .to have_been_requested 239 | end 240 | end 241 | 242 | describe '#disable_backups' do 243 | it 'disables backups' do 244 | stubbed_request = 245 | stub_request!(:post, '/droplets/221/actions') 246 | .to_return(body: fixture('droplets/disable_backups'), status: 200) 247 | expect(droplet.disable_backups(221).action.type).to eq 'disable_backups' 248 | expect(stubbed_request.with(body: { type: :disable_backups }.to_json)) 249 | .to have_been_requested 250 | end 251 | end 252 | 253 | describe '#enable_private_networking' do 254 | it 'enables private networking' do 255 | to_return = { 256 | body: fixture('droplets/enable_private_networking'), status: 200 257 | } 258 | stubbed_request = 259 | stub_request!(:post, '/droplets/222/actions').to_return(to_return) 260 | expect(droplet.enable_private_networking(222).action.type) 261 | .to eq 'enable_private_networking' 262 | expect(stubbed_request 263 | .with(body: { type: :enable_private_networking }.to_json)) 264 | .to have_been_requested 265 | end 266 | end 267 | 268 | describe '#actions' do 269 | it 'shows droplet actions' do 270 | stubbed_request = 271 | stub_request!(:get, '/droplets/51/actions') 272 | .to_return(body: fixture('droplets/actions'), status: 200) 273 | expect(droplet.actions(51).actions) 274 | .to include a_hash_including(resource_id: 23) 275 | expect(stubbed_request).to have_been_requested 276 | end 277 | end 278 | 279 | describe '#show_action' do 280 | it 'shows action information' do 281 | stubbed_request = 282 | stub_request!(:get, '/droplets/30/actions/40') 283 | .to_return(body: fixture('droplets/show_action'), status: 200) 284 | expect(droplet.show_action(30, 40).action.type).to eq 'create' 285 | expect(stubbed_request).to have_been_requested 286 | end 287 | end 288 | end 289 | -------------------------------------------------------------------------------- /spec/barge/resource/floating_ip_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::FloatingIP do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#all' do 8 | it 'lists all floating IPs' do 9 | stubbed_request = 10 | stub_request!(:get, '/floating_ips') 11 | .to_return(body: fixture('floating_ips/all'), status: 200) 12 | expect(floating_ip.all.floating_ips) 13 | .to include a_hash_including(ip: '10.20.30.40') 14 | expect(stubbed_request).to have_been_requested 15 | end 16 | 17 | it 'accepts an options hash' do 18 | stubbed_request = 19 | stub_request!(:get, '/floating_ips?per_page=3&page=5') 20 | .to_return(body: fixture('floating_ips/all'), status: 200) 21 | expect(floating_ip.all(per_page: 3, page: 5).floating_ips) 22 | .to include a_hash_including(ip: '10.20.30.40') 23 | expect(stubbed_request).to have_been_requested 24 | end 25 | end 26 | 27 | describe '#create' do 28 | it 'creates a floating IP' do 29 | stubbed_request = 30 | stub_request!(:post, '/floating_ips') 31 | .to_return(body: fixture('floating_ips/create'), status: 202) 32 | options = { region: 'lon1' } 33 | expect(floating_ip.create(options).floating_ip.ip).to eq '10.20.30.40' 34 | expect(stubbed_request.with(body: options.to_json)) 35 | .to have_been_requested 36 | end 37 | end 38 | 39 | describe '#show' do 40 | it 'returns information about a specific floating IP' do 41 | stubbed_request = 42 | stub_request!(:get, '/floating_ips/10.20.30.40') 43 | .to_return(body: fixture('floating_ips/show'), status: 200) 44 | expect(floating_ip.show('10.20.30.40').floating_ip.ip) 45 | .to eq '10.20.30.40' 46 | expect(stubbed_request).to have_been_requested 47 | end 48 | end 49 | 50 | describe '#destroy' do 51 | it 'destroys a floating IP' do 52 | stubbed_request = 53 | stub_request!(:delete, '/floating_ips/1.2.3.4').to_return(status: 202) 54 | expect(floating_ip.destroy('1.2.3.4').success?).to be true 55 | expect(stubbed_request).to have_been_requested 56 | end 57 | end 58 | 59 | describe '#assign' do 60 | it 'assigns a floating IP to a droplet' do 61 | stubbed_request = 62 | stub_request!(:post, '/floating_ips/1.2.3.4/actions') 63 | .to_return(body: fixture('floating_ips/assign'), status: 200) 64 | expect(floating_ip.assign('1.2.3.4', droplet_id: 123).action.region_slug) 65 | .to eq 'nyc3' 66 | expect(stubbed_request 67 | .with(body: { type: :assign, droplet_id: 123 }.to_json)) 68 | .to have_been_requested 69 | end 70 | end 71 | 72 | describe '#unassign' do 73 | it 'unassigns a floating IP' do 74 | stubbed_request = 75 | stub_request!(:post, '/floating_ips/5.6.7.8/actions') 76 | .to_return(body: fixture('floating_ips/unassign'), status: 200) 77 | expect(floating_ip.unassign('5.6.7.8').action.type) 78 | .to eq 'unassign_ip' 79 | expect(stubbed_request 80 | .with(body: { type: :unassign }.to_json)) 81 | .to have_been_requested 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /spec/barge/resource/image_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Image do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#all' do 8 | it 'lists all images' do 9 | stubbed_request = 10 | stub_request!(:get, '/images') 11 | .to_return(body: fixture('images/all'), status: 200) 12 | expect(image.all.images) 13 | .to include a_hash_including(name: 'Ubuntu 13.04') 14 | expect(stubbed_request).to have_been_requested 15 | end 16 | 17 | it 'accepts an options hash' do 18 | stubbed_request = 19 | stub_request!(:get, '/images?per_page=20&page=10&private=true') 20 | .to_return(body: fixture('images/all'), status: 200) 21 | expect(image.all(per_page: 20, page: 10, private: true).images) 22 | .to include a_hash_including(name: 'Ubuntu 13.04') 23 | expect(stubbed_request).to have_been_requested 24 | end 25 | end 26 | 27 | describe '#show' do 28 | it 'returns information about a given image' do 29 | stubbed_request = 30 | stub_request!(:get, '/images/100') 31 | .to_return(body: fixture('images/show'), status: 200) 32 | expect(image.show(100).image.name).to eq 'Ubuntu 13.04' 33 | expect(stubbed_request).to have_been_requested 34 | end 35 | end 36 | 37 | describe '#update' do 38 | it 'updates an image' do 39 | stubbed_request = 40 | stub_request!(:put, '/images/101') 41 | .to_return(body: fixture('images/update'), status: 200) 42 | options = { name: 'New Image Name' } 43 | expect(image.update(101, options).image.name).to eq 'New Image Name' 44 | expect(stubbed_request.with(body: options.to_json)) 45 | .to have_been_requested 46 | end 47 | end 48 | 49 | describe '#destroy' do 50 | it 'destroys an image' do 51 | stubbed_request = 52 | stub_request!(:delete, '/images/102').to_return(status: 200) 53 | expect(image.destroy(102).success?).to be true 54 | expect(stubbed_request).to have_been_requested 55 | end 56 | end 57 | 58 | describe '#transfer' do 59 | it 'transfers an image to another region' do 60 | stubbed_request = 61 | stub_request!(:post, '/images/103/actions') 62 | .to_return(body: fixture('images/transfer'), status: 200) 63 | expect(image.transfer(103, region: 'sfo1').action.type).to eq 'transfer' 64 | expect(stubbed_request 65 | .with(body: { type: :transfer, region: 'sfo1' }.to_json)) 66 | .to have_been_requested 67 | end 68 | end 69 | 70 | describe '#show_action' do 71 | it 'shows action information' do 72 | stubbed_request = 73 | stub_request!(:get, '/images/104/actions/200') 74 | .to_return(body: fixture('images/show_action'), status: 200) 75 | expect(image.show_action(104, 200).action.type).to eq 'transfer' 76 | expect(stubbed_request).to have_been_requested 77 | end 78 | end 79 | end 80 | -------------------------------------------------------------------------------- /spec/barge/resource/key_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Key do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#create' do 8 | it 'creates a key' do 9 | stubbed_request = 10 | stub_request!(:post, '/account/keys') 11 | .to_return(body: fixture('keys/create'), status: 200) 12 | options = { name: 'default', public_key: 'ssh-rsa AAAAB3N...' } 13 | expect(key.create(options).ssh_key.id).to be 3 14 | expect(stubbed_request.with(body: options.to_json)) 15 | .to have_been_requested 16 | end 17 | end 18 | 19 | describe '#all' do 20 | it 'lists all keys' do 21 | stubbed_request = 22 | stub_request!(:get, '/account/keys') 23 | .to_return(body: fixture('keys/all'), status: 200) 24 | expect(key.all.ssh_keys).to include a_hash_including(name: 'Example Key') 25 | expect(stubbed_request).to have_been_requested 26 | end 27 | end 28 | 29 | describe '#show' do 30 | it 'returns information about a given key' do 31 | stubbed_request = 32 | stub_request!(:get, '/account/keys/100') 33 | .to_return(body: fixture('keys/show'), status: 200) 34 | expect(key.show(100).ssh_key.name).to eq 'Example Key' 35 | expect(stubbed_request).to have_been_requested 36 | end 37 | end 38 | 39 | describe '#update' do 40 | it 'updates a key' do 41 | stubbed_request = 42 | stub_request!(:put, '/account/keys/115') 43 | .to_return(body: fixture('keys/update'), status: 200) 44 | options = { name: 'new_key_name' } 45 | expect(key.update(115, options).ssh_key.id).to be 5 46 | expect(stubbed_request.with(body: options.to_json)) 47 | .to have_been_requested 48 | end 49 | end 50 | 51 | describe '#destroy' do 52 | it 'destroys a key' do 53 | stubbed_request = 54 | stub_request!(:delete, '/account/keys/101').to_return(status: 200) 55 | expect(key.destroy(101).success?).to be true 56 | expect(stubbed_request).to have_been_requested 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/barge/resource/region_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Region do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#all' do 8 | it 'lists all regions' do 9 | stubbed_request = 10 | stub_request!(:get, '/regions') 11 | .to_return(body: fixture('regions/all'), status: 200) 12 | expect(region.all.regions).to include a_hash_including('slug' => 'ams1') 13 | expect(stubbed_request).to have_been_requested 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/barge/resource/size_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Resource::Size do 4 | include_context 'resource' 5 | it_behaves_like 'a resource' 6 | 7 | describe '#all' do 8 | it 'lists all sizes' do 9 | stubbed_request = 10 | stub_request!(:get, '/sizes') 11 | .to_return(body: fixture('sizes/all'), status: 200) 12 | expect(size.all.sizes) 13 | .to include a_hash_including('price_monthly' => '5.0') 14 | expect(stubbed_request).to have_been_requested 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/barge/response_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge::Response do 4 | let(:faraday_response) do 5 | Hashie::Mash.new(body: { foo: 'bar' }, success?: 123) 6 | end 7 | 8 | let(:response) { Barge::Response.new(faraday_response) } 9 | 10 | specify { expect(response).to include foo: 'bar' } 11 | 12 | describe '#response' do 13 | it 'is the argument given to .new' do 14 | expect(response.response).to be faraday_response 15 | end 16 | end 17 | 18 | describe '#success?' do 19 | specify { expect(response.success?).to be 123 } 20 | 21 | it 'delegates' do 22 | expect(response.response).to receive(:success?) 23 | response.success? 24 | end 25 | end 26 | 27 | context 'pagination' do 28 | context 'response without pagination' do 29 | let(:response) do 30 | Barge::Response.new(Hashie::Mash.new(body: { links: {} })) 31 | end 32 | 33 | describe '#paginated?' do 34 | specify { expect(response.paginated?).to be false } 35 | end 36 | 37 | describe '#prev_page' do 38 | specify { expect(response.prev_page).to be nil } 39 | end 40 | 41 | describe '#next_page' do 42 | specify { expect(response.next_page).to be nil } 43 | end 44 | 45 | describe '#last_page' do 46 | specify { expect(response.last_page).to be nil } 47 | end 48 | end 49 | 50 | context 'response with pagination' do 51 | let(:response) do 52 | Barge::Response.new( 53 | Hashie::Mash.new( 54 | body: { 55 | links: { 56 | pages: { 57 | prev: '&page=10x', 58 | next: '&page=20y', 59 | last: '&page=30z' 60 | } 61 | } 62 | } 63 | ) 64 | ) 65 | end 66 | 67 | describe '#paginated?' do 68 | specify { expect(response.paginated?).to be true } 69 | end 70 | 71 | describe '#prev_page' do 72 | it 'returns the previous page number' do 73 | expect(response.prev_page).to be 10 74 | end 75 | end 76 | 77 | describe '#next_page' do 78 | it 'returns the next page number' do 79 | expect(response.next_page).to be 20 80 | end 81 | end 82 | 83 | describe '#last_page' do 84 | it 'returns the last page number' do 85 | expect(response.last_page).to be 30 86 | end 87 | end 88 | end 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /spec/barge/version_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'Barge::Version' do 4 | describe '.to_s' do 5 | it 'returns a version string' do 6 | expect(Barge::Version.to_s).to match(/\A\d+\.\d+\.\d+/) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/barge_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Barge do 4 | end 5 | -------------------------------------------------------------------------------- /spec/fixtures/account/show.json: -------------------------------------------------------------------------------- 1 | { 2 | "account": { 3 | "droplet_limit": 25, 4 | "email": "web@digitalocean.com", 5 | "email_verified": true, 6 | "uuid": "b6fc48dbf6d9906cace5f3c78dc9851e757381ef" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /spec/fixtures/actions/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "actions": [ 3 | { 4 | "completed_at": null, 5 | "id": 1, 6 | "region": "nyc1", 7 | "resource_id": null, 8 | "resource_type": "backend", 9 | "started_at": "2014-07-02T16:10:17Z", 10 | "status": "in-progress", 11 | "type": "test" 12 | } 13 | ], 14 | "meta": { 15 | "total": 1 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spec/fixtures/actions/show.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 2, 5 | "region": "nyc1", 6 | "resource_id": null, 7 | "resource_type": "backend", 8 | "started_at": "2014-07-02T16:10:17Z", 9 | "status": "in-progress", 10 | "type": "test" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/domains/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "domains": [ 3 | { 4 | "name": "example.com", 5 | "ttl": 1800, 6 | "zone_file": "Example zone file text..." 7 | } 8 | ], 9 | "meta": { 10 | "total": 1 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/domains/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain": { 3 | "name": "example.com", 4 | "ttl": 1800, 5 | "zone_file": null 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /spec/fixtures/domains/create_record.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain_record": { 3 | "data": "2001:db8::ff00:42:8329", 4 | "id": 16, 5 | "name": "subdomain", 6 | "port": null, 7 | "priority": null, 8 | "type": "AAAA", 9 | "weight": null 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /spec/fixtures/domains/records.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain_records": [ 3 | { 4 | "data": "8.8.8.8", 5 | "id": 1, 6 | "name": "@", 7 | "port": null, 8 | "priority": null, 9 | "type": "A", 10 | "weight": null 11 | }, 12 | { 13 | "data": "NS1.DIGITALOCEAN.COM.", 14 | "id": 2, 15 | "name": null, 16 | "port": null, 17 | "priority": null, 18 | "type": "NS", 19 | "weight": null 20 | }, 21 | { 22 | "data": "NS2.DIGITALOCEAN.COM.", 23 | "id": 3, 24 | "name": null, 25 | "port": null, 26 | "priority": null, 27 | "type": "NS", 28 | "weight": null 29 | }, 30 | { 31 | "data": "NS3.DIGITALOCEAN.COM.", 32 | "id": 4, 33 | "name": null, 34 | "port": null, 35 | "priority": null, 36 | "type": "NS", 37 | "weight": null 38 | }, 39 | { 40 | "data": "@", 41 | "id": 5, 42 | "name": "example", 43 | "port": null, 44 | "priority": null, 45 | "type": "CNAME", 46 | "weight": null 47 | } 48 | ], 49 | "meta": { 50 | "total": 5 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /spec/fixtures/domains/show.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain": { 3 | "name": "example.com", 4 | "ttl": 1800, 5 | "zone_file": "Example zone file text..." 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /spec/fixtures/domains/show_record.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain_record": { 3 | "data": "@", 4 | "id": 10, 5 | "name": "example", 6 | "port": null, 7 | "priority": null, 8 | "type": "CNAME", 9 | "weight": null 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /spec/fixtures/domains/update_record.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain_record": { 3 | "data": "@", 4 | "id": 26, 5 | "name": "new_name", 6 | "port": null, 7 | "priority": null, 8 | "type": "CNAME", 9 | "weight": null 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/actions.json: -------------------------------------------------------------------------------- 1 | { 2 | "actions": [ 3 | { 4 | "completed_at": null, 5 | "id": 18, 6 | "region": "nyc1", 7 | "resource_id": 23, 8 | "resource_type": "droplet", 9 | "started_at": "2014-07-02T16:10:24Z", 10 | "status": "in-progress", 11 | "type": "create" 12 | } 13 | ], 14 | "meta": { 15 | "total": 1 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "droplets": [ 3 | { 4 | "action_ids": [], 5 | "backup_ids": [ 6 | 449676381 7 | ], 8 | "created_at": "2014-07-02T16:10:23Z", 9 | "id": 18, 10 | "image": { 11 | "created_at": "2014-07-02T16:10:23Z", 12 | "distribution": "ubuntu", 13 | "id": 119192817, 14 | "name": "Ubuntu 13.04", 15 | "public": true, 16 | "regions": [ 17 | "nyc1" 18 | ], 19 | "slug": "ubuntu1304" 20 | }, 21 | "kernel": { 22 | "id": 485432985, 23 | "name": "DO-recovery-static-fsck", 24 | "version": "3.8.0-25-generic" 25 | }, 26 | "locked": false, 27 | "name": "test.example.com", 28 | "networks": { 29 | "v4": [ 30 | { 31 | "gateway": "127.0.0.14", 32 | "ip_address": "127.0.0.13", 33 | "netmask": "255.255.255.0", 34 | "type": "public" 35 | } 36 | ], 37 | "v6": [ 38 | { 39 | "cidr": 124, 40 | "gateway": "2400:6180:0000:00D0:0000:0000:0009:7000", 41 | "ip_address": "2001::13", 42 | "type": "public" 43 | } 44 | ] 45 | }, 46 | "region": { 47 | "available": true, 48 | "features": [ 49 | "virtio", 50 | "private_networking", 51 | "backups", 52 | "ipv6" 53 | ], 54 | "name": "New York", 55 | "sizes": [ 56 | "1024mb", 57 | "512mb" 58 | ], 59 | "slug": "nyc1" 60 | }, 61 | "size": { 62 | "disk": 20, 63 | "memory": 512, 64 | "price_hourly": "0.00744", 65 | "price_monthly": "5.0", 66 | "regions": [ 67 | "nyc1", 68 | "sfo1", 69 | "ams1" 70 | ], 71 | "slug": "512mb", 72 | "transfer": null, 73 | "vcpus": 1 74 | }, 75 | "snapshot_ids": [ 76 | 449676382 77 | ], 78 | "status": "active" 79 | } 80 | ], 81 | "meta": { 82 | "total": 1 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/backups.json: -------------------------------------------------------------------------------- 1 | { 2 | "backups": [ 3 | { 4 | "created_at": "2014-07-02T16:10:24Z", 5 | "distribution": "ubuntu", 6 | "id": 449676387, 7 | "name": "Ubuntu 13.04", 8 | "public": false, 9 | "regions": [ 10 | "nyc1" 11 | ], 12 | "slug": null 13 | } 14 | ], 15 | "meta": { 16 | "total": 1 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/change_kernel.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 14, 5 | "region": "nyc1", 6 | "resource_id": 14, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:22Z", 9 | "status": "in-progress", 10 | "type": "change_kernel" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "droplet": { 3 | "action_ids": [ 4 | 19 5 | ], 6 | "backup_ids": [], 7 | "created_at": "2014-07-02T16:10:24Z", 8 | "id": 24, 9 | "image": { 10 | "created_at": "2014-07-02T16:10:24Z", 11 | "distribution": "ubuntu", 12 | "id": 449676388, 13 | "name": "Ubuntu 13.04", 14 | "public": true, 15 | "regions": [ 16 | "nyc1" 17 | ], 18 | "slug": null 19 | }, 20 | "kernel": { 21 | "id": 485432972, 22 | "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-24-generic (1221)", 23 | "version": "3.13.0-24-generic" 24 | }, 25 | "locked": false, 26 | "name": "My-Droplet", 27 | "networks": {}, 28 | "region": { 29 | "available": true, 30 | "features": [ 31 | "virtio", 32 | "private_networking", 33 | "backups", 34 | "ipv6" 35 | ], 36 | "name": "New York", 37 | "sizes": [ 38 | "1024mb", 39 | "512mb" 40 | ], 41 | "slug": "nyc1" 42 | }, 43 | "size": { 44 | "disk": 20, 45 | "memory": 512, 46 | "price_hourly": "0.00744", 47 | "price_monthly": "5.0", 48 | "regions": [ 49 | "nyc1", 50 | "sfo1", 51 | "ams1" 52 | ], 53 | "slug": "512mb", 54 | "transfer": null, 55 | "vcpus": 1 56 | }, 57 | "snapshot_ids": [], 58 | "status": "new" 59 | }, 60 | "links": { 61 | "actions": [ 62 | { 63 | "href": "http://example.org/v2/actions/19", 64 | "id": 19, 65 | "rel": "create" 66 | } 67 | ] 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/disable_backups.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 16, 5 | "region": "nyc1", 6 | "resource_id": 16, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:22Z", 9 | "status": "in-progress", 10 | "type": "disable_backups" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/enable_ipv6.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 15, 5 | "region": "nyc1", 6 | "resource_id": 15, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:22Z", 9 | "status": "in-progress", 10 | "type": "enable_ipv6" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/enable_private_networking.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 17, 5 | "region": "nyc1", 6 | "resource_id": 17, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:22Z", 9 | "status": "in-progress", 10 | "type": "enable_private_networking" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/kernels.json: -------------------------------------------------------------------------------- 1 | { 2 | "kernels": [ 3 | { 4 | "id": 61833229, 5 | "name": "Ubuntu 14.04 x32 vmlinuz-3.13.0-24-generic", 6 | "version": "3.13.0-24-generic" 7 | }, 8 | { 9 | "id": 485432972, 10 | "name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-24-generic (1221)", 11 | "version": "3.13.0-24-generic" 12 | } 13 | ], 14 | "meta": { 15 | "total": 2 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/password_reset.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 9, 5 | "region": "nyc1", 6 | "resource_id": 9, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:21Z", 9 | "status": "in-progress", 10 | "type": "password_reset" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/power_cycle.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 5, 5 | "region": "nyc1", 6 | "resource_id": 5, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:20Z", 9 | "status": "in-progress", 10 | "type": "power_cycle" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/power_off.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 7, 5 | "region": "nyc1", 6 | "resource_id": 7, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:20Z", 9 | "status": "in-progress", 10 | "type": "power_off" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/power_on.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 8, 5 | "region": "nyc1", 6 | "resource_id": 8, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:20Z", 9 | "status": "in-progress", 10 | "type": "power_on" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/reboot.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 4, 5 | "region": "nyc1", 6 | "resource_id": 4, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:19Z", 9 | "status": "in-progress", 10 | "type": "reboot" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/rebuild.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 12, 5 | "region": "nyc1", 6 | "resource_id": 12, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:21Z", 9 | "status": "in-progress", 10 | "type": "rebuild" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/rename.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 13, 5 | "region": "nyc1", 6 | "resource_id": 13, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:22Z", 9 | "status": "in-progress", 10 | "type": "rename" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/resize.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 10, 5 | "region": "nyc1", 6 | "resource_id": 10, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:21Z", 9 | "status": "in-progress", 10 | "type": "resize" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/restore.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 11, 5 | "region": "nyc1", 6 | "resource_id": 11, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:21Z", 9 | "status": "in-progress", 10 | "type": "restore" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/show.json: -------------------------------------------------------------------------------- 1 | { 2 | "droplet": { 3 | "action_ids": [], 4 | "backup_ids": [ 5 | 449676383 6 | ], 7 | "created_at": "2014-07-02T16:10:23Z", 8 | "id": 19, 9 | "image": { 10 | "created_at": "2014-07-02T16:10:23Z", 11 | "distribution": "ubuntu", 12 | "id": 119192817, 13 | "name": "Ubuntu 13.04", 14 | "public": true, 15 | "regions": [ 16 | "nyc1" 17 | ], 18 | "slug": "ubuntu1304" 19 | }, 20 | "kernel": { 21 | "id": 485432986, 22 | "name": "DO-recovery-static-fsck", 23 | "version": "3.8.0-25-generic" 24 | }, 25 | "locked": false, 26 | "name": "test.example.com", 27 | "networks": { 28 | "v4": [ 29 | { 30 | "gateway": "127.0.0.15", 31 | "ip_address": "127.0.0.14", 32 | "netmask": "255.255.255.0", 33 | "type": "public" 34 | } 35 | ], 36 | "v6": [ 37 | { 38 | "cidr": 124, 39 | "gateway": "2400:6180:0000:00D0:0000:0000:0009:7000", 40 | "ip_address": "2001::14", 41 | "type": "public" 42 | } 43 | ] 44 | }, 45 | "region": { 46 | "available": true, 47 | "features": [ 48 | "virtio", 49 | "private_networking", 50 | "backups", 51 | "ipv6" 52 | ], 53 | "name": "New York", 54 | "sizes": [ 55 | "1024mb", 56 | "512mb" 57 | ], 58 | "slug": "nyc1" 59 | }, 60 | "size": { 61 | "disk": 20, 62 | "memory": 512, 63 | "price_hourly": "0.00744", 64 | "price_monthly": "5.0", 65 | "regions": [ 66 | "nyc1", 67 | "sfo1", 68 | "ams1" 69 | ], 70 | "slug": "512mb", 71 | "transfer": null, 72 | "vcpus": 1 73 | }, 74 | "snapshot_ids": [ 75 | 449676384 76 | ], 77 | "status": "active" 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/show_action.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 3, 5 | "region": "nyc1", 6 | "resource_id": 3, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:19Z", 9 | "status": "in-progress", 10 | "type": "create" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/shutdown.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 6, 5 | "region": "nyc1", 6 | "resource_id": 6, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:20Z", 9 | "status": "in-progress", 10 | "type": "shutdown" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/snapshot.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 3636, 5 | "region": "nyc1", 6 | "resource_id": 36, 7 | "resource_type": "droplet", 8 | "started_at": "2014-07-02T16:10:22Z", 9 | "status": "in-progress", 10 | "type": "snapshot" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/droplets/snapshots.json: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "total": 1 4 | }, 5 | "snapshots": [ 6 | { 7 | "created_at": "2014-07-02T16:10:24Z", 8 | "distribution": "ubuntu", 9 | "id": 449676386, 10 | "name": "Ubuntu 13.04", 11 | "public": false, 12 | "regions": [ 13 | "nyc1" 14 | ], 15 | "slug": null 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /spec/fixtures/floating_ips/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "floating_ips": [ 3 | { 4 | "droplet": null, 5 | "ip": "10.20.30.40", 6 | "locked": false, 7 | "region": { 8 | "available": true, 9 | "features": [ 10 | "private_networking", 11 | "backups", 12 | "ipv6", 13 | "metadata" 14 | ], 15 | "name": "New York 3", 16 | "sizes": [ 17 | "512mb", 18 | "1gb", 19 | "2gb", 20 | "4gb", 21 | "8gb", 22 | "16gb", 23 | "32gb", 24 | "48gb", 25 | "64gb" 26 | ], 27 | "slug": "nyc3" 28 | } 29 | } 30 | ], 31 | "links": {}, 32 | "meta": { 33 | "total": 1 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spec/fixtures/floating_ips/assign.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 68212728, 5 | "region": { 6 | "available": true, 7 | "features": [ 8 | "private_networking", 9 | "backups", 10 | "ipv6", 11 | "metadata" 12 | ], 13 | "name": "New York 3", 14 | "sizes": [ 15 | "512mb", 16 | "1gb", 17 | "2gb", 18 | "4gb", 19 | "8gb", 20 | "16gb", 21 | "32gb", 22 | "48gb", 23 | "64gb" 24 | ], 25 | "slug": "nyc3" 26 | }, 27 | "region_slug": "nyc3", 28 | "resource_id": 758603823, 29 | "resource_type": "floating_ip", 30 | "started_at": "2015-10-15T17:45:44Z", 31 | "status": "in-progress", 32 | "type": "assign_ip" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spec/fixtures/floating_ips/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "floating_ip": { 3 | "droplet": null, 4 | "ip": "10.20.30.40", 5 | "locked": false, 6 | "region": { 7 | "available": true, 8 | "features": [ 9 | "private_networking", 10 | "backups", 11 | "ipv6", 12 | "metadata" 13 | ], 14 | "name": "New York 3", 15 | "sizes": [ 16 | "512mb", 17 | "1gb", 18 | "2gb", 19 | "4gb", 20 | "8gb", 21 | "16gb", 22 | "32gb", 23 | "48gb", 24 | "64gb" 25 | ], 26 | "slug": "nyc3" 27 | } 28 | }, 29 | "links": {} 30 | } 31 | -------------------------------------------------------------------------------- /spec/fixtures/floating_ips/show.json: -------------------------------------------------------------------------------- 1 | { 2 | "floating_ip": { 3 | "droplet": null, 4 | "ip": "10.20.30.40", 5 | "locked": false, 6 | "region": { 7 | "available": true, 8 | "features": [ 9 | "private_networking", 10 | "backups", 11 | "ipv6", 12 | "metadata" 13 | ], 14 | "name": "New York 3", 15 | "sizes": [ 16 | "512mb", 17 | "1gb", 18 | "2gb", 19 | "4gb", 20 | "8gb", 21 | "16gb", 22 | "32gb", 23 | "48gb", 24 | "64gb" 25 | ], 26 | "slug": "nyc3" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spec/fixtures/floating_ips/unassign.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 68212773, 5 | "region": { 6 | "available": true, 7 | "features": [ 8 | "private_networking", 9 | "backups", 10 | "ipv6", 11 | "metadata" 12 | ], 13 | "name": "New York 3", 14 | "sizes": [ 15 | "512mb", 16 | "1gb", 17 | "2gb", 18 | "4gb", 19 | "8gb", 20 | "16gb", 21 | "32gb", 22 | "48gb", 23 | "64gb" 24 | ], 25 | "slug": "nyc3" 26 | }, 27 | "region_slug": "nyc3", 28 | "resource_id": 758603823, 29 | "resource_type": "floating_ip", 30 | "started_at": "2015-10-15T17:46:15Z", 31 | "status": "in-progress", 32 | "type": "unassign_ip" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spec/fixtures/images/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "images": [ 3 | { 4 | "created_at": "2014-07-02T16:10:25Z", 5 | "distribution": "ubuntu", 6 | "id": 119192817, 7 | "name": "Ubuntu 13.04", 8 | "public": true, 9 | "regions": [ 10 | "nyc1" 11 | ], 12 | "slug": "ubuntu1304" 13 | }, 14 | { 15 | "created_at": "2014-07-02T16:10:25Z", 16 | "distribution": "ubuntu", 17 | "id": 449676376, 18 | "name": "Ubuntu 13.04", 19 | "public": true, 20 | "regions": [ 21 | "nyc1" 22 | ], 23 | "slug": "ubuntu1404" 24 | } 25 | ], 26 | "meta": { 27 | "total": 2 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spec/fixtures/images/show.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": { 3 | "created_at": "2014-07-02T16:10:25Z", 4 | "distribution": null, 5 | "id": 449676391, 6 | "name": "Ubuntu 13.04", 7 | "public": false, 8 | "regions": [ 9 | "region--1" 10 | ], 11 | "slug": null 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spec/fixtures/images/show_action.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 21, 5 | "region": "nyc1", 6 | "resource_id": 449676389, 7 | "resource_type": "image", 8 | "started_at": "2014-07-02T16:10:25Z", 9 | "status": "in-progress", 10 | "type": "transfer" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/images/transfer.json: -------------------------------------------------------------------------------- 1 | { 2 | "action": { 3 | "completed_at": null, 4 | "id": 22, 5 | "region": "sfo1", 6 | "resource_id": 449676390, 7 | "resource_type": "image", 8 | "started_at": "2014-07-02T16:10:25Z", 9 | "status": "in-progress", 10 | "type": "transfer" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spec/fixtures/images/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": { 3 | "created_at": "2014-07-02T16:10:26Z", 4 | "distribution": null, 5 | "id": 449676393, 6 | "name": "New Image Name", 7 | "public": false, 8 | "regions": [ 9 | "region--3" 10 | ], 11 | "slug": null 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spec/fixtures/keys/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "ssh_keys": [ 3 | { 4 | "fingerprint": "f5:de:eb:64:2d:6a:b6:d5:bb:06:47:7f:04:4b:f8:e2", 5 | "id": 1, 6 | "name": "Example Key", 7 | "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPrtBjQaNBwDSV3ePC86zaEWu06g4+KEiivyqWAiOTvIp33Nia3b91NjfQydMkJlVfKuFs+hf2buQvCvslF4NNmWqxkPB69d+fS0ZL8Y4FMqut2I8hJuDg5MHO66QX6BkMqjqt3vsaJqbn7/dy0rKsqnaHgH0xqg0sPccK98nhL3nuoDGrzlsK0zMdfktX/yRSdjlpj4KdufA8/9uX14YGXNyduKMr8Sl7fLiAgtM0J3HHPAEOXce1iSmfIbxn16c8ikOddgM5MGK8DveX4EEscqwG0MxNkXJxgrU3e+k6dkb6RKuvGCtdSthrJ5X6O99lZCP0L6i3CD69d13YFobB name@example.com" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /spec/fixtures/keys/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "ssh_key": { 3 | "fingerprint": "f5:de:eb:64:2d:6a:b6:d5:bb:06:47:7f:04:4b:f8:e2", 4 | "id": 3, 5 | "name": "Example Key", 6 | "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPrtBjQaNBwDSV3ePC86zaEWu06g4+KEiivyqWAiOTvIp33Nia3b91NjfQydMkJlVfKuFs+hf2buQvCvslF4NNmWqxkPB69d+fS0ZL8Y4FMqut2I8hJuDg5MHO66QX6BkMqjqt3vsaJqbn7/dy0rKsqnaHgH0xqg0sPccK98nhL3nuoDGrzlsK0zMdfktX/yRSdjlpj4KdufA8/9uX14YGXNyduKMr8Sl7fLiAgtM0J3HHPAEOXce1iSmfIbxn16c8ikOddgM5MGK8DveX4EEscqwG0MxNkXJxgrU3e+k6dkb6RKuvGCtdSthrJ5X6O99lZCP0L6i3CD69d13YFobB name@example.com" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /spec/fixtures/keys/show.json: -------------------------------------------------------------------------------- 1 | { 2 | "ssh_key": { 3 | "fingerprint": "f5:de:eb:64:2d:6a:b6:d5:bb:06:47:7f:04:4b:f8:e2", 4 | "id": 4, 5 | "name": "Example Key", 6 | "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPrtBjQaNBwDSV3ePC86zaEWu06g4+KEiivyqWAiOTvIp33Nia3b91NjfQydMkJlVfKuFs+hf2buQvCvslF4NNmWqxkPB69d+fS0ZL8Y4FMqut2I8hJuDg5MHO66QX6BkMqjqt3vsaJqbn7/dy0rKsqnaHgH0xqg0sPccK98nhL3nuoDGrzlsK0zMdfktX/yRSdjlpj4KdufA8/9uX14YGXNyduKMr8Sl7fLiAgtM0J3HHPAEOXce1iSmfIbxn16c8ikOddgM5MGK8DveX4EEscqwG0MxNkXJxgrU3e+k6dkb6RKuvGCtdSthrJ5X6O99lZCP0L6i3CD69d13YFobB name@example.com" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /spec/fixtures/keys/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "ssh_key": { 3 | "fingerprint": "f5:de:eb:64:2d:6a:b6:d5:bb:06:47:7f:04:4b:f8:e2", 4 | "id": 5, 5 | "name": "Example Key", 6 | "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPrtBjQaNBwDSV3ePC86zaEWu06g4+KEiivyqWAiOTvIp33Nia3b91NjfQydMkJlVfKuFs+hf2buQvCvslF4NNmWqxkPB69d+fS0ZL8Y4FMqut2I8hJuDg5MHO66QX6BkMqjqt3vsaJqbn7/dy0rKsqnaHgH0xqg0sPccK98nhL3nuoDGrzlsK0zMdfktX/yRSdjlpj4KdufA8/9uX14YGXNyduKMr8Sl7fLiAgtM0J3HHPAEOXce1iSmfIbxn16c8ikOddgM5MGK8DveX4EEscqwG0MxNkXJxgrU3e+k6dkb6RKuvGCtdSthrJ5X6O99lZCP0L6i3CD69d13YFobB name@example.com" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /spec/fixtures/regions/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "regions": [ 3 | { 4 | "available": true, 5 | "features": [ 6 | "virtio", 7 | "backups" 8 | ], 9 | "name": "San Francisco", 10 | "sizes": [ 11 | "1024mb", 12 | "512mb" 13 | ], 14 | "slug": "sfo1" 15 | }, 16 | { 17 | "available": true, 18 | "features": [ 19 | "virtio", 20 | "backups" 21 | ], 22 | "name": "Amsterdam", 23 | "sizes": [ 24 | "1024mb", 25 | "512mb" 26 | ], 27 | "slug": "ams1" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /spec/fixtures/sizes/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "sizes": [ 3 | { 4 | "disk": 20, 5 | "memory": 512, 6 | "price_hourly": "0.00744", 7 | "price_monthly": "5.0", 8 | "regions": [ 9 | "nyc1", 10 | "ams1", 11 | "sfo1" 12 | ], 13 | "slug": "512mb", 14 | "transfer": null, 15 | "vcpus": 1 16 | }, 17 | { 18 | "disk": 30, 19 | "memory": 1024, 20 | "price_hourly": "0.01488", 21 | "price_monthly": "10.0", 22 | "regions": [ 23 | "nyc1", 24 | "ams1", 25 | "sfo1" 26 | ], 27 | "slug": "1024mb", 28 | "transfer": null, 29 | "vcpus": 2 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | if ENV['SIMPLECOV'] 2 | require 'simplecov' 3 | SimpleCov.start { add_filter '/spec/' } 4 | elsif ENV['TRAVIS'] && RUBY_ENGINE == 'ruby' 5 | require 'coveralls' 6 | Coveralls.wear! { add_filter '/spec/' } 7 | end 8 | 9 | require_relative '../lib/barge' 10 | Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f } 11 | 12 | require 'webmock/rspec' 13 | WebMock.disable_net_connect!(allow: 'coveralls.io') 14 | 15 | RSpec.configure do |config| 16 | config.include SpecHelpers 17 | config.raise_errors_for_deprecations! 18 | 19 | config.expect_with :rspec do |c| 20 | c.syntax = :expect 21 | end 22 | 23 | config.mock_with :rspec do |c| 24 | c.syntax = :expect 25 | c.verify_partial_doubles = true 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/support/shared_contexts.rb: -------------------------------------------------------------------------------- 1 | shared_context 'resource' do 2 | let(:barge) { Barge::Client.new(access_token: 'some_token') } 3 | 4 | let(:account) { barge.account } 5 | let(:action) { barge.action } 6 | let(:domain) { barge.domain } 7 | let(:droplet) { barge.droplet } 8 | let(:floating_ip) { barge.floating_ip } 9 | let(:image) { barge.image } 10 | let(:key) { barge.key } 11 | let(:region) { barge.region } 12 | let(:size) { barge.size } 13 | end 14 | -------------------------------------------------------------------------------- /spec/support/shared_examples.rb: -------------------------------------------------------------------------------- 1 | shared_examples_for 'a resource' do 2 | specify { expect(described_class).to include Barge::Resource::Base } 3 | 4 | describe '#faraday' do 5 | let(:value) { '123' } 6 | 7 | it 'returns the object passed to .new' do 8 | expect(described_class.new(value).faraday).to be value 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/support/spec_helpers.rb: -------------------------------------------------------------------------------- 1 | module SpecHelpers 2 | def fixture(name) 3 | File.read(File.expand_path("../../fixtures/#{name}.json", __FILE__)) 4 | end 5 | 6 | def stub_request!(verb, path) 7 | path += '?per_page=200' if verb == :get && !path.include?('per_page=') 8 | stub_request(verb, File.join(Barge::Client::DIGITAL_OCEAN_URL, path)) 9 | .with(headers: request_stub_headers) 10 | end 11 | 12 | def request_stub_headers 13 | { 14 | authorization: 'Bearer some_token', 15 | content_type: 'application/json' 16 | } 17 | end 18 | end 19 | --------------------------------------------------------------------------------