forked from blom/barge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from petems/add_block_storage
Adds resource of Volumes to Barge
- Loading branch information
Showing
9 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Barge | ||
module Resource | ||
class Volume | ||
include Resource::Base | ||
|
||
def create(options) | ||
post('volumes', options.to_json) | ||
end | ||
|
||
def all(options = {}) | ||
get('volumes', options) | ||
end | ||
|
||
def show(volume_id) | ||
get("volumes/#{volume_id}") | ||
end | ||
|
||
def destroy(volume_id) | ||
delete("volumes/#{volume_id}") | ||
end | ||
|
||
def create_record(volume_id, options) | ||
post("volumes/#{volume_id}/records", options.to_json) | ||
end | ||
|
||
def records(volume_id, options = {}) | ||
get("volumes/#{volume_id}/records", options) | ||
end | ||
|
||
def show_record(volume_id, record_id) | ||
get("volumes/#{volume_id}/records/#{record_id}") | ||
end | ||
|
||
def update_record(volume_id, record_id, options) | ||
put("volumes/#{volume_id}/records/#{record_id}", options.to_json) | ||
end | ||
|
||
def destroy_record(volume_id, record_id) | ||
delete("volumes/#{volume_id}/records/#{record_id}") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'spec_helper' | ||
|
||
describe Barge::Resource::Volume do | ||
include_context 'resource' | ||
it_behaves_like 'a resource' | ||
|
||
describe '#all' do | ||
it 'lists all volumes' do | ||
stubbed_request = | ||
stub_request!(:get, '/volumes') | ||
.to_return(body: fixture('volumes/all'), status: 200) | ||
expect(volume.all.volumes) | ||
.to include a_hash_including(id: "7724db7c-e098-11e5-b522-000f53304e51") | ||
expect(stubbed_request).to have_been_requested | ||
end | ||
|
||
it 'accepts an options hash' do | ||
stubbed_request = | ||
stub_request!(:get, '/volumes?page=10&per_page=20®ion=nyc1') | ||
.to_return(body: fixture('volumes/all'), status: 200) | ||
expect(volume.all(per_page: 20, page: 10, region: 'nyc1').volumes) | ||
.to include a_hash_including(id: "7724db7c-e098-11e5-b522-000f53304e51") | ||
expect(stubbed_request).to have_been_requested | ||
end | ||
end | ||
|
||
describe '#create' do | ||
it 'creates a volume' do | ||
stubbed_request = | ||
stub_request!(:post, '/volumes') | ||
.to_return(body: fixture('volumes/create'), status: 201) | ||
options = { | ||
size_gigabytes: 10, | ||
name: "Example", | ||
description: "Block store for examples", | ||
region: "nyc1" | ||
} | ||
expect(volume.create(options).volume.id).to eql('7724db7c-e098-11e5-b522-000f53304e51') | ||
expect(stubbed_request.with(body: options.to_json)) | ||
.to have_been_requested | ||
end | ||
end | ||
|
||
describe '#destroy' do | ||
it 'destroys a volume' do | ||
stubbed_request = | ||
stub_request!(:delete, '/volumes/7724db7c-e098-11e5-b522-000f53304e51').to_return(status: 204) | ||
expect(volume.destroy('7724db7c-e098-11e5-b522-000f53304e51').success?).to be true | ||
expect(stubbed_request).to have_been_requested | ||
end | ||
end | ||
|
||
describe '#show' do | ||
it 'returns information about a given volume' do | ||
stubbed_request = | ||
stub_request!(:get, '/volumes/7724db7c-e098-11e5-b522-000f53304e51') | ||
.to_return(body: fixture('volumes/show'), status: 200) | ||
expect(volume.show('7724db7c-e098-11e5-b522-000f53304e51').volume.name).to eq 'Example' | ||
expect(stubbed_request).to have_been_requested | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"volumes": [ | ||
{ | ||
"id": "7724db7c-e098-11e5-b522-000f53304e51", | ||
"region": { | ||
"name": "New York 1", | ||
"slug": "nyc1", | ||
"sizes": [ | ||
"512mb", | ||
"1gb", | ||
"2gb", | ||
"4gb", | ||
"8gb", | ||
"16gb", | ||
"32gb", | ||
"48gb", | ||
"64gb" | ||
], | ||
"features": [ | ||
"private_networking", | ||
"backups", | ||
"ipv6", | ||
"metadata" | ||
], | ||
"available": true | ||
}, | ||
"droplet_ids": [ | ||
|
||
], | ||
"name": "Example", | ||
"description": "Block store for examples", | ||
"size_gigabytes": 10, | ||
"created_at": "2016-03-02T17:00:49Z" | ||
} | ||
], | ||
"links": { | ||
}, | ||
"meta": { | ||
"total": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"volume": { | ||
"id": "7724db7c-e098-11e5-b522-000f53304e51", | ||
"region": { | ||
"name": "New York 1", | ||
"slug": "nyc1", | ||
"sizes": [ | ||
"512mb", | ||
"1gb", | ||
"2gb", | ||
"4gb", | ||
"8gb", | ||
"16gb", | ||
"32gb", | ||
"48gb", | ||
"64gb" | ||
], | ||
"features": [ | ||
"private_networking", | ||
"backups", | ||
"ipv6", | ||
"metadata" | ||
], | ||
"available": true | ||
}, | ||
"droplet_ids": [ | ||
|
||
], | ||
"name": "Example", | ||
"description": "Block store for examples", | ||
"size_gigabytes": 10, | ||
"created_at": "2016-03-02T17:00:49Z" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"volume": { | ||
"id": "7724db7c-e098-11e5-b522-000f53304e51", | ||
"region": { | ||
"name": "New York 1", | ||
"slug": "nyc1", | ||
"sizes": [ | ||
"512mb", | ||
"1gb", | ||
"2gb", | ||
"4gb", | ||
"8gb", | ||
"16gb", | ||
"32gb", | ||
"48gb", | ||
"64gb" | ||
], | ||
"features": [ | ||
"private_networking", | ||
"backups", | ||
"ipv6", | ||
"metadata" | ||
], | ||
"available": true | ||
}, | ||
"droplet_ids": [ | ||
|
||
], | ||
"name": "Example", | ||
"description": "Block store for examples", | ||
"size_gigabytes": 10, | ||
"created_at": "2016-03-02T17:00:49Z" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters