Skip to content

Commit

Permalink
feat: support for tagged records
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Apr 15, 2021
1 parent 290f289 commit fe8e464
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 28 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ zone = client.zone('some-ref', field: :external_reference)
# Get all the records for a zone
zone.records

# Get specific type of records for a zone
zone.records(type: 'A')

# Get all records matching a given name
zone.records(name: 'www')

# Get all records matching a given query (for any content in name or content)
zone.records(query: 'v=spf')

# Get all records with ANY of the given tags
zone.records(tags: ['tag1'])

# Create a new group
group = client.create_group(name: 'My example group', external_reference: 'some-ref')

Expand Down
17 changes: 16 additions & 1 deletion lib/dennis/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ class Record

class << self

def all(client, zone, type: nil, name: nil, query: nil)
def all(client, zone, type: nil, name: nil, query: nil, tags: nil)
request = client.api.create_request(:get, 'zones/:zone/records')
request.arguments[:zone] = zone
request.arguments[:name] = name if name
request.arguments[:type] = type if type
request.arguments[:query] = query if query
request.arguments[:tags] = tags if tags
request.perform.hash['records'].map { |hash| new(client, hash) }
end

def all_by_tag(client, tags, group: nil)
request = client.api.create_request(:get, 'records/tagged')
request.arguments[:tags] = tags
request.arguments[:group] = group if group
request.perform.hash['records'].map { |hash| new(client, hash) }
end

Expand Down Expand Up @@ -123,6 +131,13 @@ def updated_at
Time.at(@hash['updated_at'])
end

def zone
return @zone if @zone
return nil unless @hash['zone']

@zone = Zone.new(@client, @hash['zone'])
end

def content
return nil if type.nil?

Expand Down
Loading

0 comments on commit fe8e464

Please sign in to comment.