droplet_kit 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4573b2ad1d55aa0ad804badf5bce1b2614800b34
4
- data.tar.gz: 02c8d03d60f9f1ef07aeddaf8a39005c58b1206e
3
+ metadata.gz: c7ec2875e0c5cdc19cca7b6660ea0a1ccb03e3dd
4
+ data.tar.gz: 8e293ff411e4fa8c276b402a8c046a30dabb512a
5
5
  SHA512:
6
- metadata.gz: b5b1a994c2dbe57857d9ae95bdc61aba6704d3f6be89cf091cfe5ec0652e1e9eaf75796822bb527c85c901a5e44e59fe3f903174bd4d1de6bbf6c215c40522d8
7
- data.tar.gz: ef0228046db08ff59a8d21053efb37ca0460a073304057efe83be3d9aac6684525b61f345068e68407815a9dc2a075129e5dc885540213013e11ff24c3172728
6
+ metadata.gz: da7a4a687a6b048947355157036e0ed363c37d3a5cd274b0d802846be0ba734af181839e74d1f190a8f43159604be1a5e26342dfaaf26a985294f97e365932cb
7
+ data.tar.gz: 5a81bcc796c32dedfb5247333c53bf5e2fad5b6c285b38ddd872f619cfbced1c6cc8e7dd3fa2d90994fc4a128bc793b0119ff66d13c8a532493ff291986398d6
data/.travis.yml CHANGED
@@ -1,6 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+
1
4
  rvm:
2
5
  - "2.0.0"
3
6
  - "2.1.5"
4
7
  - "2.2.0"
5
8
 
6
- script: bundle exec rspec ./spec
9
+ env:
10
+ - ACTIVESUPPORT_VERSION=3
11
+ - ACTIVESUPPORT_VERSION=4
12
+
13
+ script:
14
+ - bundle exec rspec ./spec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ### Version 1.2.2
2
+
3
+ * Add image convert action.
4
+ * Loosen dependency on ActiveSupport, update travis.
5
+ * Add Image#type property.
6
+ * Allow client option with indifferent access.
7
+ * Add private filtering to image endpoint.
8
+ * Add droplet upgrades resource.
9
+
10
+ ### Version 1.2.1
11
+
12
+ * Update to action resources to support embedded region breaking changes in API.
13
+
1
14
  ### Version 1.2.0
2
15
 
3
16
  * Add droplet upgrade action.
data/Gemfile CHANGED
@@ -2,4 +2,13 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'simplecov'
4
4
  # Specify your gem's dependencies in droplet_kit.gemspec
5
- gemspec
5
+ gemspec
6
+
7
+ version = case (ENV['ACTIVESUPPORT_VERSION'] || '4')
8
+ when '4'
9
+ '~> 4.0'
10
+ when '3'
11
+ '~> 3.1'
12
+ end
13
+
14
+ gem 'activesupport', version
data/droplet_kit.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'virtus', '~> 1.0.3'
24
24
  spec.add_dependency "resource_kit", '~> 0.1.1'
25
25
  spec.add_dependency "kartograph", '~> 0.2.1'
26
- spec.add_dependency "activesupport", '~> 4.1.6'
26
+ spec.add_dependency "activesupport", '> 3.0', '< 5.0.0'
27
27
  spec.add_dependency "faraday", '~> 0.9.1'
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.6"
data/lib/droplet_kit.rb CHANGED
@@ -24,6 +24,7 @@ module DropletKit
24
24
  autoload :SSHKey, 'droplet_kit/models/ssh_key'
25
25
  autoload :MetaInformation, 'droplet_kit/models/meta_information'
26
26
  autoload :Account, 'droplet_kit/models/account'
27
+ autoload :DropletUpgrade, 'droplet_kit/models/droplet_upgrade'
27
28
 
28
29
  # Resources
29
30
  autoload :DropletResource, 'droplet_kit/resources/droplet_resource'
@@ -37,6 +38,7 @@ module DropletKit
37
38
  autoload :RegionResource, 'droplet_kit/resources/region_resource'
38
39
  autoload :SizeResource, 'droplet_kit/resources/size_resource'
39
40
  autoload :AccountResource, 'droplet_kit/resources/account_resource'
41
+ autoload :DropletUpgradeResource, 'droplet_kit/resources/droplet_upgrade_resource'
40
42
 
41
43
  # JSON Maps
42
44
  autoload :DropletMapping, 'droplet_kit/mappings/droplet_mapping'
@@ -55,6 +57,7 @@ module DropletKit
55
57
  autoload :ImageActionMapping, 'droplet_kit/mappings/image_action_mapping'
56
58
  autoload :SSHKeyMapping, 'droplet_kit/mappings/ssh_key_mapping'
57
59
  autoload :AccountMapping, 'droplet_kit/mappings/account_mapping'
60
+ autoload :DropletUpgradeMapping, 'droplet_kit/mappings/droplet_upgrade_mapping'
58
61
 
59
62
 
60
63
  # Utils
@@ -7,7 +7,7 @@ module DropletKit
7
7
  attr_reader :access_token
8
8
 
9
9
  def initialize(options = {})
10
- @access_token = options[:access_token]
10
+ @access_token = options.with_indifferent_access[:access_token]
11
11
  end
12
12
 
13
13
  def connection
@@ -0,0 +1,12 @@
1
+ module DropletKit
2
+ class DropletUpgradeMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping DropletUpgrade
7
+
8
+ property :droplet_id, scopes: [:read]
9
+ property :date_of_migration, scopes: [:read]
10
+ end
11
+ end
12
+ end
@@ -12,6 +12,7 @@ module DropletKit
12
12
  property :slug, scopes: [:read]
13
13
  property :public, scopes: [:read]
14
14
  property :regions, scopes: [:read]
15
+ property :type, scopes: [:read]
15
16
  end
16
17
  end
17
18
  end
@@ -0,0 +1,6 @@
1
+ module DropletKit
2
+ class DropletUpgrade < BaseModel
3
+ attribute :droplet_id
4
+ attribute :date_of_migration
5
+ end
6
+ end
@@ -6,5 +6,6 @@ module DropletKit
6
6
  attribute :slug
7
7
  attribute :public
8
8
  attribute :regions
9
+ attribute :type
9
10
  end
10
11
  end
@@ -0,0 +1,10 @@
1
+ module DropletKit
2
+ class DropletUpgradeResource < ResourceKit::Resource
3
+ resources do
4
+ action :all, 'GET /v2/droplet_upgrades' do
5
+ query_keys :per_page, :page
6
+ handler(200) { |response| DropletUpgradeMapping.extract_collection(response.body, :read) }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -6,6 +6,11 @@ module DropletKit
6
6
  handler(200, 201) { |response| ImageActionMapping.extract_single(response.body, :read) }
7
7
  end
8
8
 
9
+ action :convert, 'POST /v2/images/:image_id/actions' do
10
+ body { |object| { type: 'convert' }.to_json }
11
+ handler(200, 201) { |response| ImageActionMapping.extract_single(response.body, :read) }
12
+ end
13
+
9
14
  action :all, 'GET /v2/images/:image_id/actions' do
10
15
  handler(200) { |response| ImageActionMapping.extract_collection(response.body, :read) }
11
16
  end
@@ -2,7 +2,7 @@ module DropletKit
2
2
  class ImageResource < ResourceKit::Resource
3
3
  resources do
4
4
  action :all, 'GET /v2/images' do
5
- query_keys :page, :per_page, :type
5
+ query_keys :page, :per_page, :type, :private
6
6
  handler(200) { |response| ImageMapping.extract_collection(response.body, :read) }
7
7
  end
8
8
 
@@ -1,3 +1,3 @@
1
1
  module DropletKit
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -0,0 +1,7 @@
1
+ [
2
+ {
3
+ "droplet_id": 123,
4
+ "date_of_migration": "2014-12-01T12:00:00Z",
5
+ "url": "https://api.digitalocean.com/v2/droplets/123"
6
+ }
7
+ ]
@@ -9,7 +9,8 @@
9
9
  "regions": [
10
10
  "nyc1"
11
11
  ],
12
- "created_at": "2014-07-29T14:35:40Z"
12
+ "created_at": "2014-07-29T14:35:40Z",
13
+ "type": "snapshot"
13
14
  },
14
15
  {
15
16
  "id": 449676376,
@@ -20,7 +21,8 @@
20
21
  "regions": [
21
22
  "nyc1"
22
23
  ],
23
- "created_at": "2014-07-29T14:35:40Z"
24
+ "created_at": "2014-07-29T14:35:40Z",
25
+ "type": "snapshot"
24
26
  }
25
27
  ],
26
28
  "meta": {
@@ -8,6 +8,7 @@
8
8
  "regions": [
9
9
  "region--1"
10
10
  ],
11
- "created_at": "2014-07-29T14:35:41Z"
11
+ "created_at": "2014-07-29T14:35:41Z",
12
+ "type": "snapshot"
12
13
  }
13
14
  }
@@ -8,10 +8,14 @@ RSpec.describe DropletKit::Client do
8
8
  client = DropletKit::Client.new(access_token: 'my-token')
9
9
  expect(client.access_token).to eq('my-token')
10
10
  end
11
+
12
+ it 'allows string option keys for the client' do
13
+ client = DropletKit::Client.new('access_token' => 'my-token')
14
+ expect(client.access_token).to eq('my-token')
15
+ end
11
16
  end
12
17
 
13
18
  describe "#method_missing" do
14
-
15
19
  context "called with an existing method" do
16
20
  it { expect{ client.actions}.to_not raise_error }
17
21
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DropletKit::DropletUpgradeResource do
4
+ subject(:resource) { described_class.new(connection: connection) }
5
+ include_context 'resources'
6
+
7
+ describe '#all' do
8
+ it 'returns a collection of Droplet upgrades' do
9
+ body = api_fixture('droplet_upgrades/all')
10
+ stub_do_api('/v2/droplet_upgrades').to_return(body: body)
11
+ expected = DropletKit::DropletUpgradeMapping.extract_collection(body, :read)
12
+
13
+ expect(resource.all).to eq(expected)
14
+ end
15
+ end
16
+ end
@@ -4,11 +4,35 @@ RSpec.describe DropletKit::ImageActionResource do
4
4
  subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
+ def json
8
+ {
9
+ "action" => {
10
+ "id" => 23,
11
+ "status" => "in-progress",
12
+ "type" => action,
13
+ "started_at" => "2014-08-05T15:15:28Z",
14
+ "completed_at" => nil,
15
+ "resource_id" => 449676391,
16
+ "resource_type" => "image",
17
+ "region_slug" => "nyc1",
18
+ "region" => {
19
+ "name" => "New York",
20
+ "slug" => "nyc1",
21
+ "available" => true,
22
+ "sizes" => ["512mb"],
23
+ "features" => ["virtio", "private_networking", "backups", "ipv6", "metadata"]
24
+ }
25
+ }
26
+ }.to_json
27
+ end
28
+
7
29
  describe '#transfer' do
30
+ let(:action) { 'transfer' }
31
+
8
32
  it 'sends a transfer request for an image' do
9
33
  request = stub_do_api('/v2/images/449676391/actions').with(
10
- body: { type: 'transfer', region: 'sfo1' }.to_json
11
- ).to_return(body: api_fixture('image_actions/create'), status: 201)
34
+ body: { type: action, region: 'sfo1' }.to_json
35
+ ).to_return(body: json, status: 201)
12
36
 
13
37
  action = resource.transfer(image_id: 449676391, region: 'sfo1')
14
38
 
@@ -33,6 +57,37 @@ RSpec.describe DropletKit::ImageActionResource do
33
57
  end
34
58
  end
35
59
 
