droplet_kit 1.2.2 → 1.2.3

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: c7ec2875e0c5cdc19cca7b6660ea0a1ccb03e3dd
4
- data.tar.gz: 8e293ff411e4fa8c276b402a8c046a30dabb512a
3
+ metadata.gz: 8248d66e3b2a7ea6e7525aa221378fefd3089202
4
+ data.tar.gz: 2fc041cce279e282b2775a7dfc183aff9fd3dbb8
5
5
  SHA512:
6
- metadata.gz: da7a4a687a6b048947355157036e0ed363c37d3a5cd274b0d802846be0ba734af181839e74d1f190a8f43159604be1a5e26342dfaaf26a985294f97e365932cb
7
- data.tar.gz: 5a81bcc796c32dedfb5247333c53bf5e2fad5b6c285b38ddd872f619cfbced1c6cc8e7dd3fa2d90994fc4a128bc793b0119ff66d13c8a532493ff291986398d6
6
+ metadata.gz: f8546836585fd8f04ed333ab3a66e66e3d7ac9bc34690e09e91323090d9d60c2a908ed968dc3412826177f4b67e72482f51fe190d6d9e31cfceba60ab9c6279b
7
+ data.tar.gz: 5b3bbc5443f5119c09bfeca6138f6d0636ea6b193e50cf75011ee6df591ab93cd85621cc34c591e8b651a4a6b690f6e72cb1c434094ea7acd350fd1e71412f88
@@ -7,9 +7,14 @@ module DropletKit
7
7
  root_key singular: 'size', plural: 'sizes', scopes: [:read]
8
8
 
9
9
  property :slug, scopes: [:read]
10
+ property :memory, scopes: [:read]
11
+ property :vcpus, scopes: [:read]
12
+ property :disk, scopes: [:read]
10
13
  property :transfer, scopes: [:read]
11
14
  property :price_monthly, scopes: [:read]
12
15
  property :price_hourly, scopes: [:read]
16
+ property :regions, scopes: [:read]
17
+ property :available, scopes: [:read]
13
18
  end
14
19
  end
15
- end
20
+ end
@@ -1,8 +1,13 @@
1
1
  module DropletKit
2
2
  class Size < BaseModel
3
3
  attribute :slug
4
+ attribute :memory
5
+ attribute :vcpus
6
+ attribute :disk
4
7
  attribute :transfer
5
8
  attribute :price_monthly
6
9
  attribute :price_hourly
10
+ attribute :regions
11
+ attribute :available
7
12
  end
8
- end
13
+ end
@@ -2,6 +2,7 @@ module DropletKit
2
2
  class DomainRecordResource < ResourceKit::Resource
3
3
  resources do
4
4
  action :all, 'GET /v2/domains/:for_domain/records' do
5
+ query_keys :per_page, :page
5
6
  handler(200) { |response| DomainRecordMapping.extract_collection(response.body, :read) }
6
7
  end
7
8
 
@@ -28,4 +29,4 @@ module DropletKit
28
29
  PaginatedResource.new(action(:all), self, *args)
29
30
  end
30
31
  end
31
- end
32
+ end
@@ -2,6 +2,7 @@ module DropletKit
2
2
  class DomainResource < ResourceKit::Resource
3
3
  resources do
4
4
  action :all, 'GET /v2/domains' do
5
+ query_keys :per_page, :page
5
6
  handler(200) { |response| DomainMapping.extract_collection(response.body, :read) }
6
7
  end
7
8
 
@@ -23,4 +24,4 @@ module DropletKit
23
24
  PaginatedResource.new(action(:all), self, *args)
24
25
  end
25
26
  end
26
- end
27
+ end
@@ -2,7 +2,6 @@ module DropletKit
2
2
  class DropletUpgradeResource < ResourceKit::Resource
3
3
  resources do
4
4
  action :all, 'GET /v2/droplet_upgrades' do
5
- query_keys :per_page, :page
6
5
  handler(200) { |response| DropletUpgradeMapping.extract_collection(response.body, :read) }
7
6
  end
