droplet_kit 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +7 -0
  4. data/README.md +46 -12
  5. data/droplet_kit.gemspec +2 -1
  6. data/lib/droplet_kit.rb +12 -0
  7. data/lib/droplet_kit/client.rb +2 -0
  8. data/lib/droplet_kit/mappings/certificate_mapping.rb +25 -0
  9. data/lib/droplet_kit/mappings/droplet_mapping.rb +1 -0
  10. data/lib/droplet_kit/mappings/forwarding_rule_mapping.rb +19 -0
  11. data/lib/droplet_kit/mappings/health_check_mapping.rb +19 -0
  12. data/lib/droplet_kit/mappings/image_mapping.rb +5 -1
  13. data/lib/droplet_kit/mappings/load_balancer_mapping.rb +33 -0
  14. data/lib/droplet_kit/mappings/sticky_session_mapping.rb +15 -0
  15. data/lib/droplet_kit/models/certificate.rb +12 -0
  16. data/lib/droplet_kit/models/droplet.rb +1 -0
  17. data/lib/droplet_kit/models/forwarding_rule.rb +10 -0
  18. data/lib/droplet_kit/models/health_check.rb +11 -0
  19. data/lib/droplet_kit/models/image.rb +42 -0
  20. data/lib/droplet_kit/models/load_balancer.rb +17 -0
  21. data/lib/droplet_kit/models/sticky_session.rb +7 -0
  22. data/lib/droplet_kit/resources/certificate_resource.rb +30 -0
  23. data/lib/droplet_kit/resources/droplet_action_resource.rb +2 -2
  24. data/lib/droplet_kit/resources/load_balancer_resource.rb +56 -0
  25. data/lib/droplet_kit/version.rb +1 -1
  26. data/spec/fixtures/certificates/all.json +16 -0
  27. data/spec/fixtures/certificates/find.json +9 -0
  28. data/spec/fixtures/images/find.json +4 -2
  29. data/spec/fixtures/load_balancers/all.json +129 -0
  30. data/spec/fixtures/load_balancers/find.json +59 -0
  31. data/spec/lib/droplet_kit/resources/certificate_resource_spec.rb +90 -0
  32. data/spec/lib/droplet_kit/resources/droplet_action_resource_spec.rb +4 -4
  33. data/spec/lib/droplet_kit/resources/droplet_resource_spec.rb +2 -0
  34. data/spec/lib/droplet_kit/resources/image_resource_spec.rb +5 -1
  35. data/spec/lib/droplet_kit/resources/load_balancer_resource_spec.rb +213 -0
  36. data/spec/spec_helper.rb +1 -3
  37. metadata +41 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62abc974f3667b61cb9e9586ea73f408d8921674
4
- data.tar.gz: 49265e741c8b097ec93dd0f498e7fd268d12adbf
3
+ metadata.gz: 025077918c4a61f739d58486166607209439b129
4
+ data.tar.gz: c66125a6ac2909c842b79242e3c818c0e5228287
5
5
  SHA512:
6
- metadata.gz: 47de64509760e6cbf3f78ded12d503d8cb2636182535d8fbf77bbcc4fd0b9a3a01ca4355b944aaee20e97d63bdca29bffd4fc67e3dc370f8e7f36ab5344e477d
7
- data.tar.gz: f3c3461af6d3750234302eba87d47c6b470cd46c17a6b15cdb86038defef9234ac50d1945b723f0e4667da231153fc8f73ac49b5cd70ee96a9421890067c3f64
6
+ metadata.gz: 6198f8fc7be8f537cbbbd8996253c877748428ada7078c680f4f95598d3e2d7dbcd8aebb99da5623927c7d8dbaec30ff2dc6f6a2eb7c814c2bd2d6a2029c4e57
7
+ data.tar.gz: f84a6955aae3e753dcba901b31527bde4048e887779be627b77a68b6a0e3b49801e71b4b3624d3d7043c4c59640af27cae4cf512d2a516ff5a7c38025ae736c8
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ vendor
@@ -1,3 +1,10 @@
1
+ ### Version 2.1.0
2
+ * Added monitoring to the Droplet resource.
3
+ * Added LoadBalancer resource.
4
+ * Added Certificate resource.
5
+ * Added min_disk_size, size_gigabytes and created_at to the Image resource.
6
+ * Updated DropletActionResource to use tag_name instead of tag.
7
+
1
8
  ### Version 2.0.1