60
+ describe '#convert' do
61
+ let(:action) { 'convert' }
62
+
63
+ it 'sends a convert request for an image' do
64
+ request = stub_do_api('/v2/images/449676391/actions').with(
65
+ body: { type: action }.to_json
66
+ ).to_return(body: json, status: 201)
67
+
68
+ action = resource.convert(image_id: 449676391)
69
+
70
+ expect(request).to have_been_made
71
+
72
+ expect(action).to be_kind_of(DropletKit::ImageAction)
73
+ expect(action.id).to eq(23)
74
+ expect(action.status).to eq("in-progress")
75
+ expect(action.type).to eq("convert")
76
+ expect(action.started_at).to eq("2014-08-05T15:15:28Z")
77
+ expect(action.completed_at).to eq(nil)
78
+ expect(action.resource_id).to eq(449676391)
79
+ expect(action.resource_type).to eq("image")
80
+ expect(action.region_slug).to eq("nyc1")
81
+
82
+ expect(action.region).to be_kind_of(DropletKit::Region)
83
+ expect(action.region.slug).to eq('nyc1')
84
+ expect(action.region.name).to eq('New York')
85
+ expect(action.region.sizes).to include('512mb')
86
+ expect(action.region.available).to be(true)
87
+ expect(action.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
88
+ end
89
+ end
90
+
36
91
  describe '#all' do
37
92
  it 'returns all of the image actions via a paginated resources' do
38
93
  request = stub_do_api('/v2/images/449676391/actions', :get).to_return(
@@ -12,6 +12,26 @@ RSpec.describe DropletKit::ImageResource do
12
12
 
13
13
  expect(resource.all).to eq(expected_images)
14
14
  end
15
+
16
+ it 'returns private images' do
17
+ images_json = api_fixture('images/all')
18
+ stub_do_api('/v2/images', :get)
19
+ .with(query: hash_including({ private: 'true' }))
20
+ .to_return(body: images_json)
21
+ expected_images = DropletKit::ImageMapping.extract_collection images_json, :read
22
+
23
+ expect(resource.all(private: true)).to eq(expected_images)
24
+ end
25
+
26
+ it 'returns images of a type' do
27
+ images_json = api_fixture('images/all')
28
+ stub_do_api('/v2/images', :get)
29
+ .with(query: hash_including({ type: 'application' }))
30
+ .to_return(body: images_json)
31
+ expected_images = DropletKit::ImageMapping.extract_collection images_json, :read
32
+
33
+ expect(resource.all(type: :application)).to eq(expected_images)
34
+ end
15
35
  end
16
36
 
17
37
  describe '#find' do
@@ -25,6 +45,7 @@ RSpec.describe DropletKit::ImageResource do
25
45
  expect(image.slug).to eq(nil)
26
46
  expect(image.public).to eq(false)
27
47
  expect(image.regions).to eq(["region--1"])
48
+ expect(image.type).to eq("snapshot")
28
49
  end
29
50
  end
30
51
 
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.2.1
4
+ version: 1.2.2
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-03-20 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -56,16 +56,22 @@ dependencies:
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - '>'
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - - <
60
63
  - !ruby/object:Gem::Version
61
- version: 4.1.6
64
+ version: 5.0.0
62
65
  type: :runtime
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - ~>
69
+ - - '>'
70
+ - !ruby/object:Gem::Version
71
+ version: '3.0'
72
+ - - <
67
73
  - !ruby/object:Gem::Version
68
- version: 4.1.6
74
+ version: 5.0.0
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: faraday
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +194,7 @@ files:
188
194
  - lib/droplet_kit/mappings/domain_mapping.rb
189
195
  - lib/droplet_kit/mappings/domain_record_mapping.rb
190
196
  - lib/droplet_kit/mappings/droplet_mapping.rb
197
+ - lib/droplet_kit/mappings/droplet_upgrade_mapping.rb
191
198
  - lib/droplet_kit/mappings/error_mapping.rb
192
199
  - lib/droplet_kit/mappings/image_action_mapping.rb
193
200
  - lib/droplet_kit/mappings/image_mapping.rb
@@ -205,6 +212,7 @@ files:
205
212
  - lib/droplet_kit/models/domain.rb
206
213
  - lib/droplet_kit/models/domain_record.rb
207
214
  - lib/droplet_kit/models/droplet.rb
215
+ - lib/droplet_kit/models/droplet_upgrade.rb
208
216
  - lib/droplet_kit/models/image.rb
209
217
  - lib/droplet_kit/models/image_action.rb
210
218
  - lib/droplet_kit/models/kernel.rb
@@ -223,6 +231,7 @@ files:
223
231
  - lib/droplet_kit/resources/domain_resource.rb
224
232
  - lib/droplet_kit/resources/droplet_action_resource.rb
225
233
  - lib/droplet_kit/resources/droplet_resource.rb
234
+ - lib/droplet_kit/resources/droplet_upgrade_resource.rb
226
235
  - lib/droplet_kit/resources/image_action_resource.rb
227
236
  - lib/droplet_kit/resources/image_resource.rb
228
237
  - lib/droplet_kit/resources/region_resource.rb
@@ -240,6 +249,7 @@ files:
240
249
  - spec/fixtures/domains/all.json
241
250
  - spec/fixtures/domains/create.json
242
251
  - spec/fixtures/domains/find.json
252
+ - spec/fixtures/droplet_upgrades/all.json
243
253
  - spec/fixtures/droplets/all.json
244
254
  - spec/fixtures/droplets/all_empty.json
245
255
  - spec/fixtures/droplets/create.json
@@ -249,7 +259,6 @@ files:
249
259
  - spec/fixtures/droplets/list_kernels.json
250
260
  - spec/fixtures/droplets/list_snapshots.json
251
261
  - spec/fixtures/image_actions/all.json
252
- - spec/fixtures/image_actions/create.json
253
262
  - spec/fixtures/image_actions/find.json
254
263
  - spec/fixtures/images/all.json
255
264
  - spec/fixtures/images/find.json
@@ -269,6 +278,7 @@ files:
269
278
  - spec/lib/droplet_kit/resources/domain_resource_spec.rb
270
279
  - spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb
271
280
  - spec/lib/droplet_kit/resources/droplet_resource_spec.rb
281
+ - spec/lib/droplet_kit/resources/droplet_upgrade_resource_spec.rb
272
282
  - spec/lib/droplet_kit/resources/image_action_resource_spec.rb
273
283
  - spec/lib/droplet_kit/resources/image_resource_spec.rb
274
284
  - spec/lib/droplet_kit/resources/region_resource_spec.rb
@@ -314,6 +324,7 @@ test_files:
314
324
  - spec/fixtures/domains/all.json
315
325
  - spec/fixtures/domains/create.json
316
326
  - spec/fixtures/domains/find.json
327
+ - spec/fixtures/droplet_upgrades/all.json
317
328
  - spec/fixtures/droplets/all.json
318
329
  - spec/fixtures/droplets/all_empty.json
319
330
  - spec/fixtures/droplets/create.json
@@ -323,7 +334,6 @@ test_files:
323
334
  - spec/fixtures/droplets/list_kernels.json
324
335
  - spec/fixtures/droplets/list_snapshots.json
325
336
  - spec/fixtures/image_actions/all.json
326
- - spec/fixtures/image_actions/create.json
327
337
  - spec/fixtures/image_actions/find.json
328
338
  - spec/fixtures/images/all.json
329
339
  - spec/fixtures/images/find.json
@@ -343,6 +353,7 @@ test_files:
343
353
  - spec/lib/droplet_kit/resources/domain_resource_spec.rb
344
354
  - spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb
345
355
  - spec/lib/droplet_kit/resources/droplet_resource_spec.rb
356
+ - spec/lib/droplet_kit/resources/droplet_upgrade_resource_spec.rb
346
357
  - spec/lib/droplet_kit/resources/image_action_resource_spec.rb
347
358
  - spec/lib/droplet_kit/resources/image_resource_spec.rb
348
359
  - spec/lib/droplet_kit/resources/region_resource_spec.rb
@@ -1,19 +0,0 @@
1
- {
2
- "action": {
3
- "id": 23,
4
- "status": "in-progress",
5
- "type": "transfer",
6
- "started_at": "2014-08-05T15:15:28Z",
7
- "completed_at": null,
8
- "resource_id": 449676391,
9
- "resource_type": "image",
10
- "region_slug": "nyc1",
11
- "region": {
12
- "name": "New York",
13
- "slug": "nyc1",
14
- "available": true,
15
- "sizes": ["512mb"],
16
- "features": ["virtio", "private_networking", "backups", "ipv6", "metadata"]
17
- }
18
- }
19
- }