droplet_kit 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG.md +17 -0
  4. data/README.md +35 -0
  5. data/droplet_kit.gemspec +4 -2
  6. data/lib/droplet_kit.rb +3 -0
  7. data/lib/droplet_kit/client.rb +3 -1
  8. data/lib/droplet_kit/mappings/account_mapping.rb +17 -0
  9. data/lib/droplet_kit/mappings/droplet_mapping.rb +2 -0
  10. data/lib/droplet_kit/models/account.rb +8 -0
  11. data/lib/droplet_kit/models/droplet.rb +2 -0
  12. data/lib/droplet_kit/models/image.rb +1 -1
  13. data/lib/droplet_kit/paginated_resource.rb +5 -6
  14. data/lib/droplet_kit/resources/account_resource.rb +8 -0
  15. data/lib/droplet_kit/resources/action_resource.rb +2 -1
  16. data/lib/droplet_kit/resources/domain_record_resource.rb +1 -1
  17. data/lib/droplet_kit/resources/domain_resource.rb +1 -1
  18. data/lib/droplet_kit/resources/droplet_action_resource.rb +2 -2
  19. data/lib/droplet_kit/resources/droplet_resource.rb +22 -2
  20. data/lib/droplet_kit/resources/image_resource.rb +2 -2
  21. data/lib/droplet_kit/resources/region_resource.rb +1 -1
  22. data/lib/droplet_kit/resources/size_resource.rb +1 -1
  23. data/lib/droplet_kit/resources/ssh_key_resource.rb +1 -1
  24. data/lib/droplet_kit/version.rb +1 -1
  25. data/spec/fixtures/account/info.json +8 -0
  26. data/spec/fixtures/droplets/all.json +7 -1
  27. data/spec/fixtures/droplets/create.json +7 -1
  28. data/spec/fixtures/droplets/find.json +7 -1
  29. data/spec/lib/droplet_kit/paginated_resource_spec.rb +6 -6
  30. data/spec/lib/droplet_kit/resources/account_resource_spec.rb +24 -0
  31. data/spec/lib/droplet_kit/resources/action_resource_spec.rb +1 -1
  32. data/spec/lib/droplet_kit/resources/domain_record_resource_spec.rb +1 -1
  33. data/spec/lib/droplet_kit/resources/domain_resource_spec.rb +1 -1
  34. data/spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb +3 -3
  35. data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +21 -11
  36. data/spec/lib/droplet_kit/resources/image_action_resource_spec.rb +1 -1
  37. data/spec/lib/droplet_kit/resources/image_resource_spec.rb +1 -1
  38. data/spec/lib/droplet_kit/resources/region_resource_spec.rb +2 -2
  39. data/spec/lib/droplet_kit/resources/size_resource_spec.rb +1 -1
  40. data/spec/lib/droplet_kit/resources/ssh_key_resource_spec.rb +1 -1
  41. metadata +16 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62a4987734e9797532835df94d983541b086ae07
4
- data.tar.gz: ec155d10bdc6283b0a89000d17fc529eeab3a166
3
+ metadata.gz: 049df1218b2a89e735a4aa6a21b6021f1aa2babf
4
+ data.tar.gz: c04ff432b31fb45e1cdf3bb05af3674f07adfc32
5
5
  SHA512:
