droplet_kit 3.16.1 → 3.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -10
  3. data/lib/droplet_kit/client.rb +3 -1
  4. data/lib/droplet_kit/error_handling_resourcable.rb +4 -3
  5. data/lib/droplet_kit/mappings/balance_mapping.rb +0 -1
  6. data/lib/droplet_kit/mappings/container_registry_mapping.rb +1 -1
  7. data/lib/droplet_kit/mappings/database_cluster_mapping.rb +8 -8
  8. data/lib/droplet_kit/mappings/database_connection_pool_mapping.rb +5 -5
  9. data/lib/droplet_kit/mappings/database_eviction_policy_mapping.rb +1 -1
  10. data/lib/droplet_kit/mappings/database_firewall_rule_mapping.rb +3 -3
  11. data/lib/droplet_kit/mappings/database_maintenance_window_mapping.rb +2 -2
  12. data/lib/droplet_kit/mappings/database_mapping.rb +1 -1
  13. data/lib/droplet_kit/mappings/database_sql_mode_mapping.rb +1 -1
  14. data/lib/droplet_kit/mappings/database_user_mapping.rb +3 -3
  15. data/lib/droplet_kit/mappings/database_user_reset_auth_mapping.rb +1 -1
  16. data/lib/droplet_kit/mappings/domain_mapping.rb +2 -2
  17. data/lib/droplet_kit/mappings/domain_record_mapping.rb +9 -9
  18. data/lib/droplet_kit/mappings/droplet_upgrade_mapping.rb +1 -1
  19. data/lib/droplet_kit/mappings/error_mapping.rb +1 -1
  20. data/lib/droplet_kit/mappings/firewall_inbound_rule_mapping.rb +1 -1
  21. data/lib/droplet_kit/mappings/firewall_outbound_rule_mapping.rb +1 -1
  22. data/lib/droplet_kit/mappings/floating_ip_mapping.rb +1 -1
  23. data/lib/droplet_kit/mappings/forwarding_rule_mapping.rb +1 -1
  24. data/lib/droplet_kit/mappings/image_mapping.rb +10 -10
  25. data/lib/droplet_kit/mappings/invoice_mapping.rb +0 -1
  26. data/lib/droplet_kit/mappings/kernel_mapping.rb +1 -1
  27. data/lib/droplet_kit/mappings/kubernetes_cluster_mapping.rb +9 -9
  28. data/lib/droplet_kit/mappings/kubernetes_node_mapping.rb +0 -1
  29. data/lib/droplet_kit/mappings/kubernetes_node_pool_mapping.rb +8 -9
  30. data/lib/droplet_kit/mappings/load_balancer_mapping.rb +1 -1
  31. data/lib/droplet_kit/mappings/network_detail_mapping.rb +1 -1
  32. data/lib/droplet_kit/mappings/network_mapping.rb +1 -1
  33. data/lib/droplet_kit/mappings/project_assignment_mapping.rb +1 -1
  34. data/lib/droplet_kit/mappings/project_mapping.rb +5 -5
  35. data/lib/droplet_kit/mappings/region_mapping.rb +1 -1
  36. data/lib/droplet_kit/mappings/reserved_ip_mapping.rb +21 -0
  37. data/lib/droplet_kit/mappings/size_mapping.rb +1 -0
  38. data/lib/droplet_kit/mappings/snapshot_mapping.rb +1 -1
  39. data/lib/droplet_kit/mappings/ssh_key_mapping.rb +1 -1
  40. data/lib/droplet_kit/mappings/volume_mapping.rb +5 -6
  41. data/lib/droplet_kit/mappings/vpc_member_mapping.rb +1 -1
  42. data/lib/droplet_kit/models/base_model.rb +3 -3
  43. data/lib/droplet_kit/models/container_registry_repository.rb +1 -1
  44. data/lib/droplet_kit/models/container_registry_repository_tag.rb +1 -1
  45. data/lib/droplet_kit/models/domain.rb +1 -1
  46. data/lib/droplet_kit/models/droplet.rb +6 -7
  47. data/lib/droplet_kit/models/invoice.rb +15 -16
  48. data/lib/droplet_kit/models/kernel.rb +1 -1
  49. data/lib/droplet_kit/models/kubernetes_cluster.rb +1 -1
  50. data/lib/droplet_kit/models/kubernetes_node.rb +1 -1
  51. data/lib/droplet_kit/models/kubernetes_node_pool.rb +1 -1
  52. data/lib/droplet_kit/models/load_balancer.rb +4 -4
  53. data/lib/droplet_kit/models/meta_information.rb +1 -1
  54. data/lib/droplet_kit/models/pagination_information.rb +1 -1
  55. data/lib/droplet_kit/models/project.rb +1 -1
  56. data/lib/droplet_kit/models/reserved_ip.rb +20 -0
  57. data/lib/droplet_kit/models/size.rb +1 -0
  58. data/lib/droplet_kit/models/snapshot.rb +1 -1
  59. data/lib/droplet_kit/models/ssh_key.rb +1 -1
  60. data/lib/droplet_kit/models/volume.rb +1 -1
  61. data/lib/droplet_kit/models/vpc.rb +1 -1
  62. data/lib/droplet_kit/models/vpc_member.rb +1 -1
  63. data/lib/droplet_kit/paginated_resource.rb +10 -10
  64. data/lib/droplet_kit/resources/account_resource.rb +1 -1
  65. data/lib/droplet_kit/resources/balance_resource.rb +1 -1
  66. data/lib/droplet_kit/resources/domain_record_resource.rb +2 -2
  67. data/lib/droplet_kit/resources/droplet_action_resource.rb +5 -5
  68. data/lib/droplet_kit/resources/firewall_resource.rb +3 -3
  69. data/lib/droplet_kit/resources/image_resource.rb +1 -1
  70. data/lib/droplet_kit/resources/kubernetes_cluster_resource.rb +3 -5
  71. data/lib/droplet_kit/resources/load_balancer_resource.rb +1 -1
  72. data/lib/droplet_kit/resources/project_resource.rb +1 -1
  73. data/lib/droplet_kit/resources/reserved_ip_action_resource.rb +32 -0
  74. data/lib/droplet_kit/resources/reserved_ip_resource.rb +31 -0
  75. data/lib/droplet_kit/resources/ssh_key_resource.rb +3 -3
  76. data/lib/droplet_kit/resources/volume_action_resource.rb +3 -3
  77. data/lib/droplet_kit/resources/vpc_resource.rb +5 -5
  78. data/lib/droplet_kit/utils.rb +9 -9
  79. data/lib/droplet_kit/version.rb +1 -1
  80. data/lib/droplet_kit.rb +6 -2
  81. data/lib/tasks/resource_doc.rake +8 -9
  82. metadata +99 -19