8
7
  end
@@ -12,6 +12,7 @@ module DropletKit
12
12
  end
13
13
 
14
14
  action :all, 'GET /v2/images/:image_id/actions' do
15
+ query_keys :per_page, :page
15
16
  handler(200) { |response| ImageActionMapping.extract_collection(response.body, :read) }
16
17
  end
17
18
 
@@ -24,4 +25,4 @@ module DropletKit
24
25
  PaginatedResource.new(action(:all), self, *args)
25
26
  end
26
27
  end
27
- end
28
+ end
@@ -2,6 +2,7 @@ module DropletKit
2
2
  class RegionResource < ResourceKit::Resource
3
3
  resources do
4
4
  action :all, 'GET /v2/regions' do
5
+ query_keys :per_page, :page
5
6
  handler(200) { |r| RegionMapping.extract_collection(r.body, :read) }
6
7
  end
7
8
  end
@@ -10,4 +11,4 @@ module DropletKit
10
11
  PaginatedResource.new(action(:all), self, *args)
11
12
  end
12
13
  end
13
- end
14
+ end
@@ -2,6 +2,7 @@ module DropletKit
2
2
  class SizeResource < ResourceKit::Resource
3
3
  resources do
4
4
  action :all, 'GET /v2/sizes' do
5
+ query_keys :per_page, :page
5
6
  handler(200) { |r| SizeMapping.extract_collection(r.body, :read) }
6
7
  end
7
8
  end
@@ -10,4 +11,4 @@ module DropletKit
10
11
  PaginatedResource.new(action(:all), self, *args)
11
12
  end
12
13
  end
13
- end
14
+ end
@@ -4,6 +4,7 @@ module DropletKit
4
4
  default_handler(:ok, :created) {|r| SSHKeyMapping.extract_single(r.body, :read) }
5
5
 
6
6
  action :all, 'GET /v2/account/keys' do
7
+ query_keys :per_page, :page
7
8
  handler(:ok) { |response| SSHKeyMapping.extract_collection(response.body, :read) }
8
9
  end
9
10
 
@@ -23,4 +24,4 @@ module DropletKit
23
24
  PaginatedResource.new(action(:all), self, *args)
24
25
  end
25
26
  end
26
- end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module DropletKit
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
@@ -12,7 +12,8 @@
12
12
  "nyc1",
13
13
  "ams1",
14
14
  "sfo1"
15
- ]
15
+ ],
16
+ "available": true
16
17
  },
17
18
  {
18
19
  "slug": "1gb",
@@ -26,10 +27,11 @@
26
27
  "nyc1",
27
28
  "ams1",
28
29
  "sfo1"
29
- ]
30
+ ],
31
+ "available": true
30
32
  }
31
33
  ],
32
34
  "meta": {
33
35
  "total": 2
34
36
  }
35
- }
37
+ }
@@ -34,6 +34,11 @@ RSpec.describe DropletKit::ActionResource do
34
34
  expect(actions.first.region.available).to be(true)
