# Cloud DNS API - Class Google::Cloud::Dns::Zone::Transaction (v1.2.0)

1.2.0 (latest) 1.1.1 1.0.0 0.37.0 0.36.1 0.35.1 Reference documentation and code samples for the Cloud DNS API class Google::Cloud::Dns::Zone::Transaction.

## DNS Zone Transaction

This object is used by [#update](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-dns/latest/Google-Cloud-Dns-Zone#Google__Cloud__Dns__Zone_update_instance_ "Google::Cloud::Dns::Zone#update (method)") when passed a block. These
methods are used to update the records that are sent to the Google
Cloud DNS API.

## Inherits

- Object

## Example

```ruby
require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.add     "example.com.", "A",  86400, "1.2.3.4"
  tx.remove  "example.com.", "TXT"
  tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
                                           "20 mail2.example.com."]
  tx.modify "www.example.com.", "CNAME" do |cname|
    cname.ttl = 86400 # only change the TTL
  end
end
```

## Methods

### #add

    def add(name, type, ttl, data)

Adds a record to the Zone.
**Parameters**

- **name** (String) --- The owner of the record. For example: `example.com.`.
- **type** (String) --- The identifier of a [supported record
  type](https://cloud.google.com/dns/docs/records-overview). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
- **ttl** (Integer) --- The number of seconds that the record can be cached by resolvers.
- **data** (String, Array\<String\>) --- The resource record data, as determined by `type` and defined in [RFC 1035 (section
  5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034
  (section
  3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.
**Example**

```ruby
require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.add     "example.com.", "A",  86400, "1.2.3.4"
end
```

### #modify

    def modify(name, type, &block) { |record| ... }

Modifies records on the Zone. Records matching the `name` and `type`
are yielded to the block where they can be modified.
**Parameters**

- **name** (String) --- The owner of the record. For example: `example.com.`.
- **type** (String) --- The identifier of a [supported record
  type](https://cloud.google.com/dns/docs/records-overview). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
**Yields**

- (record) --- a block yielding each matching record
**Yield Parameter**

- **record** ([Record](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-dns/latest/Google-Cloud-Dns-Record)) --- the record to be modified
**Example**

```ruby
require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.modify "www.example.com.", "CNAME" do |cname|
    cname.ttl = 86400 # only change the TTL
  end
end
```

### #remove

    def remove(name, type)

Removes records from the Zone. The records are looked up before they
are removed.
**Parameters**

- **name** (String) --- The owner of the record. For example: `example.com.`.
- **type** (String) --- The identifier of a [supported record
  type](https://cloud.google.com/dns/docs/records-overview). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
**Example**

```ruby
require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.remove  "example.com.", "TXT"
end
```

### #replace

    def replace(name, type, ttl, data)

Replaces existing records on the Zone. Records matching the `name`
and `type` are replaced.
**Parameters**

- **name** (String) --- The owner of the record. For example: `example.com.`.
- **type** (String) --- The identifier of a [supported record
  type](https://cloud.google.com/dns/docs/records-overview). For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
- **ttl** (Integer) --- The number of seconds that the record can be cached by resolvers.
- **data** (String, Array\<String\>) --- The resource record data, as determined by `type` and defined in [RFC 1035 (section
  5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034
  (section
  3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For example: `192.0.2.1` or `example.com.`.
**Example**

```ruby
require "google/cloud/dns"

dns = Google::Cloud::Dns.new
zone = dns.zone "example-com"
zone.update do |tx|
  tx.replace "example.com.",
             "MX", 86400,
             ["10 mail1.example.com.",
              "20 mail2.example.com."]
end
```