2
9
  * Droplet create action now accepts `tags` attribute.
3
10
 
data/README.md CHANGED
@@ -30,7 +30,7 @@ client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
30
30
 
31
31
  ## Design
32
32
 
33
- DropletKit follows a strict design of resoures as methods on your client. For examples, for droplets, you will call your client like this:
33
+ DropletKit follows a strict design of resources as methods on your client. For examples, for droplets, you will call your client like this:
34
34
 
35
35
  ```ruby
36
36
  client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
@@ -45,7 +45,7 @@ client.droplets.all
45
45
  # => [ DropletKit::Droplet(id: 123, name: 'something.com', ...), DropletKit::Droplet(id: 1066, name: 'bunk.com', ...) ]
46
46
  ```
47
47
 
48
- When you'd like to save objects, it's your responsibility to instantiate the objects and persist them using the resource objects. Lets use creating a Droplet as an example:
48
+ When you'd like to save objects, it's your responsibility to instantiate the objects and persist them using the resource objects. Let's use creating a Droplet as an example:
49
49
 
50
50
  ```ruby
51
51
  client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
@@ -64,6 +64,21 @@ droplet = client.droplets.find(id: 123)
64
64
 
65
65
  # All Resources and actions.
66
66
 
67
+ ## Certificate resource
68
+
69
+ ```ruby
70
+ client = DropletKit::Client.new(access_token: 'TOKEN')
71
+ client.certificates #=> DropletKit::CertificateResource
72
+ ```
73
+
74
+ Actions supported:
75
+
76
+ * `client.certificates.find(id: 'id')`
77
+ * `client.certificates.all()`
78
+ * `client.certificates.create(certificate)`
79
+ * `client.certificates.delete(id: 'id')`
80
+
81
+
67
82
  ## Droplet resource
68
83
 
69
84
  ```ruby
@@ -96,25 +111,25 @@ Actions supported:
96
111
 
97
112
  * `client.droplet_actions.reboot(droplet_id: droplet.id)`
98
113
  * `client.droplet_actions.power_cycle(droplet_id: droplet.id)`
99
- * `client.droplet_actions.power_cycle_for_tag(tag: 'tag_name')`
114
+ * `client.droplet_actions.power_cycle_for_tag(tag_name: 'tag_name')`
100
115
  * `client.droplet_actions.shutdown(droplet_id: droplet.id)`
101
- * `client.droplet_actions.shutdown_for_tag(tag: 'tag_name')`
116
+ * `client.droplet_actions.shutdown_for_tag(tag_name: 'tag_name')`
102
117
  * `client.droplet_actions.power_off(droplet_id: droplet.id)`
103
- * `client.droplet_actions.power_off_for_tag(tag: 'tag_name')`
118
+ * `client.droplet_actions.power_off_for_tag(tag_name: 'tag_name')`
104
119
  * `client.droplet_actions.power_on(droplet_id: droplet.id)`
105
- * `client.droplet_actions.power_on_for_tag(tag: 'tag_name')`
120
+ * `client.droplet_actions.power_on_for_tag(tag_name: 'tag_name')`
106
121
  * `client.droplet_actions.password_reset(droplet_id: droplet.id)`
107
122
  * `client.droplet_actions.enable_ipv6(droplet_id: droplet.id)`