35
35
  expect(actions.first.region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
36
36
  end
37
+
38
+ it_behaves_like 'a paginated index' do
39
+ let(:fixture_path) { 'actions/all' }
40
+ let(:api_path) { '/v2/actions' }
41
+ end
37
42
  end
38
43
 
39
44
  describe '#find' do
@@ -15,6 +15,11 @@ RSpec.describe DropletKit::DomainRecordResource do
15
15
  expect(returned_records).to all(be_kind_of(DropletKit::DomainRecord))
16
16
  expect(returned_records).to eq(expected_records)
17
17
  end
18
+
19
+ it_behaves_like 'a paginated index' do
20
+ let(:fixture_path) {'domain_records/all'}
21
+ let(:api_path) {'/v2/domains/example.com/records'}
22
+ end
18
23
  end
19
24
 
20
25
  describe '#create' do
@@ -80,4 +85,4 @@ RSpec.describe DropletKit::DomainRecordResource do
80
85
  expect(updated_domain_record.data).to eq('@')
81
86
  end
82
87
  end
83
- end
88
+ end
@@ -12,6 +12,11 @@ RSpec.describe DropletKit::DomainResource do
12
12
 
13
13
  expect(resource.all).to eq(expected_domains)
14
14
  end
15
+
16
+ it_behaves_like 'a paginated index' do
17
+ let(:fixture_path) {'domains/all'}
18
+ let(:api_path) {'/v2/domains'}
19
+ end
15
20
  end
16
21
 
17
22
  describe '#create' do
@@ -50,4 +55,4 @@ RSpec.describe DropletKit::DomainResource do
50
55
  expect(request).to have_been_made
51
56
  end
52
57
  end
53
- end
58
+ end
@@ -75,6 +75,11 @@ RSpec.describe DropletKit::DropletResource do
75
75
  droplets = resource.all.map(&:id)
76
76
  expect(droplets).to be_empty
77
77
  end
78
+
79
+ it_behaves_like 'a paginated index' do
80
+ let(:fixture_path) { 'droplets/all' }
81
+ let(:api_path) { '/v2/droplets' }
82
+ end
78
83
  end
79
84
 
80
85
  describe '#find' do
@@ -143,6 +148,12 @@ RSpec.describe DropletKit::DropletResource do
143
148
  expect(kernels[1].name).to eq('Ubuntu 14.04 x64 vmlinuz-3.13.0-24-generic (1221)')
144
149
  expect(kernels[1].version).to eq('3.13.0-24-generic')
145
150
  end
151
+
152
+ it 'returns a paginated resource' do
153
+ stub_do_api('/v2/droplets/1066/kernels', :get).to_return(body: api_fixture('droplets/list_kernels'))
154
+ kernels = resource.kernels(id: 1066, page: 1, per_page: 1)
155
+ expect(kernels).to be_kind_of(DropletKit::PaginatedResource)
156
+ end
146
157
  end
147
158
 
148
159
  describe '#snapshots' do
@@ -159,6 +170,12 @@ RSpec.describe DropletKit::DropletResource do
159
170
  expect(snapshots[0].regions).to eq(["nyc1"])
160
171
  expect(snapshots[0].created_at).to eq("2014-07-29T14:35:38Z")
161
172
  end
173
+
174
+ it 'returns a paginated resource' do
175
+ stub_do_api('/v2/droplets/1066/snapshots', :get).to_return(body: api_fixture('droplets/list_snapshots'))
176
+ snapshots = resource.snapshots(id: 1066, page: 1, per_page: 1)
177
+ expect(snapshots).to be_kind_of(DropletKit::PaginatedResource)
178
+ end
162
179
  end
163
180
 
164
181
  describe '#backups' do
@@ -175,6 +192,12 @@ RSpec.describe DropletKit::DropletResource do
175
192
  expect(backups[0].regions).to eq(["nyc1"])
176
193
  expect(backups[0].created_at).to eq("2014-07-29T14:35:38Z")
177
194
  end
195
+
196
+ it 'returns a paginated resource' do
197
+ stub_do_api('/v2/droplets/1066/backups', :get).to_return(body: api_fixture('droplets/list_backups'))
198
+ backups = resource.backups(id: 1066, page: 1, per_page: 1)
199
+ expect(backups).to be_kind_of(DropletKit::PaginatedResource)
200
+ end
178
201
  end
179
202
 
180
203
  describe '#actions' do
@@ -198,6 +221,12 @@ RSpec.describe DropletKit::DropletResource do
198
221
  expect(actions[0].region.available).to be(true)
199
222
  expect(actions[0].region.features).to include("virtio", "private_networking", "backups", "ipv6", "metadata")
200
223
  end
224
+
225
+ it 'returns a paginated resource' do
226
+ stub_do_api('/v2/droplets/1066/actions', :get).to_return(body: api_fixture('droplets/list_actions'))
227
+ actions = resource.actions(id: 1066, page: 1, per_page: 1)
228
+ expect(actions).to be_kind_of(DropletKit::PaginatedResource)
229
+ end
201
230
  end
202
231
 
203
232
  describe '#delete' do
@@ -113,6 +113,11 @@ RSpec.describe DropletKit::ImageActionResource do
113
113
  expect(action.region).to eq(nil)
114
114
  expect(action.region_slug).to eq(nil)
115
115
  end
116
+
117
+ it_behaves_like 'a paginated index' do
118
+ let(:fixture_path) {'image_actions/all'}
119
+ let(:api_path) {'/v2/images/45646587/actions'}
120
+ end
116
121
  end
117
122
 
118
123
  describe '#find' do
@@ -32,6 +32,11 @@ RSpec.describe DropletKit::ImageResource do
32
32
 
33
33
  expect(resource.all(type: :application)).to eq(expected_images)
34
34
  end
35
+
36
+ it_behaves_like 'a paginated index' do
37
+ let(:fixture_path) { 'images/all' }
38
+ let(:api_path) { '/v2/images' }
39
+ end
35
40
  end
36
41
 
37
42
  describe '#find' do
@@ -12,5 +12,10 @@ RSpec.describe DropletKit::RegionResource do
12
12
 
13
13
  expect(resource.all).to eq(expected)
14
14
  end
15
+
16
+ it_behaves_like 'a paginated index' do
17
+ let(:fixture_path) {'regions/all'}
18
+ let(:api_path) {'/v2/regions'}
19
+ end
15
20
  end
16
21
  end
@@ -12,5 +12,10 @@ RSpec.describe DropletKit::SizeResource do
12
12
 
13
13
  expect(resource.all).to eq(expected)
14
14
  end
15
+
16
+ it_behaves_like 'a paginated index' do
17
+ let(:fixture_path) {'sizes/all'}
18
+ let(:api_path) {'/v2/sizes'}
19
+ end
15
20
  end
16
- end
21
+ end
@@ -16,6 +16,11 @@ RSpec.describe DropletKit::SSHKeyResource do
16
16
  expect(ssh_keys.first.public_key).to eq("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDGk5V68BJ4P3Ereh779Vi/Ft2qs/rbXrcjKLGo6zsyeyFUE0svJUpRDEJvFSf8RlezKx1/1ulJu9+kZsxRiUKn example")
17
17
  expect(ssh_keys.first.name).to eq("Example Key")
18
18
  end
19
+
20
+ it_behaves_like 'a paginated index' do
21
+ let(:fixture_path) {'ssh_keys/all'}
22
+ let(:api_path) {'/v2/ssh_keys'}
23
+ end
19
24
  end
20
25
 
21
26
  describe '#create' do
@@ -77,4 +82,4 @@ RSpec.describe DropletKit::SSHKeyResource do
77
82
  expect(request).to have_been_made
78
83
  end
79
84
  end
80
- end
85
+ end
@@ -0,0 +1,13 @@
1
+ # To use this, `fixture_path`, `api_path` and a `resource` must be defined
2
+ # using `let`s.
3
+ shared_examples_for 'a paginated index' do
4
+ let(:fixture_path) { }
5
+ let(:api_path) { }
6
+
7
+ it 'returns a paginated resource' do
8
+ fixture = api_fixture(fixture_path)
9
+ stub_do_api(api_path, :get).to_return(body: fixture)
10
+ response = resource.all(page: 1, per_page: 1)
11
+ expect(response).to be_kind_of(DropletKit::PaginatedResource)
12
+ end
13
+ end
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.2
4
+ version: 1.2.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-05-26 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -289,6 +289,7 @@ files:
289
289
  - spec/support/null_hash_load.rb
290
290
  - spec/support/request_stub_helpers.rb
291
291
  - spec/support/resource_context.rb
292
+ - spec/support/shared_examples/paginated_endpoint.rb
292
293
  homepage: ''
293
294
  licenses:
294
295
  - MIT
@@ -364,3 +365,4 @@ test_files:
364
365
  - spec/support/null_hash_load.rb
365
366
  - spec/support/request_stub_helpers.rb
366
367
  - spec/support/resource_context.rb
368
+ - spec/support/shared_examples/paginated_endpoint.rb