splicer-dns_made_easy 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzEyY2IyZTJjZDVlODIwNTk4NDU1ZmQ2OGNjMzMwZDQ4N2MwNGZlNg==
5
+ data.tar.gz: !binary |-
6
+ MThlNzIwNzgwMjQwYjkzZWE3MjU0Mjg0MzFjYTAzNjhiYWE2OTMzMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NmQ4ZWRjMDkzNDM1MzQ2N2E5NmM3MWFiNzBjZjdhNzg1NWU3N2E0Mzk0YTI0
10
+ MWM4MGYwNzE1YjQ0MjhjNzM4MTM4MWM1YzVjYzYzYzdjYTQ1NGEyNzhjMzY2
11
+ OGEzOTQ2OTA1N2IzMjAyOWRkN2QzMzQ3YWVlN2Q3Mzc2ZmU4OTM=
12
+ data.tar.gz: !binary |-
13
+ NDYxNjNiODUxODFkMzhlZTcyZDk4ZDMwMTRlNDlkM2Y5MTBkODJmMzc5OWRm
14
+ OTQ1NTY5NTY0MzFlZjUzZDRjNTYyYjMwZTdlMTY2NTI4OGYyYWM3YThiOTEx
15
+ MTFiNTIzZjc3NmYzNmJhNjNiZmI1YzkwOGUzNjM4M2M3YTQwZWM=
@@ -0,0 +1,22 @@
1
+ module Splicer
2
+ module DnsMadeEasy
3
+
4
+ class Domain
5
+ attr_reader :id, :data
6
+
7
+ def initialize(params={})
8
+ @id = params['id']
9
+ @data = params
10
+ end
11
+
12
+ def id?
13
+ !!@id
14
+ end
15
+
16
+ def persisted?
17
+ id?
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -1,7 +1,8 @@
1
1
  module Splicer
2
2
  module DnsMadeEasy
3
3
 
4
- class Provider
4
+ # @author Matthew A. Johnston <warmwaffles@gmail.com>
5
+ class Provider < Splicer::Provider
5
6
  attr_reader :client
6
7
 
7
8
  def initialize(config)
@@ -9,120 +10,189 @@ module Splicer
9
10
  @client = config.client
10
11
  end
11
12
 
12
- def publish(zone, method)
13
- case method
14
- when :rewrite
15
- rewrite(zone)
16
- when :merge
17
- merge(zone)
18
- else
19
- false
13
+ def create_zone(zone)
14
+ domain = find_domain(zone.name)
15
+ return false if domain.persisted?
16
+
17
+ client.post('dns/managed', name: zone.name)
18
+
19
+ zone.records.each do |record|
20
+ create_record(domain.id, record)
20
21
  end
21
22
  end
22
23
 
23
- # Destroys a zone
24
- def destroy(zone)
25
- domain = search(zone.name)
26
- id = domain['id']
27
- client.delete("dns/managed/#{id}")
28
- true
24
+ def update_zone(zone)
25
+ rewrite_zone(zone)
29
26
  end
30
27
 
31
- private
32
-
33
- def rewrite(zone)
34
- domain = search(zone.name)
35
- unless domain
36
- domain = create_domain(zone.name)
37
- end
28
+ def rewrite_zone(zone)
29
+ domain = find_domain(zone.name)
30
+ return false unless domain.persisted?
38
31
 
39
- # Nuke all of the records in a zone
40
- records = JSON.parse(client.get(domain_records_url(domain)))['data']
41
- unless records.empty?
42
- delete_records(domain, records.collect { |r| r['id'] })
32
+ fetch_records(domain.id).each do |record|
33
+ delete_record(domain.id, record.id)
43
34
  end
44
35
 
45
- # Time to populate the zone
46
36
  zone.records.each do |record|
47
- create_record(domain, record)
37
+ create_record(domain.id, record)
48
38
  end
49
39
  end
50
40
 
51
- def merge(zone)
52
- domain = search(zone.name)
53
- unless domain
54
- domain = create_domain(zone.name)
41
+ def delete_zone(zone)
42
+ domain = find_domain(zone.name)
43
+ return false unless domain.persisted?
44
+ client.delete(domain_resource_url(domain.id))
45
+ end
46
+
47
+ def delete_record_in_zone(record, zone)
48
+ domain = find_domain(zone.name)
49
+ return false unless domain.persisted?
50
+
51
+ record = find_records(record.name, record.type, domain.id)
52
+ return false if records.empty?
53
+
54
+ delete_record(domain_id, records.first.id)
55
+ end
56
+
57
+ def update_record_in_zone(record, zone)
58
+ domain = find_domain(zone.name)
59
+ return false unless domain.persisted?
60
+
61
+ records = find_records(record.name, record.type, domain.id)
62
+ return false if records.empty?
63
+
64
+ update_record(domain.id, records.first.id, record)
65
+ end
66
+
67
+ def create_record_in_zone(record, zone)
68
+ domain = find_domain(zone.name)
69
+ return false unless domain.persisted?
70
+
71
+ records = find_records(record.name, record.type, domain.id)
72
+ return false unless records.empty?
73
+
74
+ create_record(domain.id, record)
75
+ end
76
+
77
+ private
78
+
79
+ # @param [Integer] domain_id
80
+ # @return [Array<Splicer::DnsMadeEasy::Record>]
81
+ def fetch_records(domain_id)
82
+ response = JSON.parse(client.get(records_resource_url(domain_id)))
83
+ list = []
84
+ response['data'].each do |r|
85
+ list << Record.new(r)
55
86
  end
87
+ list
88
+ rescue Splicer::Errors::RequestError => error
89
+ []
90
+ end
56
91
 
57
- zone.records.each do |record|
58
- records = search_for_record(domain, record)
59
- if records
60
- delete_records(domain, records.collect { |r| r['id'] })
92
+ # @param [Integer] domain_id
93
+ # @return [Array<Splicer::DnsMadeEasy::Record>]
94
+ def find_records(name, type, domain_id)
95
+ payload = {
96
+ type: type,
97
+ recordName: name ? name : ''
98
+ }
99
+ response = JSON.parse(client.get(records_resource_url(domain_id), payload))
100
+ if response['data'].is_a?(Array)
101
+ list = []
102
+ response['data'].each do |params|
103
+ list << Record.new(params)
61
104
  end
62
- create_record(domain, record)
105
+ list
106
+ else
107
+ [Record.new(response['data'])]
63
108
  end
109
+ rescue Splicer::Errors::RequestError => error
110
+ []
64
111
  end
65
112
 
66
- def create_record(domain, record)
67
- payload = { type: record.type, gtdLocation: 'DEFAULT', ttl: record.ttl }
68
- payload[:name] = record.name ? record.name : ''
69
- case record
70
- when Splicer::Records::ARecord
71
- payload.merge!({ value: record.ip })
72
- when Splicer::Records::AAAARecord
73
- payload.merge!({ value: record.ip })
74
- when Splicer::Records::CNAMERecord
75
- payload.merge!({ value: record.cname })
76
- when Splicer::Records::MXRecord
77
- payload.merge!({ value: record.exchanger, mxLevel: record.priority })
78
- when Splicer::Records::NSRecord
79
- payload.merge!({ value: record.server })
80
- when Splicer::Records::PTRRecord
81
- payload.merge!({ value: record.host })
82
- when Splicer::Records::SRVRecord
83
- payload.merge!({
84
- value: record.target,
85
- weight: record.weight,
86
- priority: record.priority,
87
- port: record.port
88
- })
89
- when Splicer::Records::TXTRecord
90
- payload.merge!({
91
- value: record.text
92
- })
93
- else
94
- return nil
95
- end
96
- client.post(domain_records_url(domain), payload)
113
+ # @param [Integer] domain_id
114
+ # @param [Splicer::Records::Record] splicer_record
115
+ # @return [String]
116
+ def create_record(domain_id, splicer_record)
117
+ client.post(records_resource_url(domain_id), record_resource_payload(splicer_record))
97
118
  end
98
119
 
99
- def search_for_record(domain, record)
100
- payload = { type: record.type }
101
- payload[:recordName] = record.name ? record.name : ''
102
- resp = client.get(domain_records_url(domain), payload)
103
- JSON.parse(resp)['data']
120
+ # @param [Integer] record_id
121
+ # @param [Integer] domain_id
122
+ # @param [Splicer::Records::Record] splicer_record
123
+ # @return [String]
124
+ def update_record(domain_id, record_id, splicer_record)
125
+ client.put(records_resource_url(domain_id, record_id), record_resource_payload(splicer_record).merge({id: record_id}))
104
126
  end
105
127
 
106
- def domain_records_url(domain)
107
- "dns/managed/#{domain['id']}/records"
128
+ # @param [Integer] record_id
129
+ # @param [Integer] domain_id
130
+ # @return [String]
131
+ def delete_record(domain_id, record_id)
132
+ client.delete(records_resource_url(domain_id, record_id), id: record_id)
108
133
  end
109
134
 
110
- def create_domain(name)
111
- JSON.parse(client.post('dns/managed', name: name))
135
+ # @param [Integer] domain_id
136
+ # @return [String]
137
+ def records_resource_url(domain_id, record_id=nil)
138
+ if record_id
139
+ "dns/managed/#{domain_id}/records/#{record_id}"
140
+ else
141
+ "dns/managed/#{domain_id}/records"
142
+ end
112
143
  end
113
144
 
114
- def delete_records(domain, ids)
115
- return true if ids.empty?
116
- client.delete(domain_records_url(domain), ids: ids)
145
+ # @param [Integer] domain_id
146
+ # @return [String]
147
+ def domain_resource_url(domain_id)
148
+ "dns/managed/#{domain_id}"
117
149
  end
118
150
 
119
- # Search for a domain
120
- # @param [String] name the name of the domain you wish to look for
121
- # @return [Hash] nil if it can't be found
122
- def search(name)
123
- JSON.parse(client.get("dns/managed/id/#{name}"))
151
+ def find_domain(name)
152
+ response = JSON.parse(client.get("dns/managed/id/#{name}"))
153
+ Domain.new(response)
124
154
  rescue Splicer::Errors::RequestError => error
125
- nil
155
+ Domain.new
156
+ end
157
+
158
+ # Returns a hash for the record data
159
+ # @param [Splicer::Records::Record] record
160
+ # @return [Hash]
161
+ def record_resource_payload(record)
162
+ payload = {
163
+ type: record.type,
164
+ gtdLocation: 'DEFAULT',
165
+ name: record.name ? record.name : '',
166
+ ttl: record.ttl
167
+ }
168
+ case record
169
+ when Splicer::Records::ARecord
170
+ payload.merge!({ value: record.ip })
171
+ when Splicer::Records::AAAARecord
172
+ payload.merge!({ value: record.ip })
173
+ when Splicer::Records::CNAMERecord
174
+ payload.merge!({ value: record.cname })
175
+ when Splicer::Records::MXRecord
176
+ payload.merge!({ value: record.exchanger, mxLevel: record.priority })
177
+ when Splicer::Records::NSRecord
178
+ payload.merge!({ value: record.server })
179
+ when Splicer::Records::PTRRecord
180
+ payload.merge!({ value: record.host })
181
+ when Splicer::Records::SRVRecord
182
+ payload.merge!({
183
+ value: record.target,
184
+ weight: record.weight,
185
+ priority: record.priority,
186
+ port: record.port
187
+ })
188
+ when Splicer::Records::TXTRecord
189
+ payload.merge!({
190
+ value: record.text
191
+ })
192
+ else
193
+ payload = {}
194
+ end
195
+ payload
126
196
  end
127
197
  end
128
198
 
@@ -0,0 +1,20 @@
1
+ module Splicer
2
+ module DnsMadeEasy
3
+
4
+ class Record
5
+ attr_reader :id, :type, :value, :ttl, :data
6
+ def initialize(params={})
7
+ @id = params['id']
8
+ @type = params['type']
9
+ @value = params['value']
10
+ @ttl = params['ttl']
11
+ @data = params
12
+ end
13
+
14
+ def id?
15
+ !!@id
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Splicer
2
2
  module DnsMadeEasy
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -5,6 +5,8 @@ require 'json'
5
5
 
6
6
  require 'splicer/dns_made_easy/version'
7
7
  require 'splicer/dns_made_easy/time'
8
+ require 'splicer/dns_made_easy/domain'
9
+ require 'splicer/dns_made_easy/record'
8
10
  require 'splicer/dns_made_easy/provider'
