droplet_kit 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +1 -0
- data/droplet_kit.gemspec +1 -1
- data/lib/droplet_kit/mappings/droplet_mapping.rb +2 -1
- data/lib/droplet_kit/models/droplet.rb +1 -0
- data/lib/droplet_kit/resources/droplet_resource.rb +6 -0
- data/lib/droplet_kit/version.rb +1 -1
- data/spec/fixtures/droplets/create_multiple.json +160 -0
- data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +74 -9
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a86ff8a04cf0c309cc0664c732326179bb5c645
|
4
|
+
data.tar.gz: d38e878482a1ebe271bc139dc5a90a3f0b1d094b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce73f66a82d4a2d08638c4e4af1a8e171fee5d0ae0c50ee10dfc40701c5a6aab5c536a11e68fca4fbc6160cb635d203d4a1c6c89c53ba08b762f0cbcb928ec70
|
7
|
+
data.tar.gz: af22eec48bfa4e8e159df286252db56da1de69247857933e6c35be9b559d600746920b328f6d87c2ba2510b1518afbb4a2eba9f5a30eaf155b10d21360ed979e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,7 @@ Actions supported:
|
|
76
76
|
* `client.droplets.all()`
|
77
77
|
* `client.droplets.find(id: 'id')`
|
78
78
|
* `client.droplets.create(droplet)`
|
79
|
+
* `client.droplets.create_multiple(droplet)`
|
79
80
|
* `client.droplets.delete(id: 'id')`
|
80
81
|
* `client.droplets.kernels(id: 'id')`
|
81
82
|
* `client.droplets.snapshots(id: 'id')`
|
data/droplet_kit.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_dependency "activesupport", '> 3.0', '< 5.0.0'
|
27
27
|
spec.add_dependency "faraday", '~> 0.9.1'
|
28
28
|
|
29
|
-
spec.add_development_dependency "bundler", "~> 1.
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11.0"
|
30
30
|
spec.add_development_dependency "rake"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0.0"
|
32
32
|
spec.add_development_dependency "pry"
|
@@ -26,7 +26,8 @@ module DropletKit
|
|
26
26
|
property :kernel, scopes: [:read], include: KernelMapping
|
27
27
|
|
28
28
|
# Create properties arent quite the same
|
29
|
-
property :name, scopes: [:create]
|
29
|
+
property :name, scopes: [:create] # "Regular" create
|
30
|
+
property :names, scopes: [:create] # Multiple create
|
30
31
|
property :region, scopes: [:create]
|
31
32
|
property :size, scopes: [:create]
|
32
33
|
property :image, scopes: [:create]
|
@@ -18,6 +18,12 @@ module DropletKit
|
|
18
18
|
handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
|
19
19
|
end
|
20
20
|
|
21
|
+
action :create_multiple, 'POST /v2/droplets' do
|
22
|
+
body { |object| DropletMapping.representation_for(:create, object) }
|
23
|
+
handler(202) { |response| DropletMapping.extract_collection(response.body, :read) }
|
24
|
+
handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
|
25
|
+
end
|
26
|
+
|
21
27
|
action :delete, 'DELETE /v2/droplets/:id' do
|
22
28
|
handler(204) { |response| true }
|
23
29
|
end
|
data/lib/droplet_kit/version.rb
CHANGED
@@ -0,0 +1,160 @@
|
|
1
|
+
{
|
2
|
+
"droplets": [
|
3
|
+
{
|
4
|
+
"id": 19,
|
5
|
+
"name": "test-01.example.com",
|
6
|
+
"memory": 1024,
|
7
|
+
"vcpus": 2,
|
8
|
+
"disk": 20,
|
9
|
+
"region": {
|
10
|
+
"slug": "nyc1",
|
11
|
+
"name": "New York",
|
12
|
+
"sizes": [
|
13
|
+
"1024mb",
|
14
|
+
"512mb"
|
15
|
+
],
|
16
|
+
"available": true,
|
17
|
+
"features": [
|
18
|
+
"virtio",
|
19
|
+
"private_networking",
|
20
|
+
"backups",
|
21
|
+
"ipv6"
|
22
|
+
]
|
23
|
+
},
|
24
|
+
"image": {
|
25
|
+
"id": 119192817,
|
26
|
+
"name": "Ubuntu 13.04",
|
27
|
+
"distribution": "ubuntu",
|
28
|
+
"slug": "ubuntu1304",
|
29
|
+
"public": true,
|
30
|
+
"regions": [
|
31
|
+
"nyc1"
|
32
|
+
],
|
33
|
+
"created_at": "2014-07-29T14:35:37Z"
|
34
|
+
},
|
35
|
+
"size_slug": "1024mb",
|
36
|
+
"locked": false,
|
37
|
+
"status": "active",
|
38
|
+
"networks": {
|
39
|
+
"v4": [
|
40
|
+
{
|
41
|
+
"ip_address": "10.0.0.19",
|
42
|
+
"netmask": "255.255.0.0",
|
43
|
+
"gateway": "10.0.0.1",
|
44
|
+
"type": "private"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"ip_address": "127.0.0.19",
|
48
|
+
"netmask": "255.255.255.0",
|
49
|
+
"gateway": "127.0.0.20",
|
50
|
+
"type": "public"
|
51
|
+
}
|
52
|
+
],
|
53
|
+
"v6": [
|
54
|
+
{
|
55
|
+
"ip_address": "2001::13",
|
56
|
+
"cidr": 124,
|
57
|
+
"gateway": "2400:6180:0000:00D0:0000:0000:0009:7000",
|
58
|
+
"type": "public"
|
59
|
+
}
|
60
|
+
]
|
61
|
+
},
|
62
|
+
"kernel": {
|
63
|
+
"id": 485432985,
|
64
|
+
"name": "DO-recovery-static-fsck",
|
65
|
+
"version": "3.8.0-25-generic"
|
66
|
+
},
|
67
|
+
"created_at": "2014-07-29T14:35:37Z",
|
68
|
+
"features": [
|
69
|
+
"ipv6"
|
70
|
+
],
|
71
|
+
"backup_ids": [
|
72
|
+
449676382
|
73
|
+
],
|
74
|
+
"snapshot_ids": [
|
75
|
+
449676383
|
76
|
+
],
|
77
|
+
"action_ids": [
|
78
|
+
|
79
|
+
]
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"id": 20,
|
83
|
+
"name": "test-02.example.com",
|
84
|
+
"memory": 1024,
|
85
|
+
"vcpus": 2,
|
86
|
+
"disk": 20,
|
87
|
+
"region": {
|
88
|
+
"slug": "nyc1",
|
89
|
+
"name": "New York",
|
90
|
+
"sizes": [
|
91
|
+
"1024mb",
|
92
|
+
"512mb"
|
93
|
+
],
|
94
|
+
"available": true,
|
95
|
+
"features": [
|
96
|
+
"virtio",
|
97
|
+
"private_networking",
|
98
|
+
"backups",
|
99
|
+
"ipv6"
|
100
|
+
]
|
101
|
+
},
|
102
|
+
"image": {
|
103
|
+
"id": 119192817,
|
104
|
+
"name": "Ubuntu 13.04",
|
105
|
+
"distribution": "ubuntu",
|
106
|
+
"slug": "ubuntu1304",
|
107
|
+
"public": true,
|
108
|
+
"regions": [
|
109
|
+
"nyc1"
|
110
|
+
],
|
111
|
+
"created_at": "2014-07-29T14:35:37Z"
|
112
|
+
},
|
113
|
+
"size_slug": "1024mb",
|
114
|
+
"locked": false,
|
115
|
+
"status": "active",
|
116
|
+
"networks": {
|
117
|
+
"v4": [
|
118
|
+
{
|
119
|
+
"ip_address": "10.0.0.19",
|
120
|
+
"netmask": "255.255.0.0",
|
121
|
+
"gateway": "10.0.0.1",
|
122
|
+
"type": "private"
|
123
|
+
},
|
124
|
+
{
|
125
|
+
"ip_address": "127.0.0.19",
|
126
|
+
"netmask": "255.255.255.0",
|
127
|
+
"gateway": "127.0.0.20",
|
128
|
+
"type": "public"
|
129
|
+
}
|
130
|
+
],
|
131
|
+
"v6": [
|
132
|
+
{
|
133
|
+
"ip_address": "2001::13",
|
134
|
+
"cidr": 124,
|
135
|
+
"gateway": "2400:6180:0000:00D0:0000:0000:0009:7000",
|
136
|
+
"type": "public"
|
137
|
+
}
|
138
|
+
]
|
139
|
+
},
|
140
|
+
"kernel": {
|
141
|
+
"id": 485432985,
|
142
|
+
"name": "DO-recovery-static-fsck",
|
143
|
+
"version": "3.8.0-25-generic"
|
144
|
+
},
|
145
|
+
"created_at": "2014-07-29T14:35:37Z",
|
146
|
+
"features": [
|
147
|
+
"ipv6"
|
148
|
+
],
|
149
|
+
"backup_ids": [
|
150
|
+
449676382
|
151
|
+
],
|
152
|
+
"snapshot_ids": [
|
153
|
+
449676383
|
154
|
+
],
|
155
|
+
"action_ids": [
|
156
|
+
|
157
|
+
]
|
158
|
+
}
|
159
|
+
]
|
160
|
+
}
|
@@ -4,15 +4,22 @@ RSpec.describe DropletKit::DropletResource do
|
|
4
4
|
subject(:resource) { described_class.new(connection: connection) }
|
5
5
|
include_context 'resources'
|
6
6
|
|
7
|
-
#
|
8
|
-
def check_droplet(droplet)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
# There's a lot to check
|
8
|
+
def check_droplet(droplet, overrides = {})
|
9
|
+
attrs = {
|
10
|
+
id: 19,
|
11
|
+
name: 'test.example.com',
|
12
|
+
memory: 1024,
|
13
|
+
vcpus: 2,
|
14
|
+
disk: 20,
|
15
|
+
locked: false,
|
16
|
+
status: 'active'
|
17
|
+
}.merge(overrides)
|
18
|
+
|
19
|
+
attrs.each do |attr, val|
|
20
|
+
expect(droplet.send(attr)).to eq attrs[attr]
|
21
|
+
end
|
22
|
+
|
16
23
|
expect(droplet.created_at).to be_present
|
17
24
|
expect(droplet.backup_ids).to include(449676382)
|
18
25
|
expect(droplet.snapshot_ids).to include(449676383)
|
@@ -153,6 +160,64 @@ RSpec.describe DropletKit::DropletResource do
|
|
153
160
|
end
|
154
161
|
end
|
155
162
|
|
163
|
+
describe '#create_multiple' do
|
164
|
+
let(:path) { '/v2/droplets' }
|
165
|
+
|
166
|
+
context 'for a successful multiple create' do
|
167
|
+
it 'returns the created droplets' do
|
168
|
+
droplet = DropletKit::Droplet.new(
|
169
|
+
names: ['test-01.example.com', 'test-02.example.com'],
|
170
|
+
region: 'nyc1',
|
171
|
+
size: '512mb',
|
172
|
+
image: 'ubuntu-14-04-x86',
|
173
|
+
ssh_keys: [123],
|
174
|
+
backups: true,
|
175
|
+
ipv6: true,
|
176
|
+
private_networking: true,
|
177
|
+
user_data: "#cloud-config\nruncmd\n\t- echo 'Hello!'"
|
178
|
+
)
|
179
|
+
|
180
|
+
as_hash = DropletKit::DropletMapping.hash_for(:create, droplet)
|
181
|
+
expect(as_hash['names']).to eq(droplet.names)
|
182
|
+
expect(as_hash['region']).to eq(droplet.region)
|
183
|
+
expect(as_hash['size']).to eq(droplet.size)
|
184
|
+
expect(as_hash['image']).to eq(droplet.image)
|
185
|
+
expect(as_hash['ssh_keys']).to eq(droplet.ssh_keys)
|
186
|
+
expect(as_hash['backups']).to eq(droplet.backups)
|
187
|
+
expect(as_hash['ipv6']).to eq(droplet.ipv6)
|
188
|
+
expect(as_hash['private_networking']).to eq(droplet.private_networking)
|
189
|
+
expect(as_hash['user_data']).to eq(droplet.user_data)
|
190
|
+
|
191
|
+
as_string = DropletKit::DropletMapping.representation_for(:create, droplet)
|
192
|
+
stub_do_api(path, :post).with(body: as_string).to_return(body: api_fixture('droplets/create_multiple'), status: 202)
|
193
|
+
|
194
|
+
created_droplets = resource.create_multiple(droplet)
|
195
|
+
check_droplet(created_droplets[0], name: 'test-01.example.com')
|
196
|
+
check_droplet(created_droplets[1], id: 20, name: 'test-02.example.com')
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'reuses the same object' do
|
200
|
+
droplet = DropletKit::Droplet.new(
|
201
|
+
names: ['test-01.example.com', 'test-02.example.com'],
|
202
|
+
region: 'nyc1',
|
203
|
+
size: '512mb',
|
204
|
+
image: 'ubuntu-14-04-x86'
|
205
|
+
)
|
206
|
+
|
207
|
+
json = DropletKit::DropletMapping.representation_for(:create, droplet)
|
208
|
+
stub_do_api(path, :post).with(body: json).to_return(body: api_fixture('droplets/create_multiple'), status: 202)
|
209
|
+
created_droplets = resource.create_multiple(droplet)
|
210
|
+
check_droplet(created_droplets[0], name: 'test-01.example.com')
|
211
|
+
check_droplet(created_droplets[1], id: 20, name: 'test-02.example.com')
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
it_behaves_like 'an action that handles invalid parameters' do
|
216
|
+
let(:action) { 'create' }
|
217
|
+
let(:arguments) { DropletKit::Droplet.new }
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
156
221
|
describe '#kernels' do
|
157
222
|
it 'returns a list of kernels for a droplet' do
|
158
223
|
stub_do_api('/v2/droplets/1066/kernels', :get).to_return(body: api_fixture('droplets/list_kernels'))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: droplet_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: 1.11.0
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
102
|
+
version: 1.11.0
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: rake
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -276,6 +276,7 @@ files:
|
|
276
276
|
- spec/fixtures/droplets/all.json
|
277
277
|
- spec/fixtures/droplets/all_empty.json
|
278
278
|
- spec/fixtures/droplets/create.json
|
279
|
+
- spec/fixtures/droplets/create_multiple.json
|
279
280
|
- spec/fixtures/droplets/find.json
|
280
281
|
- spec/fixtures/droplets/list_actions.json
|
281
282
|
- spec/fixtures/droplets/list_backups.json
|
@@ -349,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
349
350
|
version: '0'
|
350
351
|
requirements: []
|
351
352
|
rubyforge_project:
|
352
|
-
rubygems_version: 2.4.
|
353
|
+
rubygems_version: 2.4.6
|
353
354
|
signing_key:
|
354
355
|
specification_version: 4
|
355
356
|
summary: Droplet Kit is the official Ruby library for DigitalOcean's API
|
@@ -386,6 +387,7 @@ test_files:
|
|
386
387
|
- spec/fixtures/droplets/all.json
|
387
388
|
- spec/fixtures/droplets/all_empty.json
|
388
389
|
- spec/fixtures/droplets/create.json
|
390
|
+
- spec/fixtures/droplets/create_multiple.json
|
389
391
|
- spec/fixtures/droplets/find.json
|
390
392
|
- spec/fixtures/droplets/list_actions.json
|
391
393
|
- spec/fixtures/droplets/list_backups.json
|
@@ -439,4 +441,3 @@ test_files:
|
|
439
441
|
- spec/support/shared_examples/common_errors.rb
|
440
442
|
- spec/support/shared_examples/paginated_endpoint.rb
|
441
443
|
- spec/support/shared_examples/unsuccessful_create.rb
|
442
|
-
has_rdoc:
|