@@ -17,4 +17,4 @@ module DropletKit
17
17
  new(name: identifier)
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module DropletKit
4
4
  class Droplet < BaseModel
5
- [:id, :name, :memory, :vcpus, :disk, :locked, :created_at,
6
- :status, :backup_ids, :snapshot_ids, :action_ids, :features,
7
- :region, :image, :networks, :kernel, :size_slug, :tags,
8
- :volume_ids].each do |key|
5
+ %i[id name memory vcpus disk locked created_at
6
+ status backup_ids snapshot_ids action_ids features
7
+ region image networks kernel size_slug tags
8
+ volume_ids].each do |key|
9
9
  attribute(key)
10
10
  end
11
11
 
@@ -24,12 +24,12 @@ module DropletKit
24
24
 
25
25
  def public_ip
26
26
  network = network_for(:v4, 'public')
27
- network && network.ip_address
27
+ network&.ip_address
28
28
  end
29
29
 
30
30
  def private_ip
31
31
  network = network_for(:v4, 'private')
32
- network && network.ip_address
32
+ network&.ip_address
33
33
  end
34
34
 
35
35
  private
@@ -46,4 +46,3 @@ module DropletKit
46
46
  end
47
47
  end
48
48
  end
49
-
@@ -1,20 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DropletKit
4
- class Invoice < BaseModel
5
- attribute :invoice_uuid
6
- attribute :amount
7
- attribute :invoice_period
8
- attribute :product
9
- attribute :resource_uuid
10
- attribute :group_description
11
- attribute :description
12
- attribute :duration
13
- attribute :duration_unit
14
- attribute :start_time
15
- attribute :end_time
16
- attribute :project_name
17
- attribute :category
18
- end
4
+ class Invoice < BaseModel
5
+ attribute :invoice_uuid
6
+ attribute :amount
7
+ attribute :invoice_period
8
+ attribute :product
9
+ attribute :resource_uuid
10
+ attribute :group_description
11
+ attribute :description
12
+ attribute :duration
13
+ attribute :duration_unit
14
+ attribute :start_time
15
+ attribute :end_time
16
+ attribute :project_name
17
+ attribute :category
19
18
  end
20
-
19
+ end
@@ -6,4 +6,4 @@ module DropletKit
6
6
  attribute :name
7
7
  attribute :version
8
8
  end
9
- end
9
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DropletKit
4
4
  class KubernetesCluster < BaseModel
5
- [:id, :name, :region, :version, :auto_upgrade, :cluster_subnet, :service_subnet, :ipv4, :endpoint, :tags, :maintenance_policy, :node_pools, :vpc_uuid, :ha].each do |key|
5
+ %i[id name region version auto_upgrade cluster_subnet service_subnet ipv4 endpoint tags maintenance_policy node_pools vpc_uuid ha].each do |key|
6
6
  attribute(key)
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DropletKit
4
4
  class KubernetesNode < BaseModel
5
- [:id, :name, :status, :created_at, :updated_at].each do |key|
5
+ %i[id name status created_at updated_at].each do |key|
6
6
  attribute(key)
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DropletKit
4
4
  class KubernetesNodePool < BaseModel
5
- [:id, :name, :size, :count, :tags, :labels, :nodes, :auto_scale, :min_nodes, :max_nodes].each do |key|
5
+ %i[id name size count tags labels nodes auto_scale min_nodes max_nodes].each do |key|
6
6
  attribute(key)
7
7
  end
8
8
  end
@@ -12,10 +12,10 @@ module DropletKit
12
12
  attribute :region
13
13
  attribute :size
14
14
  attribute :size_unit
15
- attribute :redirect_http_to_https, Boolean, :default => false
16
- attribute :enable_proxy_protocol, Boolean, :default => false
17
- attribute :enable_backend_keepalive, Boolean, :default => false
18
- attribute :disable_lets_encrypt_dns_records, Boolean, :default => false
15
+ attribute :redirect_http_to_https, Boolean, default: false
16
+ attribute :enable_proxy_protocol, Boolean, default: false
17
+ attribute :enable_backend_keepalive, Boolean, default: false
18
+ attribute :disable_lets_encrypt_dns_records, Boolean, default: false
19
19
  attribute :droplet_ids
20
20
  attribute :sticky_sessions, StickySession
21
21
  attribute :health_check
@@ -13,4 +13,4 @@ module DropletKit
13
13
 
14
14
  attribute :total
15
15
  end
16
- end
16
+ end
@@ -16,4 +16,4 @@ module DropletKit
16
16
  end
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module DropletKit
4
4
  class Project < BaseModel
5
- DEFAULT = 'default'.freeze
5
+ DEFAULT = 'default'
6
6
 
7
7
  attribute :id
8
8
  attribute :owner_uuid
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DropletKit
4
+ class ReservedIp < BaseModel
5
+ attribute :ip
6
+ attribute :region
7
+ attribute :droplet
8
+
9
+ # Used for creates
10
+ attribute :droplet_id
11
+
12
+ def identifier
13
+ ip
14
+ end
15
+
16
+ def self.from_identifier(identifier)
17
+ new(ip: identifier)
18
+ end
19
+ end
20
+ end
@@ -11,6 +11,7 @@ module DropletKit
11
11
  attribute :price_hourly
12
12
  attribute :regions
13
13
  attribute :available
14
+ attribute :description
14
15
  end
15
16
 
16
17
  def self.from_identifier(identifier)
@@ -11,4 +11,4 @@ module DropletKit
11
11
  attribute :min_disk_size
12
12
  attribute :size_gigabytes
13
13
  end
14
- end
14
+ end
@@ -7,4 +7,4 @@ module DropletKit
7
7
  attribute :public_key
8
8
  attribute :name
9
9
  end
10
- end
10
+ end
@@ -15,4 +15,4 @@ module DropletKit
15
15
  # Used for creates
16
16
  attribute :snapshot_id
17
17
  end
18
- end
18
+ end
@@ -11,4 +11,4 @@ module DropletKit
11
11
  attribute :created_at
12
12
  attribute :default
13
13
  end
14
- end
14
+ end
@@ -6,4 +6,4 @@ module DropletKit
6
6
  attribute :name
7
7
  attribute :created_at
8
8
  end
9
- end
9
+ end
@@ -16,7 +16,7 @@ module DropletKit
16
16
  @resource = resource
17
17
  @collection = []
18
18
  @args = args