6
- metadata.gz: f3b979fe64594230f98330f6b140455cd2e9c55f673f3afe33ef1dcf088d04465d2f9489a45dcf037c0805ca45608d2cc3efd32c01ddec4663ee6d0f0922bd38
7
- data.tar.gz: fbb993a4c5592d5ae321e86771ba01740848720c2f3b7119e77ed1a6797ff74e1e24608c65867b9d47430d3e86f6f892c61dcb314b744e782c2b5b81dfd2cece
6
+ metadata.gz: 9dff4c196ff43708ae25e5ee2d285e86758a021cba20045d37bb8d7016d21e1644b1b439e657de6de6f8bcb87c974ccd28ae2edf683f2d0658c99ca540554561
7
+ data.tar.gz: 8f28a270b70529fbca2862f461c24dee13af86ba5dbb9a13acce7ad6173b9ee7286fc15d6ded6beb6404eb95a5641b7d19aaac8587c47234f55e7f68139b76fb
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - "2.0.0-p594"
3
+ - "2.1.4"
4
+
5
+ script: bundle exec rspec ./spec
@@ -0,0 +1,17 @@
1
+ ### Version 1.1.0
2
+
3
+ * Changing kernels is now `client.droplet_actions.change_kernel(kernel: 'name', droplet_id: 123)` instead of `droplet_actions.kernel()`.
4
+ * Include Account resource. `client.account`. This allows you to grab information about the user for the access token provided.
5
+ * Paginate more resources. This includes:
6
+ * Droplet Kernels
7
+ * Actions
8
+ * Snapshots
9
+ * Backups
10
+ * Allow creating droplets with User Data and Private Networking
11
+ * See [#8](https://github.com/digitalocean/droplet_kit/pull/8) - Thanks @rbishop !
12
+ * Fixed a bug where if the resource was paginated and returning 0 entries, an infinite loop would occur.
13
+ * See [#11](https://github.com/digitalocean/droplet_kit/pull/11) - Thanks @webdestroya !
14
+
15
+ ### August 8, 2014 (Initial Release)
16
+
17
+ * Initial Release
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  DropletKit is the official [DigitalOcean V2 API](https://developers.digitalocean.com/v2/) client. It supports everything the API can do with a simple interface written in Ruby.
4
4
 
5
+ [![Build Status](https://travis-ci.org/digitalocean/droplet_kit.svg?branch=master)](https://travis-ci.org/digitalocean/droplet_kit)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -61,6 +63,7 @@ droplet = client.droplets.find(id: 123)
61
63
  ```
62
64
 
63
65
  # All Resources and actions.
66
+
64
67
  ## Droplet resource
65
68
 
66
69
  client = DropletKit::Client.new(access_token: 'TOKEN')
@@ -77,6 +80,29 @@ Actions supported:
77
80
  * `client.droplets.backups(id: 'id')`
78
81
  * `client.droplets.actions(id: 'id')`
79
82
 
83
+ ## Droplet Action resource
84
+
85
+ client = DropletKit::Client.new(access_token: 'TOKEN')
86
+ client.droplet_actions #=> DropletKit::DropletAction
87
+
88
+ Actions supported:
89
+
90
+ * `client.droplet_actions.reboot(droplet_id: droplet.id)`
91
+ * `client.droplet_actions.power_cycle(droplet_id: droplet.id)`
92
+ * `client.droplet_actions.shutdown(droplet_id: droplet.id)`
93
+ * `client.droplet_actions.power_off(droplet_id: droplet.id)`
94
+ * `client.droplet_actions.power_on(droplet_id: droplet.id)`
95
+ * `client.droplet_actions.password_reset(droplet_id: droplet.id)`
96
+ * `client.droplet_actions.enable_ipv6(droplet_id: droplet.id)`
97
+ * `client.droplet_actions.disable_backups(droplet_id: droplet.id)`
98
+ * `client.droplet_actions.enable_private_networking(droplet_id: droplet.id)`
99
+ * `client.droplet_actions.snapshot(droplet_id: droplet.id, name: 'Snapshot Name')`
100
+ * `client.droplet_actions.change_kernel(droplet_id: droplet.id, kernel: 'kernel_id')`
101
+ * `client.droplet_actions.rename(droplet_id: droplet.id, name: 'New-Droplet-Name')`
102
+ * `client.droplet_actions.rebuild(droplet_id: droplet.id, image: 'image_id')`
103
+ * `client.droplet_actions.restore(droplet_id: droplet.id, image: 'image_id')`
104
+ * `client.droplet_actions.resize(droplet_id: droplet.id, size: '1gb')`
105
+ * `client.droplet_actions.find(droplet_id: droplet.id, id: action.id)`
80
106
 
81
107
  ## Domain resource
82
108
 
@@ -151,6 +177,15 @@ Actions supported:
151
177
  * `client.ssh_keys.delete(id: 'id')`
152
178
  * `client.ssh_keys.update(ssh_key, id: 'id')`
153
179
 
180
+ ## Account resource
181
+
182
+ client = DropletKit::Client.new(access_token: 'TOKEN')
183
+ client.account #=> DropletKit::AccountResource
184
+
185
+ Actions supported:
186
+
187
+ * `client.account.info()`
188
+
154
189
 
155
190
  ## Contributing
156
191
 
@@ -17,10 +17,12 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.0.0'
20
22
 
21
23
  spec.add_dependency 'virtus', '~> 1.0.3'
22
- spec.add_dependency "resource_kit", '~> 0.0.5'
23
- spec.add_dependency "kartograph", '~> 0.0.5'
24
+ spec.add_dependency "resource_kit", '~> 0.1.1'
25
+ spec.add_dependency "kartograph", '~> 0.2.0'
24
26
  spec.add_dependency "activesupport", '~> 4.1.6'
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -23,6 +23,7 @@ module DropletKit
23
23
  autoload :DomainRecord, 'droplet_kit/models/domain_record'
24
24
  autoload :SSHKey, 'droplet_kit/models/ssh_key'
25
25
  autoload :MetaInformation, 'droplet_kit/models/meta_information'
26
+ autoload :Account, 'droplet_kit/models/account'
26
27
 
27
28
  # Resources
28
29
  autoload :DropletResource, 'droplet_kit/resources/droplet_resource'
@@ -35,6 +36,7 @@ module DropletKit
35
36
  autoload :SSHKeyResource, 'droplet_kit/resources/ssh_key_resource'
36
37
  autoload :RegionResource, 'droplet_kit/resources/region_resource'
37
38
  autoload :SizeResource, 'droplet_kit/resources/size_resource'
39
+ autoload :AccountResource, 'droplet_kit/resources/account_resource'
38
40
 
39
41
  # JSON Maps
40
42
  autoload :DropletMapping, 'droplet_kit/mappings/droplet_mapping'
@@ -52,6 +54,7 @@ module DropletKit
52
54
  autoload :DropletActionMapping, 'droplet_kit/mappings/droplet_action_mapping'
53
55
  autoload :ImageActionMapping, 'droplet_kit/mappings/image_action_mapping'
54
56
  autoload :SSHKeyMapping, 'droplet_kit/mappings/ssh_key_mapping'
57
+ autoload :AccountMapping, 'droplet_kit/mappings/account_mapping'
55
58
 
56
59
 
57
60
  # Utils
@@ -18,6 +18,7 @@ module DropletKit
18
18
 
19
19
  def self.resources
20
20
  {
21
+ actions: ActionResource,
21
22
  droplets: DropletResource,
22
23
  domains: DomainResource,
23
24
  domain_records: DomainRecordResource,
@@ -27,12 +28,13 @@ module DropletKit
27
28
  regions: RegionResource,
28
29
  sizes: SizeResource,
29
30
  ssh_keys: SSHKeyResource,
31
+ account: AccountResource,
30
32
  }
31
33
  end
32
34
 
33
35
  def method_missing(name, *args, &block)
34
36
  if self.class.resources.keys.include?(name)
35
- resources[name] ||= self.class.resources[name].new(connection)
37
+ resources[name] ||= self.class.resources[name].new(connection: connection)
36
38
  resources[name]
37
39
  else
38
40
  super
@@ -0,0 +1,17 @@
1
+ module DropletKit
2
+ class AccountMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ root_key singular: 'account', scopes: [:read]
7
+ mapping Account
8
+
9
+ scoped :read do
10
+ property :droplet_limit
11
+ property :email
12
+ property :uuid
13
+ property :email_verified
14
+ end
15
+ end
16
+ end
17
+ end
@@ -33,6 +33,8 @@ module DropletKit
33
33
  property :ssh_keys, scopes: [:create]
34
34
  property :backups, scopes: [:create]
35
35
  property :ipv6, scopes: [:create]
36
+ property :user_data, scopes: [:create]
37
+ property :private_networking, scopes: [:create]
36
38
  end
37
39
  end
38
40
  end
@@ -0,0 +1,8 @@
1
+ module DropletKit
2
+ class Account < BaseModel
3
+ attribute :droplet_limit
4
+ attribute :email
5
+ attribute :uuid
6
+ attribute :email_verified
7
+ end
8
+ end
@@ -10,6 +10,8 @@ module DropletKit
10
10
  attribute :ssh_keys
11
11
  attribute :backups
12
12
  attribute :ipv6
13
+ attribute :user_data
14
+ attribute :private_networking
13
15
  end
14
16
  end
15
17
 
@@ -7,4 +7,4 @@ module DropletKit
7
7
  attribute :public
8
8
  attribute :regions
9
9
  end
10
- end
10
+ end
@@ -4,14 +4,14 @@ module DropletKit
4
4
 
5
5
  PER_PAGE = 20
6
6
 
7
- attr_reader :action, :connection, :collection
7
+ attr_reader :action, :resource, :collection
8
8
  attr_accessor :total
9
9
 
10
- def initialize(action_connection, *args)
10
+ def initialize(action, resource, *args)
11
11
  @current_page = 0
12
12
  @total = nil
13
- @action = action_connection.action
14
- @connection = action_connection.connection
13
+ @action = action
14
+ @resource = resource
15
15
  @collection = []
16
16
  @args = args
17
17
  @options = args.last.kind_of?(Hash) ? args.last : {}
@@ -44,7 +44,6 @@ module DropletKit
44
44
  end
45
45
 
46
46
  def ==(other)
47
- return false if self.total != other.length
48
47
  each_with_index.each.all? {|object, index| object == other[index] }
49
48
  end
50
49
 
@@ -56,7 +55,7 @@ module DropletKit
56
55
  end
57
56
 
58
57
  def retrieve(page, per_page = self.per_page)
59
- invoker = ResourceKit::ActionInvoker.new(action, connection, *@args)
58
+ invoker = ResourceKit::ActionInvoker.new(action, resource, *@args)
60
59
  invoker.options[:per_page] ||= per_page
61
60
  invoker.options[:page] = page
62
61
 
@@ -0,0 +1,8 @@
1
+ module DropletKit
2
+ class AccountResource < ResourceKit::Resource
3
+ resources do
4
+ default_handler(:ok) {|r| AccountMapping.extract_single(r.body, :read) }
5
+ get '/v2/account' => :info
6
+ end
7
+ end
8
+ end
@@ -2,6 +2,7 @@ module DropletKit
2
2
  class ActionResource < ResourceKit::Resource
3
3
  resources do
4
4
  action :all, 'GET /v2/actions' do
5
+ query_keys :per_page, :page
5
6
  handler(200) { |response| ActionMapping.extract_collection(response.body, :read) }
6
7
  end
7
8
 
@@ -11,7 +12,7 @@ module DropletKit
11
12
  end
12
13
 
13
14
  def all(*args)
14
- PaginatedResource.new(action_and_connection(:all), *args)
15
+ PaginatedResource.new(action(:all), self, *args)
15
16
  end
16
17
  end
17
18
  end
@@ -25,7 +25,7 @@ module DropletKit
25
25
  end
26
26
 
27
27
  def all(*args)
28
- PaginatedResource.new(action_and_connection(:all), *args)
28
+ PaginatedResource.new(action(:all), self, *args)
29
29
  end
30
30
  end
31
31
  end
@@ -20,7 +20,7 @@ module DropletKit
20
20
  end
21
21
 
22
22
  def all(*args)
23
- PaginatedResource.new(action_and_connection(:all), *args)
23
+ PaginatedResource.new(action(:all), self, *args)
24
24
  end
25
25
  end
26
26
  end
@@ -16,8 +16,8 @@ module DropletKit
16
16
  handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
17
17
  end
18
18
 
19
- action :kernel, 'POST /v2/droplets/:droplet_id/actions' do
20
- body { |hash| { type: 'kernel', kernel: hash[:kernel] }.to_json }
19
+ action :change_kernel, 'POST /v2/droplets/:droplet_id/actions' do
20
+ body { |hash| { type: 'change_kernel', kernel: hash[:kernel] }.to_json }
21
21
  handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
22
22
  end
23
23
 
@@ -21,24 +21,44 @@ module DropletKit
21
21
  end
22
22
 
23
23
  action :kernels, 'GET /v2/droplets/:id/kernels' do
24
+ query_keys :per_page, :page
24
25
  handler(200) { |response| KernelMapping.extract_collection(response.body, :read) }
25
26
  end
26
27
 
27
28
  action :snapshots, 'GET /v2/droplets/:id/snapshots' do
29
+ query_keys :per_page, :page
28
30
  handler(200) { |response| SnapshotMapping.extract_collection(response.body, :read) }
29
31
  end
30
32
 
31
33
  action :backups, 'GET /v2/droplets/:id/backups' do
34
+ query_keys :per_page, :page
32
35
  handler(200) { |response| BackupMapping.extract_collection(response.body, :read) }
33
36
  end
34
37
 
35
38
  action :actions, 'GET /v2/droplets/:id/actions' do
39
+ query_keys :per_page, :page
36
40
  handler(200) { |response| ActionMapping.extract_collection(response.body, :read) }
37
41
  end
38
42
  end
39
43
 
40
44
  def all(*args)
41
- PaginatedResource.new(action_and_connection(:all), *args)
45
+ PaginatedResource.new(action(:all), self, *args)
46
+ end
47
+
48
+ def kernels(*args)
49
+ PaginatedResource.new(action(:kernels), self, *args)
50
+ end
51
+
52
+ def snapshots(*args)
53
+ PaginatedResource.new(action(:snapshots), self, *args)
54
+ end
55
+
56
+ def backups(*args)
57
+ PaginatedResource.new(action(:backups), self, *args)
58
+ end
59
+
60
+ def actions(*args)
61
+ PaginatedResource.new(action(:actions), self, *args)
42
62
  end
43
63
  end
44
- end
64
+ 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
5
+ query_keys :page, :per_page, :type
6
6
  handler(200) { |response| ImageMapping.extract_collection(response.body, :read) }
7
7
  end
8
8
 
@@ -21,7 +21,7 @@ module DropletKit
21
21
  end
22
22
 
23
23
  def all(*args)
24
- PaginatedResource.new(action_and_connection(:all), *args)
24
+ PaginatedResource.new(action(:all), self, *args)
25
25
  end
26
26
  end
27
27
  end
@@ -7,7 +7,7 @@ module DropletKit
7
7
  end
8
8
 
9
9
  def all(*args)
10
- PaginatedResource.new(action_and_connection(:all), *args)
10
+ PaginatedResource.new(action(:all), self, *args)
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ module DropletKit
7
7
  end
8
8
 
9
9
  def all(*args)
10
- PaginatedResource.new(action_and_connection(:all), *args)
10
+ PaginatedResource.new(action(:all), self, *args)
11
11
  end
12
12
  end
13
13
  end
@@ -20,7 +20,7 @@ module DropletKit
20
20
  end
21
21
 
22
22
  def all(*args)
23
- PaginatedResource.new(action_and_connection(:all), *args)
23
+ PaginatedResource.new(action(:all), self, *args)
24
24
  end
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module DropletKit
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ {
2
+ "account": {
3
+ "droplet_limit": 200,
4
+ "email": "droplet_kit@digitalocean.com",
5
+ "uuid": "alksdjfhlakjdsfh12983712",
6
+ "email_verified": true
7
+ }
8
+ }
@@ -42,6 +42,12 @@
42
42
  "status": "active",
43
43
  "networks": {
44
44
  "v4": [
45
+ {
46
+ "ip_address": "10.0.0.19",
47
+ "netmask": "255.255.0.0",
48
+ "gateway": "10.0.0.1",
49
+ "type": "private"
50
+ },
45
51
  {
46
52
  "ip_address": "127.0.0.19",
47
53
  "netmask": "255.255.255.0",
@@ -81,4 +87,4 @@
81
87
  "meta": {
82
88
  "total": 1
83
89
  }
84
- }
90
+ }
@@ -41,6 +41,12 @@
41
41
  "status": "active",
42
42
  "networks": {
43
43
  "v4": [
44
+ {
45
+ "ip_address": "10.0.0.19",
46
+ "netmask": "255.255.0.0",
47
+ "gateway": "10.0.0.1",
48
+ "type": "private"
49
+ },
44
50
  {
45
51
  "ip_address": "127.0.0.19",
46
52
  "netmask": "255.255.255.0",
@@ -76,4 +82,4 @@
76
82
 
77
83
  ]
78
84
  }
79
- }
85
+ }
@@ -41,6 +41,12 @@
41
41
  "status": "active",
42
42
  "networks": {
43
43
  "v4": [
44
+ {
45
+ "ip_address": "10.0.0.19",
46
+ "netmask": "255.255.0.0",
47
+ "gateway": "10.0.0.1",
48
+ "type": "private"
49
+ },
44
50
  {
45
51
  "ip_address": "127.0.0.19",
46
52
  "netmask": "255.255.255.0",
@@ -76,4 +82,4 @@
76
82
 
77
83
  ]
78
84
  }
79
- }
85
+ }
@@ -4,6 +4,7 @@ require 'addressable/uri'
4
4
  RequestCounter = Struct.new(:count)
5
5
 
6
6
  RSpec.describe DropletKit::PaginatedResource do
7
+ let(:resource) { ResourceKit::Resource.new(connection: connection) }
7
8
  let(:request_count) { RequestCounter.new(0) }
8
9
 
9
10
  let(:connection) { Faraday.new {|b| b.adapter :test, stubs } }
@@ -23,7 +24,6 @@ RSpec.describe DropletKit::PaginatedResource do
23
24
  end
24
25
  end
25
26
  let(:action) { ResourceKit::Action.new(:find, :get, '/droplets') }
26
- let(:action_connection) { ResourceKit::ActionConnection.new(action, connection) }
27
27
 
28
28
  before do
29
29
  action.query_keys :per_page, :page
@@ -31,15 +31,15 @@ RSpec.describe DropletKit::PaginatedResource do
31
31
  end
32
32
 
33
33
  describe '#initialize' do
34
- it 'initializes with a action connection struct' do
35
- instance = DropletKit::PaginatedResource.new(action_connection)
34
+ it 'initializes with a action and resource' do
35
+ instance = DropletKit::PaginatedResource.new(action, resource)
36
36
  expect(instance.action).to be(action)
37
- expect(instance.connection).to be(connection)
37
+ expect(instance.resource).to be(resource)
38
38
  end
39
39
  end
40
40
 
41
41
  describe '#each' do
42
- subject(:paginated) { DropletKit::PaginatedResource.new(action_connection) }
42
+ subject(:paginated) { DropletKit::PaginatedResource.new(action, resource) }
43
43
 
44
44
  it 'iterates over every object returned from the API' do
45
45
  total = 0
@@ -59,7 +59,7 @@ RSpec.describe DropletKit::PaginatedResource do
59
59
  end
60
60
 
61
61
  context 'for changing size' do
62
- subject(:paginated) { DropletKit::PaginatedResource.new(action_connection, per_page: 40) }
62
+ subject(:paginated) { DropletKit::PaginatedResource.new(action, resource, per_page: 40) }
63
63
 
64
64
  it 'only calls the API once' do
65
65
  expect {|b| paginated.each {|c| c } }.to change { request_count.count }.to(1).from(0)
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DropletKit::AccountResource do
4
+ subject(:resource) { described_class.new(connection: connection) }
5
+ include_context 'resources'
6
+
7
+ describe '#info' do
8
+ it 'returns the information about the current user' do
9
+ fixture = api_fixture('account/info')
10
+ parsed = JSON.load(fixture)
11
+
12
+ stub_do_api('/v2/account').to_return(body: fixture)
13
+ account_info = resource.info
14
+
15
+ expect(account_info).to be_kind_of(DropletKit::Account)
16
+
17
+ expect(account_info.droplet_limit).to eq(parsed['account']['droplet_limit'])
18
+ expect(account_info.email).to eq(parsed['account']['email'])
19
+ expect(account_info.uuid).to eq(parsed['account']['uuid'])
20
+ expect(account_info.email_verified).to eq(parsed['account']['email_verified'])
21
+
22
+ end
23
+ end
24
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::ActionResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#all' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::DomainRecordResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#all' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::DomainResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#all' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::DropletActionResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  let(:droplet_id) { 1066 }
6
6
  def json
7
7
  {
@@ -55,8 +55,8 @@ RSpec.describe DropletKit::DropletActionResource do
55
55
  end
56
56
  end
57
57
 
58
- describe "Action kernel" do
59
- let(:action) { 'kernel' }
58
+ describe "Action change_kernel" do
59
+ let(:action) { 'change_kernel' }
60
60
 
61
61
  it 'performs the action' do
62
62
  request = stub_do_api("/v2/droplets/#{droplet_id}/actions", :post).with(
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::DropletResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  # Theres a lot to check
@@ -41,11 +41,17 @@ RSpec.describe DropletKit::DropletResource do
41
41
  expect(droplet.size.price_hourly).to eq(0.01488)
42
42
 
43
43
  expect(droplet.networks).to be_kind_of(DropletKit::NetworkHash)
44
- v4_network = droplet.networks.v4.first
45
- expect(v4_network.ip_address).to eq('127.0.0.19')
46
- expect(v4_network.netmask).to eq("255.255.255.0")
47
- expect(v4_network.gateway).to eq("127.0.0.20")
48
- expect(v4_network.type).to eq("public")
44
+ private_v4_network = droplet.networks.v4.first
45
+ expect(private_v4_network.ip_address).to eq('10.0.0.19')
46
+ expect(private_v4_network.netmask).to eq("255.255.0.0")
47
+ expect(private_v4_network.gateway).to eq("10.0.0.1")
48
+ expect(private_v4_network.type).to eq("private")
49
+
50
+ public_v4_network = droplet.networks.v4.last
51
+ expect(public_v4_network.ip_address).to eq('127.0.0.19')
52
+ expect(public_v4_network.netmask).to eq("255.255.255.0")
53
+ expect(public_v4_network.gateway).to eq("127.0.0.20")
54
+ expect(public_v4_network.type).to eq("public")
49
55
 
50
56
  v6_network = droplet.networks.v6.first
51
57
  expect(v6_network.ip_address).to eq('2001::13')
@@ -88,7 +94,9 @@ RSpec.describe DropletKit::DropletResource do
88
94
  image: 'ubuntu-14-04-x86',
89
95
  ssh_keys: [123],
90
96
  backups: true,
91
- ipv6: true
97
+ ipv6: true,
98
+ private_networking: true,
99
+ user_data: "#cloud-config\nruncmd\n\t- echo 'Hello!'"
92
100
  )
93
101
 
94
102
  as_hash = DropletKit::DropletMapping.representation_for(:create, droplet, NullHashLoad)
@@ -99,6 +107,8 @@ RSpec.describe DropletKit::DropletResource do
99
107
  expect(as_hash[:ssh_keys]).to eq(droplet.ssh_keys)
100
108
  expect(as_hash[:backups]).to eq(droplet.backups)
101
109
  expect(as_hash[:ipv6]).to eq(droplet.ipv6)
110
+ expect(as_hash[:private_networking]).to eq(droplet.private_networking)
111
+ expect(as_hash[:user_data]).to eq(droplet.user_data)
102
112
 
103
113
  as_string = DropletKit::DropletMapping.representation_for(:create, droplet)
104
114
  stub_do_api('/v2/droplets', :post).with(body: as_string).to_return(body: api_fixture('droplets/create'), status: 202)
@@ -120,7 +130,7 @@ RSpec.describe DropletKit::DropletResource do
120
130
  describe '#kernels' do
121
131
  it 'returns a list of kernels for a droplet' do
122
132
  stub_do_api('/v2/droplets/1066/kernels', :get).to_return(body: api_fixture('droplets/list_kernels'))
123
- kernels = resource.kernels(id: 1066)
133
+ kernels = resource.kernels(id: 1066).take(20)
124
134
 
125
135
  expect(kernels).to all(be_kind_of(DropletKit::Kernel))
126
136
  expect(kernels[0].id).to eq(61833229)
@@ -136,7 +146,7 @@ RSpec.describe DropletKit::DropletResource do
136
146
  describe '#snapshots' do
137
147
  it 'returns a list of kernels for a droplet' do
138
148
  stub_do_api('/v2/droplets/1066/snapshots', :get).to_return(body: api_fixture('droplets/list_snapshots'))
139
- snapshots = resource.snapshots(id: 1066)
149
+ snapshots = resource.snapshots(id: 1066).take(20)
140
150
 
141
151
  expect(snapshots).to all(be_kind_of(DropletKit::Snapshot))
142
152
  expect(snapshots[0].id).to eq(449676387)
@@ -152,7 +162,7 @@ RSpec.describe DropletKit::DropletResource do
152
162
  describe '#backups' do
153
163
  it 'returns a list of backups for a droplet' do
154
164
  stub_do_api('/v2/droplets/1066/backups', :get).to_return(body: api_fixture('droplets/list_backups'))
155
- backups = resource.backups(id: 1066)
165
+ backups = resource.backups(id: 1066).take(20)
156
166
 
157
167
  expect(backups).to all(be_kind_of(DropletKit::Backup))
158
168
  expect(backups[0].id).to eq(449676388)
@@ -168,7 +178,7 @@ RSpec.describe DropletKit::DropletResource do
168
178
  describe '#actions' do
169
179
  it 'returns a list of actions for the droplet' do
170
180
  stub_do_api('/v2/droplets/1066/actions', :get).to_return(body: api_fixture('droplets/list_actions'))
171
- actions = resource.actions(id: 1066)
181
+ actions = resource.actions(id: 1066).take(20)
172
182
 
173
183
  expect(actions).to all(be_kind_of(DropletKit::Action))
174
184
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::ImageActionResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#transfer' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::ImageResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#all' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::RegionResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#all' do
@@ -13,4 +13,4 @@ RSpec.describe DropletKit::RegionResource do
13
13
  expect(resource.all).to eq(expected)
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::SizeResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#all' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DropletKit::SSHKeyResource do
4
- subject(:resource) { described_class.new(connection) }
4
+ subject(:resource) { described_class.new(connection: connection) }
5
5
  include_context 'resources'
6
6
 
7
7
  describe '#all' do
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.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Ross
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.5
33
+ version: 0.1.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.5
40
+ version: 0.1.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: kartograph
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.5
47
+ version: 0.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.0.5
54
+ version: 0.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +159,8 @@ extra_rdoc_files: []
159
159
  files:
160
160
  - ".gitignore"
161
161
  - ".rspec"
162
+ - ".travis.yml"
163
+ - CHANGELOG.md
162
164
  - Gemfile
163
165
  - LICENSE.txt
164
166
  - README.md
@@ -166,6 +168,7 @@ files:
166
168
  - droplet_kit.gemspec
167
169
  - lib/droplet_kit.rb
168
170
  - lib/droplet_kit/client.rb
171
+ - lib/droplet_kit/mappings/account_mapping.rb
169
172
  - lib/droplet_kit/mappings/action_mapping.rb
170
173
  - lib/droplet_kit/mappings/backup_mapping.rb
171
174
  - lib/droplet_kit/mappings/domain_mapping.rb
@@ -181,6 +184,7 @@ files:
181
184
  - lib/droplet_kit/mappings/size_mapping.rb
182
185
  - lib/droplet_kit/mappings/snapshot_mapping.rb
183
186
  - lib/droplet_kit/mappings/ssh_key_mapping.rb
187
+ - lib/droplet_kit/models/account.rb
184
188
  - lib/droplet_kit/models/action.rb
185
189
  - lib/droplet_kit/models/backup.rb
186
190
  - lib/droplet_kit/models/base_model.rb
@@ -199,6 +203,7 @@ files:
199
203
  - lib/droplet_kit/models/snapshot.rb
200
204
  - lib/droplet_kit/models/ssh_key.rb
201
205
  - lib/droplet_kit/paginated_resource.rb
206
+ - lib/droplet_kit/resources/account_resource.rb
202
207
  - lib/droplet_kit/resources/action_resource.rb
203
208
  - lib/droplet_kit/resources/domain_record_resource.rb
204
209
  - lib/droplet_kit/resources/domain_resource.rb
@@ -211,6 +216,7 @@ files:
211
216
  - lib/droplet_kit/resources/ssh_key_resource.rb
212
217
  - lib/droplet_kit/version.rb
213
218
  - lib/tasks/resource_doc.rake
219
+ - spec/fixtures/account/info.json
214
220
  - spec/fixtures/actions/all.json
215
221
  - spec/fixtures/actions/find.json
216
222
  - spec/fixtures/domain_records/all.json
@@ -239,6 +245,7 @@ files:
239
245
  - spec/fixtures/ssh_keys/update.json
240
246
  - spec/lib/droplet_kit/client_spec.rb
241
247
  - spec/lib/droplet_kit/paginated_resource_spec.rb
248
+ - spec/lib/droplet_kit/resources/account_resource_spec.rb
242
249
  - spec/lib/droplet_kit/resources/action_resource_spec.rb
243
250
  - spec/lib/droplet_kit/resources/domain_record_resource_spec.rb
244
251
  - spec/lib/droplet_kit/resources/domain_resource_spec.rb
@@ -266,7 +273,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
273
  requirements:
267
274
  - - ">="
268
275
  - !ruby/object:Gem::Version
269
- version: '0'
276
+ version: 2.0.0
270
277
  required_rubygems_version: !ruby/object:Gem::Requirement
271
278
  requirements:
272
279
  - - ">="
@@ -279,6 +286,7 @@ signing_key:
279
286
  specification_version: 4
280
287
  summary: Droplet Kit is the official Ruby library for Digital Ocean's API
281
288
  test_files:
289
+ - spec/fixtures/account/info.json
282
290
  - spec/fixtures/actions/all.json
283
291
  - spec/fixtures/actions/find.json
284
292
  - spec/fixtures/domain_records/all.json
@@ -307,6 +315,7 @@ test_files:
307
315
  - spec/fixtures/ssh_keys/update.json
308
316
  - spec/lib/droplet_kit/client_spec.rb
309
317
  - spec/lib/droplet_kit/paginated_resource_spec.rb
318
+ - spec/lib/droplet_kit/resources/account_resource_spec.rb
310
319
  - spec/lib/droplet_kit/resources/action_resource_spec.rb
311
320
  - spec/lib/droplet_kit/resources/domain_record_resource_spec.rb
312
321
  - spec/lib/droplet_kit/resources/domain_resource_spec.rb