9
11
  require 'splicer/dns_made_easy/config'
10
12
  require 'splicer/dns_made_easy/client'
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Splicer::DnsMadeEasy::Domain do
4
+
5
+ describe '#initialize' do
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Splicer::DnsMadeEasy::Provider do
4
+ let(:config) { Splicer::DnsMadeEasy::Config.new('key','secret') }
5
+ let(:provider) { Splicer::DnsMadeEasy::Provider.new(config) }
6
+
7
+ describe '#create_zone' do
8
+ subject { provider.create_zone(zone) }
9
+ end
10
+
11
+ describe '#update_zone' do
12
+ subject { provider.update_zone(zone) }
13
+ end
14
+
15
+ describe '#rewrite_zone' do
16
+ subject { provider.rewrite_zone(zone) }
17
+ end
18
+
19
+ describe '#delete_zone' do
20
+ subject { provider.delete_zone(zone) }
21
+ end
22
+
23
+ describe '#delete_record_in_zone' do
24
+ subject { provider.delete_record_in_zone(record, zone) }
25
+ end
26
+
27
+ describe '#update_record_in_zone' do
28
+ subject { provider.update_record_in_zone(record, zone) }
29
+ end
30
+
31
+ describe '#create_record_in_zone' do
32
+ subject { provider.create_record_in_zone(record, zone) }
33
+ end
34
+ end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency('splicer', '~> 1.0')
21
+ spec.add_dependency('splicer', '~> 1.1')
22
22
  spec.add_dependency('rest-client')
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splicer-dns_made_easy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matthew Johnston
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-10 00:00:00.000000000 Z
11
+ date: 2013-05-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: splicer
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '1.0'
19
+ version: '1.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: '1.0'
26
+ version: '1.1'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rest-client
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -109,45 +98,44 @@ files:
109
98
  - lib/splicer/dns_made_easy.rb
110
99
  - lib/splicer/dns_made_easy/client.rb
111
100
  - lib/splicer/dns_made_easy/config.rb
101
+ - lib/splicer/dns_made_easy/domain.rb
112
102
  - lib/splicer/dns_made_easy/provider.rb
103
+ - lib/splicer/dns_made_easy/record.rb
113
104
  - lib/splicer/dns_made_easy/time.rb
114
105
  - lib/splicer/dns_made_easy/version.rb
115
106
  - spec/spec_helper.rb
116
107
  - spec/splicer/dns_made_easy/client_spec.rb
117
108
  - spec/splicer/dns_made_easy/config_spec.rb
109
+ - spec/splicer/dns_made_easy/domain_spec.rb
110
+ - spec/splicer/dns_made_easy/provider_spec.rb
118
111
  - splicer-dns_made_easy.gemspec
119
112
  homepage: https://github.com/zippykid/dns_made_easy
120
113
  licenses:
121
114
  - MIT
115
+ metadata: {}
122
116
  post_install_message:
123
117
  rdoc_options: []
124
118
  require_paths:
125
119
  - lib
126
120
  required_ruby_version: !ruby/object:Gem::Requirement
127
- none: false
128
121
  requirements:
129
122
  - - ! '>='
130
123
  - !ruby/object:Gem::Version
131
124
  version: '0'
132
- segments:
133
- - 0
134
- hash: 4133550921617049631
135
125
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
126
  requirements:
138
127
  - - ! '>='
139
128
  - !ruby/object:Gem::Version
140
129
  version: '0'
141
- segments:
142
- - 0
143
- hash: 4133550921617049631
144
130
  requirements: []
145
131
  rubyforge_project:
146
- rubygems_version: 1.8.25
132
+ rubygems_version: 2.0.3
147
133
  signing_key:
148
- specification_version: 3
134
+ specification_version: 4
149
135
  summary: The splicer adapter for interacting DnsMadeEasy
150
136
  test_files:
151
137
  - spec/spec_helper.rb
152
138
  - spec/splicer/dns_made_easy/client_spec.rb
153
139
  - spec/splicer/dns_made_easy/config_spec.rb
140
+ - spec/splicer/dns_made_easy/domain_spec.rb
141
+ - spec/splicer/dns_made_easy/provider_spec.rb