19
- @options = args.last.kind_of?(Hash) ? args.last : {}
19
+ @options = args.last.is_a?(Hash) ? args.last : {}
20
20
  end
21
21
 
22
22
  def per_page
@@ -31,10 +31,9 @@ module DropletKit
31
31
  # Start off with the first page if we have no idea of anything yet
32
32
  fetch_next_page if total.nil?
33
33
 
34
- return to_enum(:each, start) unless block_given?
35
- Array(@collection[start..-1]).each do |element|
36
- yield(element)
37
- end
34
+ return to_enum(:each, start) unless block
35
+
36
+ Array(@collection[start..-1]).each(&block)
38
37
 
39
38
  unless last?
40
39
  start = [@collection.size, start].max
@@ -46,18 +45,19 @@ module DropletKit
46
45
  end
47
46
 
48
47
  def last?
49
- return true if self.total.nil?
50
- @current_page == total_pages || self.total.zero?
48
+ return true if total.nil?
49
+
50
+ @current_page == total_pages || total.zero?
51
51
  end
52
52
 
53
53
  def total_pages
54
- return nil if self.total.nil?
54
+ return nil if total.nil?
55
55
 
56
- (self.total.to_f / per_page.to_f).ceil
56
+ (total.to_f / per_page).ceil
57
57
  end
58
58
 
59
59
  def ==(other)
60
- each_with_index.each.all? {|object, index| object == other[index] }
60
+ each_with_index.each.all? { |object, index| object == other[index] }
61
61
  end
62
62
 
63
63
  private
@@ -5,7 +5,7 @@ module DropletKit
5
5
  include ErrorHandlingResourcable
6
6
 
7
7
  resources do
8
- default_handler(:ok) {|r| AccountMapping.extract_single(r.body, :read) }
8
+ default_handler(:ok) { |r| AccountMapping.extract_single(r.body, :read) }
9
9
  get '/v2/account' => :info
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module DropletKit
5
5
  include ErrorHandlingResourcable
6
6
 
7
7
  resources do
8
- default_handler(:ok) {|r| BalanceMapping.extract_single(r.body, :read) }
8
+ default_handler(:ok) { |r| BalanceMapping.extract_single(r.body, :read) }
9
9
  get '/v2/customers/my/balance' => :info
10
10
  end
11
11
  end
@@ -11,7 +11,7 @@ module DropletKit
11
11
  end
12
12
 
13
13
  action :create, 'POST /v2/domains/:for_domain/records' do
14
- body {|object| DomainRecordMapping.representation_for(:create, object) }
14
+ body { |object| DomainRecordMapping.representation_for(:create, object) }
15
15
  handler(201) { |response| DomainRecordMapping.extract_single(response.body, :read) }
16
16
  end
17
17
 
@@ -24,7 +24,7 @@ module DropletKit
24
24
  end
25
25
 
26
26
  action :update, 'PUT /v2/domains/:for_domain/records/:id' do
27
- body {|object| DomainRecordMapping.representation_for(:update, object) }
27
+ body { |object| DomainRecordMapping.representation_for(:update, object) }
28
28
  handler(200) { |response| DomainRecordMapping.extract_single(response.body, :read) }
29
29
  end
30
30
  end
@@ -4,14 +4,14 @@ module DropletKit
4
4
  class DropletActionResource < ResourceKit::Resource
5
5
  include ErrorHandlingResourcable
6
6
 
7
- ACTIONS_WITHOUT_INPUT = %w(reboot power_cycle shutdown power_off power_on
8
- password_reset enable_ipv6 enable_backups disable_backups
9
- enable_private_networking)
7
+ ACTIONS_WITHOUT_INPUT = %w[reboot power_cycle shutdown power_off power_on
8
+ password_reset enable_ipv6 enable_backups disable_backups
9
+ enable_private_networking].freeze
10
10
 
11
- TAG_ACTIONS = %w(
11
+ TAG_ACTIONS = %w[
12
12
  enable_backups disable_backups power_cycle power_on power_off shutdown
13
13
  enable_private_networking enable_ipv6 snapshot
14
- )
14
+ ].freeze
15
15
 
16
16
  resources do
17
17
  default_handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
@@ -45,13 +45,13 @@ module DropletKit
45
45
  handler(204) { |_| true }
46
46
  end
47
47
 