108
- * `client.droplet_actions.enable_ipv6_for_tag(tag: 'tag_name')`
123
+ * `client.droplet_actions.enable_ipv6_for_tag(tag_name: 'tag_name')`
109
124
  * `client.droplet_actions.enable_backups(droplet_id: droplet.id)`
110
- * `client.droplet_actions.enable_backups_for_tag(tag: 'tag_name')`
125
+ * `client.droplet_actions.enable_backups_for_tag(tag_name: 'tag_name')`
111
126
  * `client.droplet_actions.disable_backups(droplet_id: droplet.id)`
112
- * `client.droplet_actions.disable_backups_for_tag(tag: 'tag_name')`
127
+ * `client.droplet_actions.disable_backups_for_tag(tag_name: 'tag_name')`
113
128
  * `client.droplet_actions.upgrade(droplet_id: droplet.id)`
114
129
  * `client.droplet_actions.enable_private_networking(droplet_id: droplet.id)`
115
- * `client.droplet_actions.enable_private_networking_for_tag(tag: 'tag_name')`
130
+ * `client.droplet_actions.enable_private_networking_for_tag(tag_name: 'tag_name')`
116
131
  * `client.droplet_actions.snapshot(droplet_id: droplet.id, name: 'Snapshot Name')`
117
- * `client.droplet_actions.snapshot_for_tag(tag: 'tag_name', name: 'Snapshot Name')`
132
+ * `client.droplet_actions.snapshot_for_tag(tag_name: 'tag_name', name: 'Snapshot Name')`
118
133
  * `client.droplet_actions.change_kernel(droplet_id: droplet.id, kernel: 'kernel_id')`
119
134
  * `client.droplet_actions.rename(droplet_id: droplet.id, name: 'New-Droplet-Name')`
120
135
  * `client.droplet_actions.rebuild(droplet_id: droplet.id, image: 'image_id')`
@@ -122,7 +137,7 @@ Actions supported:
122
137
  * `client.droplet_actions.resize(droplet_id: droplet.id, size: '1gb')`
123
138
  * `client.droplet_actions.find(droplet_id: droplet.id, id: action.id)`
124
139
  * `client.droplet_actions.action_for_id(droplet_id: droplet.id, type: 'event_name', param: 'value')`
125
- * `client.droplet_actions.action_for_tag(tag: 'tag_name', type: 'event_name', param: 'value')`
140
+ * `client.droplet_actions.action_for_tag(tag_name: 'tag_name', type: 'event_name', param: 'value')`
126
141
 
127
142
  ## Domain resource
128
143
 
@@ -189,6 +204,25 @@ Image Actions Supported:
189
204
  * `client.image_actions.transfer(image_id: 123, region: 'nyc3')`
190
205
 
191
206
 
207
+ ## Load balancer resource
208
+ ```ruby
209
+ client = DropletKit::Client.new(access_token: 'TOKEN')
210
+ client.load_balancers #=> DropletKit::LoadBalancerResource
211
+ ```
212
+
213
+ Actions supported:
214
+
215
+ * `client.load_balancers.find(id: 'id')`
216
+ * `client.load_balancers.all()`
217
+ * `client.load_balancers.create(load_balancer)`
218
+ * `client.load_balancers.update(load_balancer, id: 'id')`
219
+ * `client.load_balancers.delete(id: 'id')`
220
+ * `client.load_balancers.add_droplets([droplet.id], id: 'id')`
221
+ * `client.load_balancers.remove_droplets([droplet.id], id: 'id')`
222
+ * `client.load_balancers.add_forwarding_rules([forwarding_rule], id: 'id')`
223
+ * `client.load_balancers.remove_forwarding_rules([forwarding_rule], id: 'id')`
224
+
225
+
192
226
  ## Region resource
193
227
 
