-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
|
||
module Dennis | ||
class RecordType | ||
|
||
class << self | ||
|
||
def all(client) | ||
request = client.api.create_request(:get, 'record_types') | ||
request.perform.hash['record_types'].each_with_object({}) do |rt, hash| | ||
type = new(rt) | ||
hash[type.name] = type | ||
end | ||
end | ||
|
||
end | ||
|
||
def initialize(hash) | ||
@hash = hash | ||
end | ||
|
||
def name | ||
@hash['name'] | ||
end | ||
|
||
def requires_priority? | ||
@hash['requires_priority'] == true | ||
end | ||
|
||
def managed_only? | ||
@hash['managed_only'] == true | ||
end | ||
|
||
def content_attributes | ||
@hash['content_attributes'].map do |hash| | ||
ContentAttribute.new(hash) | ||
end | ||
end | ||
|
||
class ContentAttribute | ||
|
||
def initialize(hash) | ||
@hash = hash | ||
end | ||
|
||
def name | ||
@hash['name'] | ||
end | ||
|
||
def label | ||
@hash['label'] | ||
end | ||
|
||
def type | ||
@hash['type'] | ||
end | ||
|
||
def options | ||
return [] if @hash['options'].nil? | ||
|
||
@hash['options'].map do |hash| | ||
ContentAttributeOption.new(hash) | ||
end | ||
end | ||
|
||
end | ||
|
||
class ContentAttributeOption | ||
|
||
def initialize(hash) | ||
@hash = hash | ||
end | ||
|
||
def label | ||
@hash['label'] | ||
end | ||
|
||
def value | ||
@hash['value'] | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
module Dennis | ||
|
||
describe RecordType do | ||
include_context 'with client' | ||
|
||
describe '.all' do | ||
it 'returns all the record types' do | ||
VCR.use_cassette('record-types') do | ||
types = described_class.all(@client) | ||
expect(types).to be_a Hash | ||
expect(types).to match hash_including( | ||
'A' => have_attributes( | ||
name: 'A', | ||
requires_priority?: false, | ||
managed_only?: false, | ||
content_attributes: [ | ||
have_attributes( | ||
name: 'ip_address', | ||
type: 'text', | ||
options: [] | ||
) | ||
] | ||
), | ||
'SOA' => have_attributes( | ||
name: 'SOA', | ||
requires_priority?: false, | ||
managed_only?: true, | ||
content_attributes: [] | ||
), | ||
'MX' => have_attributes( | ||
name: 'MX', | ||
requires_priority?: true, | ||
managed_only?: false, | ||
content_attributes: [ | ||
have_attributes( | ||
name: 'hostname', | ||
type: 'text', | ||
options: [] | ||
) | ||
] | ||
), | ||
'CAA' => have_attributes( | ||
name: 'CAA', | ||
requires_priority?: false, | ||
managed_only?: false, | ||
content_attributes: [ | ||
have_attributes( | ||
name: 'flag', | ||
type: 'text', | ||
options: [] | ||
), | ||
have_attributes( | ||
name: 'tag', | ||
type: 'options', | ||
options: [ | ||
have_attributes(label: 'issue', value: 'issue'), | ||
have_attributes(label: 'issuewild', value: 'issuewild'), | ||
have_attributes(label: 'iodef', value: 'iodef'), | ||
have_attributes(label: 'contactemail', value: 'contactemail'), | ||
have_attributes(label: 'contactphone', value: 'contactphone') | ||
] | ||
), | ||
have_attributes( | ||
name: 'value', | ||
type: 'text', | ||
options: [] | ||
) | ||
] | ||
) | ||
) | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |