Class: Gcloud::Dns::Connection
- Inherits:
-
Object
- Object
- Gcloud::Dns::Connection
- Defined in:
- lib/gcloud/dns/connection.rb
Constant Summary collapse
- API_VERSION =
"v1"
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#project ⇒ Object
Returns the value of attribute project.
Class Method Summary collapse
-
.fqdn(name, origin_dns) ⇒ Object
Fully Qualified Domain Name.
- .ip_addr?(name) ⇒ Boolean
Instance Method Summary collapse
- #create_change(zone_id, additions, deletions) ⇒ Object
- #create_zone(zone_name, zone_dns, description: nil, name_server_set: nil) ⇒ Object
- #delete_zone(zone_id) ⇒ Object
- #get_change(zone_id, change_id) ⇒ Object
- #get_project(project_id = @project) ⇒ Object
- #get_zone(zone_id) ⇒ Object
-
#initialize(project, credentials) ⇒ Connection
constructor
Creates a new Connection instance.
- #inspect ⇒ Object
- #list_changes(zone_id, token: nil, max: nil, order: nil, sort: nil) ⇒ Object
- #list_records(zone_id, name = nil, type = nil, token: nil, max: nil) ⇒ Object
- #list_zones(token: nil, max: nil) ⇒ Object
Constructor Details
#initialize(project, credentials) ⇒ Connection
Creates a new Connection instance.
31 32 33 34 35 36 37 38 |
# File 'lib/gcloud/dns/connection.rb', line 31 def initialize project, credentials @project = project @credentials = credentials @client = Google::APIClient.new application_name: "gcloud-ruby", application_version: Gcloud::VERSION @client. = @credentials.client @dns = @client.discovered_api "dns", API_VERSION end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
27 28 29 |
# File 'lib/gcloud/dns/connection.rb', line 27 def credentials @credentials end |
#project ⇒ Object
Returns the value of attribute project.
26 27 28 |
# File 'lib/gcloud/dns/connection.rb', line 26 def project @project end |
Class Method Details
.fqdn(name, origin_dns) ⇒ Object
Fully Qualified Domain Name
138 139 140 141 142 143 144 145 146 |
# File 'lib/gcloud/dns/connection.rb', line 138 def self.fqdn name, origin_dns name = name.to_s.strip return name if self.ip_addr? name name = origin_dns if name.empty? name = origin_dns if name == "@" name = "#{name}.#{origin_dns}" unless name.include? "." name = "#{name}." unless name.end_with? "." name end |
.ip_addr?(name) ⇒ Boolean
152 153 154 155 156 157 |
# File 'lib/gcloud/dns/connection.rb', line 152 def self.ip_addr? name IPAddr.new name true rescue IPAddr::Error false end |
Instance Method Details
#create_change(zone_id, additions, deletions) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/gcloud/dns/connection.rb', line 110 def create_change zone_id, additions, deletions change = { "kind" => "dns#change", "additions" => Array(additions), "deletions" => Array(deletions) } @client.execute( api_method: @dns.changes.create, parameters: { project: @project, managedZone: zone_id }, body_object: change ) end |
#create_zone(zone_name, zone_dns, description: nil, name_server_set: nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gcloud/dns/connection.rb', line 66 def create_zone zone_name, zone_dns, description: nil, name_server_set: nil body = { kind: "dns#managedZone", name: zone_name, dnsName: zone_dns, description: (description || ""), nameServerSet: name_server_set }.delete_if { |_, v| v.nil? } @client.execute( api_method: @dns.managed_zones.create, parameters: { project: @project }, body_object: body ) end |
#delete_zone(zone_id) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/gcloud/dns/connection.rb', line 81 def delete_zone zone_id @client.execute( api_method: @dns.managed_zones.delete, parameters: { project: @project, managedZone: zone_id } ) end |
#get_change(zone_id, change_id) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/gcloud/dns/connection.rb', line 88 def get_change zone_id, change_id @client.execute( api_method: @dns.changes.get, parameters: { project: @project, managedZone: zone_id, changeId: change_id } ) end |
#get_project(project_id = @project) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/gcloud/dns/connection.rb', line 40 def get_project project_id = @project @client.execute( api_method: @dns.projects.get, parameters: { project: project_id } ) end |
#get_zone(zone_id) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/gcloud/dns/connection.rb', line 47 def get_zone zone_id @client.execute( api_method: @dns.managed_zones.get, parameters: { project: @project, managedZone: zone_id } ) end |
#inspect ⇒ Object
159 160 161 |
# File 'lib/gcloud/dns/connection.rb', line 159 def inspect "#{self.class}(#{@project})" end |
#list_changes(zone_id, token: nil, max: nil, order: nil, sort: nil) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/gcloud/dns/connection.rb', line 96 def list_changes zone_id, token: nil, max: nil, order: nil, sort: nil params = { project: @project, managedZone: zone_id, pageToken: token, maxResults: max, sortBy: sort, sortOrder: order }.delete_if { |_, v| v.nil? } @client.execute( api_method: @dns.changes.list, parameters: params ) end |
#list_records(zone_id, name = nil, type = nil, token: nil, max: nil) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gcloud/dns/connection.rb', line 122 def list_records zone_id, name = nil, type = nil, token: nil, max: nil params = { project: @project, managedZone: zone_id, pageToken: token, maxResults: max, name: name, type: type }.delete_if { |_, v| v.nil? } @client.execute( api_method: @dns.resource_record_sets.list, parameters: params ) end |
#list_zones(token: nil, max: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gcloud/dns/connection.rb', line 54 def list_zones token: nil, max: nil params = { project: @project, pageToken: token, maxResults: max }.delete_if { |_, v| v.nil? } @client.execute( api_method: @dns.managed_zones.list, parameters: params ) end |