194
228
  ```ruby
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["rross@digitalocean.com"]
11
11
  spec.summary = %q{Droplet Kit is the official Ruby library for DigitalOcean's API}
12
12
  spec.description = %q{Droplet Kit is the official Ruby library for DigitalOcean's API}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/digitalocean/droplet_kit"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rake"
31
31
  spec.add_development_dependency "rspec", "~> 3.0.0"
32
32
  spec.add_development_dependency "pry"
33
+ spec.add_development_dependency "rb-readline"
33
34
 
34
35
  # FakeServe
35
36
  spec.add_development_dependency 'sinatra', '~> 1.4'
@@ -28,6 +28,11 @@ module DropletKit
28
28
  autoload :TaggedResources, 'droplet_kit/models/tagged_resources'
29
29
  autoload :TaggedDropletsResources, 'droplet_kit/models/tagged_droplets_resources'
30
30
  autoload :Volume, 'droplet_kit/models/volume'
31
+ autoload :LoadBalancer, 'droplet_kit/models/load_balancer'
32
+ autoload :StickySession, 'droplet_kit/models/sticky_session'
33
+ autoload :HealthCheck, 'droplet_kit/models/health_check'
34
+ autoload :ForwardingRule, 'droplet_kit/models/forwarding_rule'
35
+ autoload :Certificate, 'droplet_kit/models/certificate'
31
36
 
32
37
  # Resources
33
38
  autoload :DropletResource, 'droplet_kit/resources/droplet_resource'
@@ -48,6 +53,8 @@ module DropletKit
48
53
  autoload :VolumeResource, 'droplet_kit/resources/volume_resource'
49
54
  autoload :VolumeActionResource, 'droplet_kit/resources/volume_action_resource'
50
55
  autoload :SnapshotResource, 'droplet_kit/resources/snapshot_resource'
56
+ autoload :LoadBalancerResource, 'droplet_kit/resources/load_balancer_resource'
57
+ autoload :CertificateResource, 'droplet_kit/resources/certificate_resource'
51
58
 
52
59
  # JSON Maps
53
60
  autoload :DropletMapping, 'droplet_kit/mappings/droplet_mapping'
@@ -71,6 +78,11 @@ module DropletKit
71
78
  autoload :TaggedResourcesMapping, 'droplet_kit/mappings/tagged_resources_mapping'
72
79
  autoload :TaggedDropletsResourcesMapping, 'droplet_kit/mappings/tagged_droplets_resources_mapping'
73
80
  autoload :VolumeMapping, 'droplet_kit/mappings/volume_mapping'
81
+ autoload :LoadBalancerMapping, 'droplet_kit/mappings/load_balancer_mapping'
82
+ autoload :StickySessionMapping, 'droplet_kit/mappings/sticky_session_mapping'
83
+ autoload :HealthCheckMapping, 'droplet_kit/mappings/health_check_mapping'
84
+ autoload :ForwardingRuleMapping, 'droplet_kit/mappings/forwarding_rule_mapping'
85
+ autoload :CertificateMapping, 'droplet_kit/mappings/certificate_mapping'
74
86
 
75
87
  # Utils
76
88
  autoload :PaginatedResource, 'droplet_kit/paginated_resource'
@@ -19,12 +19,14 @@ module DropletKit
19
19
  def self.resources
20
20
  {
21
21
  actions: ActionResource,
22
+ certificates: CertificateResource,
22
23
  droplets: DropletResource,
23
24
  domains: DomainResource,
24
25
  domain_records: DomainRecordResource,
25
26
  droplet_actions: DropletActionResource,
26
27
  images: ImageResource,
27
28
  image_actions: ImageActionResource,
29
+ load_balancers: LoadBalancerResource,
28
30
  regions: RegionResource,
29
31
  sizes: SizeResource,
30
32
  ssh_keys: SSHKeyResource,
@@ -0,0 +1,25 @@
1
+ module DropletKit
2
+ class CertificateMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping Certificate
7
+ root_key singular: 'certificate', plural: 'certificates', scopes: [:read]
8
+
9
+ scoped :read do
10
+ property :id
11
+ property :name
12
+ property :not_after
13
+ property :sha1_fingerprint
14
+ property :created_at
15
+ end
16
+
17
+ scoped :create do
18
+ property :name
19
+ property :private_key
20
+ property :leaf_certificate
21
+ property :certificate_chain
22
+ end
23
+ end
24
+ end
25
+ end
@@ -35,6 +35,7 @@ module DropletKit
35
35
  property :image, scopes: [:create]
36
36
  property :ssh_keys, scopes: [:create]
37
37
  property :backups, scopes: [:create]
38
+ property :monitoring, scopes: [:create]
38
39
  property :ipv6, scopes: [:create]
39
40
  property :user_data, scopes: [:create]
40
41
  property :private_networking, scopes: [:create]
@@ -0,0 +1,19 @@
1
+ module DropletKit
2
+ class ForwardingRuleMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ root_key plural: 'forwarding_rules', scopes: [:create, :update]
7
+ mapping ForwardingRule
8
+
9
+ scoped :read, :create, :update do
10
+ property :entry_protocol
11
+ property :entry_port
12
+ property :target_protocol
13
+ property :target_port
14
+ property :certificate_id
15
+ property :tls_passthrough
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module DropletKit
2
+ class HealthCheckMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping HealthCheck
7
+
8
+ scoped :read, :create, :update do
9
+ property :protocol
10
+ property :port
11
+ property :path
12
+ property :check_interval_seconds
13
+ property :response_timeout_seconds
14
+ property :healthy_threshold
15
+ property :unhealthy_threshold
16
+ end
17
+ end
18
+ end
19
+ end
@@ -15,6 +15,10 @@ module DropletKit
15
15
  property :public, scopes: [:read, :read_snapshot, :read_backup]
16
16
  property :regions, scopes: [:read, :read_snapshot, :read_backup]
17
17
  property :type, scopes: [:read, :read_snapshot, :read_backup]
18
+
19
+ property :min_disk_size, scopes: [:read, :read_snapshot, :read_backup]
20
+ property :created_at, scopes: [:read, :read_snapshot, :read_backup]
21
+ property :size_gigabytes, scopes: [:read, :read_snapshot, :read_backup]
18
22
  end
19
23
  end
20
- end
24
+ end
@@ -0,0 +1,33 @@
1
+ module DropletKit
2
+ class LoadBalancerMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping LoadBalancer
7
+ root_key singular: 'load_balancer', plural: 'load_balancers', scopes: [:read]
8
+
9
+ scoped :read do
10
+ property :id
11
+ property :ip
12
+ property :status
13
+ property :created_at
14
+ property :region, include: RegionMapping
15
+ end
16
+
17
+ scoped :read, :update, :create do
18
+ property :name
19
+ property :algorithm
20
+ property :tag
21
+ property :redirect_http_to_https
22
+ property :droplet_ids
23
+ property :sticky_sessions, include: StickySessionMapping
24
+ property :health_check, include: HealthCheckMapping
25
+ property :forwarding_rules, plural: true, include: ForwardingRuleMapping
26
+ end
27
+
28
+ scoped :update, :create do
29
+ property :region
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module DropletKit
2
+ class StickySessionMapping
3
+ include Kartograph::DSL
4
+
5
+ kartograph do
6
+ mapping StickySession
7
+
8
+ scoped :read, :create, :update do
9
+ property :type
10
+ property :cookie_name
11
+ property :cookie_ttl_seconds
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module DropletKit
2
+ class Certificate < BaseModel
3
+ attribute :id
4
+ attribute :name
5
+ attribute :not_after
6
+ attribute :sha1_fingerprint
7
+ attribute :created_at
8
+ attribute :private_key
9
+ attribute :leaf_certificate
10
+ attribute :certificate_chain
11
+ end
12
+ end
@@ -11,6 +11,7 @@ module DropletKit
11
11
  attribute :volumes
12
12
  attribute :ssh_keys
13
13
  attribute :backups
14
+ attribute :monitoring
14
15
  attribute :size
15
16
  attribute :ipv6
16
17
  attribute :user_data
@@ -0,0 +1,10 @@
1
+ module DropletKit
2
+ class ForwardingRule < BaseModel
3
+ attribute :entry_protocol
4
+ attribute :entry_port
5
+ attribute :target_protocol
6
+ attribute :target_port
7
+ attribute :certificate_id
8
+ attribute :tls_passthrough
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module DropletKit
2
+ class HealthCheck < BaseModel
3
+ attribute :protocol
4
+ attribute :port
5
+ attribute :path
6
+ attribute :check_interval_seconds
7
+ attribute :response_timeout_seconds
8
+ attribute :healthy_threshold
9
+ attribute :unhealthy_threshold
10
+ end
11
+ end
@@ -1,11 +1,53 @@
1
1
  module DropletKit
2
2
  class Image < BaseModel
3
+ # @!attribute id
4
+ # @example 12345
5
+ # @return [Fixnum] A unique number that can be used to identify and reference a specific image.
3
6
  attribute :id
7
+
8
+ # @!attribute name
9
+ # @example 'foo'
10
+ # @return [String] The display name that has been given to an image. This is what is shown in the control panel and is generally a descriptive title for the image in question.
4
11
  attribute :name
12
+
13
+ # @!attribute distribution
14
+ # @example 'Ubuntu'
15
+ # @return [String] This attribute describes the base distribution used for this image.
5
16
  attribute :distribution
17
+
18
+ # @!attribute slug
19
+ # @example 'ubuntu-16-04-x64'
20
+ # @return [String] A uniquely identifying string that is associated with each of the DigitalOcean-provided public images. These can be used to reference a public image as an alternative to the numeric id.
6
21
  attribute :slug
22
+
23
+ # @!attribute public
24
+ # @example false
25
+ # @return [Boolean] This is a boolean value that indicates whether the image in question is public or not. An image that is public is available to all accounts. A non-public image is only accessible from your account.
7
26
  attribute :public
27
+
28
+ # @!attribute regions
29
+ # @example [ "nyc2", "nyc2" ]
30
+ # @return [Array<String>] This attribute is an array of the regions that the image is available in. The regions are represented by their identifying slug values.
8
31
  attribute :regions
32
+
33
+ # @!attribute type
34
+ # @example 'snapshot'
35
+ # @return [String] The kind of image, describing the duration of how long the image is stored. This is either "snapshot" or "backup".
9
36
  attribute :type
37
+
38
+ # @!attribute min_disk_size
39
+ # @example 'snapshot'
40
+ # @return [Fixnum] The minimum 'disk' required for a size to use this image.
41
+ attribute :min_disk_size
42
+
43
+ # @!attribute size_gigabytes
44
+ # @example 2.34
45
+ # @return [Fixnum] The size of the image in gigabytes.
46
+ attribute :size_gigabytes
47
+
48
+ # @!attribute created_at
49
+ # @example '2014-11-04T22:23:02Z'
50
+ # @return [String] A time value given in ISO8601 combined date and time format that represents when the Image was created.
51
+ attribute :created_at
10
52
  end
11
53
  end
@@ -0,0 +1,17 @@
1
+ module DropletKit
2
+ class LoadBalancer < BaseModel
3
+ attribute :id
4
+ attribute :ip
5
+ attribute :name
6
+ attribute :algorithm
7
+ attribute :status
8
+ attribute :created_at
9
+ attribute :tag
10
+ attribute :region
11
+ attribute :redirect_http_to_https
12
+ attribute :droplet_ids
13
+ attribute :sticky_sessions
14
+ attribute :health_check
15
+ attribute :forwarding_rules
16
+ end
17
+ end