48
- action :add_tags, 'POST /v2/firewalls/:id/tags' do
49
- body { |tags| { tags: tags}.to_json }
48
+ action :add_tags, 'POST /v2/firewalls/:id/tags' do
49
+ body { |tags| { tags: tags }.to_json }
50
50
  handler(204) { |_| true }
51
51
  end
52
52
 
53
53
  action :remove_tags, 'DELETE /v2/firewalls/:id/tags' do
54
- body { |tags| { tags: tags}.to_json }
54
+ body { |tags| { tags: tags }.to_json }
55
55
  handler(204) { |_| true }
56
56
  end
57
57
 
@@ -19,7 +19,7 @@ module DropletKit
19
19
  end
20
20
 
21
21
  action :update, 'PUT /v2/images/:id' do
22
- body {|image| ImageMapping.representation_for(:update, image) }
22
+ body { |image| ImageMapping.representation_for(:update, image) }
23
23
  handler(200) { |response| ImageMapping.extract_single(response.body, :read) }
24
24
  end
25
25
  end
@@ -15,17 +15,15 @@ module DropletKit
15
15
  end
16
16
 
17
17
  action :create, 'POST /v2/kubernetes/clusters' do
18
- body do |object|
18
+ body do |object|
19
19
  # This ensures that both a hash and an instance of KubernetesNodePool can be passed
20
20
  # into the node_pools array
21
- #
21
+ #
22
22
  # Ex:
23
23
  # KubernetesCluster.new(node_pools: [{}])
24
24
  # or
25
25
  # KubernetesCluster.new(node_pools: [KubernetesNodePool.new()])
26
- if object.respond_to?(:node_pools) && object.node_pools.respond_to?(:map)
27
- object.node_pools = object.node_pools.map(&:to_hash)
28
- end
26
+ object.node_pools = object.node_pools.map(&:to_hash) if object.respond_to?(:node_pools) && object.node_pools.respond_to?(:map)
29
27
 
30
28
  KubernetesClusterMapping.representation_for(:create, object)
31
29
  end
@@ -21,7 +21,7 @@ module DropletKit
21
21
  end
22
22
 
23
23
  action :update, 'PUT /v2/load_balancers/:id' do
24
- body {|load_balancer| LoadBalancerMapping.representation_for(:update, load_balancer) }
24
+ body { |load_balancer| LoadBalancerMapping.representation_for(:update, load_balancer) }
25
25
  handler(200) { |response| LoadBalancerMapping.extract_single(response.body, :read) }
26
26
  handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
27
27
  end
@@ -54,7 +54,7 @@ module DropletKit
54
54
  elsif resource.respond_to?(:urn) && resource.urn && DropletKit::BaseModel.valid_urn?(resource.urn)
55
55
  resource.urn
56
56
  else
57
- raise DropletKit::Error.new("cannot assign resource without valid urn: #{resource}")
57
+ raise DropletKit::Error, "cannot assign resource without valid urn: #{resource}"
58
58
  end
59
59
  end
60
60
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DropletKit
4
+ class ReservedIpActionResource < ResourceKit::Resource
5
+ resources do
6
+ default_handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
7
+
8
+ action :assign, 'POST /v2/reserved_ips/:ip/actions' do
9
+ body { |hash| { type: 'assign', droplet_id: hash[:droplet_id] }.to_json }
10
+ handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
11
+ end
12
+
13
+ action :unassign, 'POST /v2/reserved_ips/:ip/actions' do
14
+ body { |hash| { type: 'unassign' }.to_json }
15
+ handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
16
+ end
17
+
18
+ action :find, 'GET /v2/reserved_ips/:ip/actions/:id' do
19
+ handler(200) { |response| ActionMapping.extract_single(response.body, :read) }
20
+ end
21
+
22
+ action :all, 'GET /v2/reserved_ips/:ip/actions' do
23
+ query_keys :per_page, :page
24
+ handler(200) { |response| ActionMapping.extract_collection(response.body, :read) }
25
+ end
26
+ end
27
+
28
+ def all(*args)
29
+ PaginatedResource.new(action(:all), self, *args)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DropletKit
4
+ class ReservedIpResource < ResourceKit::Resource
5
+ resources do
6
+ action :all, 'GET /v2/reserved_ips' do
7
+ query_keys :per_page, :page
8
+ handler(200) { |response| ReservedIpMapping.extract_collection(response.body, :read) }
9
+ end
10
+
11
+ action :find, 'GET /v2/reserved_ips/:ip' do
12
+ handler(200) { |response| ReservedIpMapping.extract_single(response.body, :read) }
13
+ end
14
+
15
+ action :create, 'POST /v2/reserved_ips' do
16
+ body { |object| ReservedIpMapping.representation_for(:create, object) }
17
+ handler(202) { |response| ReservedIpMapping.extract_single(response.body, :read) }
18
+ handler(422) { |response| ErrorMapping.fail_with(FailedCreate, response.body) }
19
+ end
20
+
21
+ action :delete, 'DELETE /v2/reserved_ips/:ip' do
22
+ handler(202) { |response| ActionMapping.extract_single(response.body, :read) }
23
+ handler(204) { |response| true }
24
+ end
25
+ end
26
+
27
+ def all(*args)
28
+ PaginatedResource.new(action(:all), self, *args)
29
+ end
30
+ end
31
+ end
@@ -5,7 +5,7 @@ module DropletKit
5
5
  include ErrorHandlingResourcable
6
6
 
7
7
  resources do
8
- default_handler(:ok, :created) {|r| SSHKeyMapping.extract_single(r.body, :read) }
8
+ default_handler(:ok, :created) { |r| SSHKeyMapping.extract_single(r.body, :read) }
9
9
 
10
10
  action :all, 'GET /v2/account/keys' do
11
11
  query_keys :per_page, :page
@@ -13,14 +13,14 @@ module DropletKit
13
13
  end
14
14
 
15
15
  action :create, 'POST /v2/account/keys' do
16
- body {|object| SSHKeyMapping.representation_for(:create, object) }
16
+ body { |object| SSHKeyMapping.representation_for(:create, object) }
17
17
  end
18
18
 
19
19
  action :find, 'GET /v2/account/keys/:id'
20
20
  action :delete, 'DELETE /v2/account/keys/:id'
21
21
 
22
22
  action :update, 'PUT /v2/account/keys/:id' do
23
- body {|ssh_key| SSHKeyMapping.representation_for(:update, ssh_key) }
23
+ body { |ssh_key| SSHKeyMapping.representation_for(:update, ssh_key) }
24
24
  end
25
25
  end
26
26
 
@@ -11,7 +11,7 @@ module DropletKit
11
11
  type: 'attach',
12
12
  droplet_id: hash[:droplet_id],
13
13
  volume_id: hash[:volume_id], # seems redundant to the id in the url?
14
- region: hash[:region], # seems redundant - inferred from the droplet?
14
+ region: hash[:region] # seems redundant - inferred from the droplet?
15
15
  }.to_json
16
16
  end
17
17
  handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
@@ -23,7 +23,7 @@ module DropletKit
23
23
  type: 'detach',
24
24
  droplet_id: hash[:droplet_id],
25
25
  volume_id: hash[:volume_id], # seems redundant to the id in the url?
26
- region: hash[:region], # seems redundant - inferred from the droplet?
26
+ region: hash[:region] # seems redundant - inferred from the droplet?
27
27
  }.to_json
28
28
  end
29
29
  handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
@@ -34,7 +34,7 @@ module DropletKit
34
34
  {
35
35
  type: 'resize',
36
36
  size_gigabytes: hash[:size_gigabytes],
37
- region: hash[:region],
37
+ region: hash[:region]
38
38
  }.to_json
39
39
  end
40
40
  handler(201, 200) { |response| ActionMapping.extract_single(response.body, :read) }
@@ -26,16 +26,16 @@ module DropletKit
26
26
  end
27
27
 
28
28
  action :update, 'PUT /v2/vpcs/:id' do
29
- body {|vpc| VPCMapping.representation_for(:update, vpc) }
29
+ body { |vpc| VPCMapping.representation_for(:update, vpc) }
30
30
  handler(200) { |response| VPCMapping.extract_single(response.body, :read) }
31
31
  handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
32
32
  end
33
33
 
34
34
  action :patch, 'PATCH /v2/vpcs/:id' do
35
- body {|vpc| VPCMapping.representation_for(:patch, vpc) }
36
- handler(200) { |response| VPCMapping.extract_single(response.body, :read) }
37
- handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
38
- end
35
+ body { |vpc| VPCMapping.representation_for(:patch, vpc) }
36
+ handler(200) { |response| VPCMapping.extract_single(response.body, :read) }
37
+ handler(422) { |response| ErrorMapping.fail_with(FailedUpdate, response.body) }
38
+ end
39
39
 
40
40
  action :delete, 'DELETE /v2/vpcs/:id' do
41
41
  handler(204) { |_| true }
@@ -5,29 +5,29 @@ module DropletKit
5
5
  def self.camelize(term)
6
6
  string = term.to_s
7
7
  string.sub!(/^[a-z\d]*/, &:capitalize)
8
- string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) { $2.capitalize }
9
- string.gsub!('/'.freeze, '::'.freeze)
8
+ string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) { Regexp.last_match(2).capitalize }
9
+ string.gsub!('/', '::')
10
10
  string
11
11
  end
12
12
 
13
13
  def self.underscore(term)
14
- return term unless /[A-Z-]|::/ =~ term
14
+ return term unless /[A-Z-]|::/.match?(term)
15
15
 
16
- word = term.to_s.gsub('::'.freeze, '/'.freeze)
17
- word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
18
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
19
- word.tr!('-'.freeze, '_'.freeze)
16
+ word = term.to_s.gsub('::', '/')
17
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
18
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
19
+ word.tr!('-', '_')
20
20
  word.downcase!
21
21
  word
22
22
  end
23
23
 
24
24
  def self.transform_keys(hash, &block)
25
25
  return hash.transform_keys(&block) if hash.respond_to?(:transform_keys)
26
- return to_enum(__caller__) unless block_given?
26
+ return to_enum(__caller__) unless block
27
27
 
28
28
  {}.tap do |result|
29
29
  hash.each do |key, value|
30
- result[block.call(key)] = value
30
+ result[yield(key)] = value
31
31
  end
32
32
  end
33
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DropletKit
4
- VERSION = "3.16.1"
4
+ VERSION = '3.18.0'
5
5
  end
data/lib/droplet_kit.rb CHANGED
@@ -30,6 +30,7 @@ module DropletKit
30
30
  autoload :Balance, 'droplet_kit/models/balance'
31
31
  autoload :DropletUpgrade, 'droplet_kit/models/droplet_upgrade'
32
32
  autoload :FloatingIp, 'droplet_kit/models/floating_ip'
33
+ autoload :ReservedIp, 'droplet_kit/models/reserved_ip'
33
34
  autoload :Project, 'droplet_kit/models/project'
34
35
  autoload :ProjectAssignment, 'droplet_kit/models/project_assignment'
35
36
  autoload :Links, 'droplet_kit/models/links'
@@ -88,6 +89,8 @@ module DropletKit
88
89
  autoload :DropletUpgradeResource, 'droplet_kit/resources/droplet_upgrade_resource'
89
90
  autoload :FloatingIpResource, 'droplet_kit/resources/floating_ip_resource'
90
91
  autoload :FloatingIpActionResource, 'droplet_kit/resources/floating_ip_action_resource'
92
+ autoload :ReservedIpResource, 'droplet_kit/resources/reserved_ip_resource'
93
+ autoload :ReservedIpActionResource, 'droplet_kit/resources/reserved_ip_action_resource'
91
94
  autoload :ProjectResource, 'droplet_kit/resources/project_resource'
92
95
  autoload :TagResource, 'droplet_kit/resources/tag_resource'
93
96
  autoload :VolumeResource, 'droplet_kit/resources/volume_resource'
@@ -125,6 +128,7 @@ module DropletKit
125
128
  autoload :BalanceMapping, 'droplet_kit/mappings/balance_mapping'
126
129
  autoload :DropletUpgradeMapping, 'droplet_kit/mappings/droplet_upgrade_mapping'
127
130
  autoload :FloatingIpMapping, 'droplet_kit/mappings/floating_ip_mapping'
131
+ autoload :ReservedIpMapping, 'droplet_kit/mappings/reserved_ip_mapping'
128
132
  autoload :ProjectMapping, 'droplet_kit/mappings/project_mapping'
129
133
  autoload :ProjectAssignmentMapping, 'droplet_kit/mappings/project_assignment_mapping'
130
134
  autoload :LinksMapping, 'droplet_kit/mappings/links_mapping'
@@ -181,11 +185,11 @@ module DropletKit
181
185
  attr_writer :limit, :remaining
182
186
 
183
187
  def limit
184
- @limit.to_i if @limit
188
+ @limit&.to_i
185
189
  end
186
190
 
187
191
  def remaining
188
- @remaining.to_i if @remaining
192
+ @remaining&.to_i
189
193
  end
190
194
  end
191
195
  end