dnsmadeeasy-rest-api 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +32 -0
- data/README.md +12 -0
- data/Rakefile +2 -0
- data/dnsmadeeasy-rest-api.gemspec +15 -0
- data/lib/dnsmadeeasy-rest-api.rb +197 -0
- data/spec/lib/dnsmadeeasyapi-rest-api_spec.rb +248 -0
- data/spec/spec_helper.rb +18 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f9ddc73dd5d5d013d421ee073808567c2442dae3
|
4
|
+
data.tar.gz: 1483b6715e07ad01e3d7f50c49cd52a665919c47
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bfa52525de4f9326a6a8ed564f768c39bb6198fc50129e6b83dad1c34a2840144ae0b2687a4f1dc96a44164559b50d0de5405c83efc7cc9dc235cbc2e52ce4bc
|
7
|
+
data.tar.gz: 8613bb2c37928fa9a88e4546c6344991d17951a6cadb85d8368fa35cbe9e6bfeaf6eb282949118ba487519253ab6f0a5a017abd4a33182c9e7a26ad3126c9fff
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dnsmadeeasy-rest-api (1.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.3.6)
|
10
|
+
crack (0.4.2)
|
11
|
+
safe_yaml (~> 1.0.0)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
rspec (2.14.1)
|
14
|
+
rspec-core (~> 2.14.0)
|
15
|
+
rspec-expectations (~> 2.14.0)
|
16
|
+
rspec-mocks (~> 2.14.0)
|
17
|
+
rspec-core (2.14.8)
|
18
|
+
rspec-expectations (2.14.5)
|
19
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
+
rspec-mocks (2.14.6)
|
21
|
+
safe_yaml (1.0.3)
|
22
|
+
webmock (1.18.0)
|
23
|
+
addressable (>= 2.3.6)
|
24
|
+
crack (>= 0.3.2)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
dnsmadeeasy-rest-api!
|
31
|
+
rspec
|
32
|
+
webmock
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Dns Made Easy Api, but better.
|
2
|
+
==============
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
## Contributing
|
7
|
+
|
8
|
+
1. Fork it
|
9
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
10
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
11
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
12
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'dnsmadeeasy-rest-api'
|
3
|
+
s.version = '1.0.1'
|
4
|
+
s.authors = ['Paul Henry', 'James Hart']
|
5
|
+
s.email = 'ops@wanelo.com'
|
6
|
+
s.license = 'Apache'
|
7
|
+
s.summary = 'DNS Made Easy V2.0 REST API client for Ruby'
|
8
|
+
s.description = 'DNS Made Easy V2.0 REST API client for Ruby, but better. With tests and no dependencies.'
|
9
|
+
s.homepage = 'https://github.com/wanelo/dnsmadeeasy-rest-api'
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
|
13
|
+
s.add_development_dependency 'rspec'
|
14
|
+
s.add_development_dependency 'webmock'
|
15
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'openssl'
|
3
|
+
require 'json'
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
class DnsMadeEasy
|
8
|
+
|
9
|
+
attr_accessor :base_uri
|
10
|
+
|
11
|
+
def initialize (api_key, api_secret, sandbox = false)
|
12
|
+
raise "api_key is undefined" unless api_key
|
13
|
+
raise "api_secret is undefined" unless api_secret
|
14
|
+
|
15
|
+
@api_key = api_key
|
16
|
+
@api_secret = api_secret
|
17
|
+
|
18
|
+
if sandbox
|
19
|
+
self.base_uri = 'https://api.sandbox.dnsmadeeasy.com/V2.0'
|
20
|
+
else
|
21
|
+
self.base_uri = 'https://api.dnsmadeeasy.com/V2.0'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# -----------------------------------
|
26
|
+
# ------------- DOMAINS -------------
|
27
|
+
# -----------------------------------
|
28
|
+
|
29
|
+
def get_id_by_domain(domain_name)
|
30
|
+
get("/dns/managed/id/#{domain_name}")['id']
|
31
|
+
end
|
32
|
+
|
33
|
+
def domains
|
34
|
+
get '/dns/managed/'
|
35
|
+
end
|
36
|
+
|
37
|
+
def domain(domain_name)
|
38
|
+
get "/dns/managed/#{get_id_by_domain(domain_name)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_domain(domain_name)
|
42
|
+
delete "/dns/managed/#{get_id_by_domain(domain_name)}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_domains(names)
|
46
|
+
post('/dns/managed/', names: names)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_domain(domain_name)
|
50
|
+
create_domains([domain_name])
|
51
|
+
end
|
52
|
+
|
53
|
+
# -----------------------------------
|
54
|
+
# ------------- RECORDS -------------
|
55
|
+
# -----------------------------------
|
56
|
+
|
57
|
+
def records_for(domain_name)
|
58
|
+
get "/dns/managed/#{get_id_by_domain(domain_name)}/records"
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_record_id(domain_name, name, type)
|
62
|
+
records = records_for(domain_name)
|
63
|
+
|
64
|
+
records['data'].select { |r| r['name'] == name && r['type'] == type }
|
65
|
+
.map { |r| r['id'] }
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_records(domain_name, ids = [])
|
69
|
+
id = get_id_by_domain(domain_name)
|
70
|
+
|
71
|
+
delete "/dns/managed/#{id}/records/", ids
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete_record(domain_name, record_id)
|
75
|
+
delete "/dns/managed/#{get_id_by_domain(domain_name)}/records/#{record_id}/"
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_record(domain_name, name, type, value, options = {})
|
79
|
+
body = {"name" => name, "type" => type, "value" => value, "ttl" => 3600, "gtdLocation" => "DEFAULT"}
|
80
|
+
post "/dns/managed/#{get_id_by_domain(domain_name)}/records/", body.merge(options)
|
81
|
+
end
|
82
|
+
|
83
|
+
def create_a_record(domain_name, name, value, options = {})
|
84
|
+
# todo: match IPv4 for value
|
85
|
+
create_record domain_name, name, "A", value, options
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_aaaa_record(domain_name, name, value, options = {})
|
89
|
+
# todo: match IPv6 for value
|
90
|
+
create_record domain_name, name, "AAAA", value, options
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_ptr_record(domain_name, name, value, options = {})
|
94
|
+
# todo: match PTR value
|
95
|
+
create_record domain_name, name, "PTR", value, options
|
96
|
+
end
|
97
|
+
|
98
|
+
def create_txt_record(domain_name, name, value, options = {})
|
99
|
+
# todo: match TXT value
|
100
|
+
create_record domain_name, name, "TXT", value, options
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_cname_record(domain_name, name, value, options = {})
|
104
|
+
# todo: match CNAME value
|
105
|
+
create_record domain_name, name, "CNAME", value, options
|
106
|
+
end
|
107
|
+
|
108
|
+
def create_ns_record(domain_name, name, value, options = {})
|
109
|
+
# todo: match domainname for value
|
110
|
+
create_record domain_name, name, "NS", value, options
|
111
|
+
end
|
112
|
+
|
113
|
+
def create_spf_record(domain_name, name, value, options = {})
|
114
|
+
create_record domain_name, name, "SPF", value, options
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_mx_record(domain_name, name, priority, value, options = {})
|
118
|
+
options.merge!({"mxLevel" => priority})
|
119
|
+
|
120
|
+
create_record domain_name, name, "MX", value, options
|
121
|
+
end
|
122
|
+
|
123
|
+
def create_srv_record(domain_name, name, priority, weight, port, value, options = {})
|
124
|
+
options.merge!({"priority" => priority, "weight" => weight, "port" => port})
|
125
|
+
create_record domain_name, name, "SRV", value, options
|
126
|
+
end
|
127
|
+
|
128
|
+
def create_httpred_record(domain_name, name, value, redirectType = "STANDARD - 302", description = "", keywords = "", title = "", options = {})
|
129
|
+
options.merge!({"redirectType" => redirectType, "description" => description, "keywords" => keywords, "title" => title})
|
130
|
+
create_record domain_name, name, "HTTPRED", value, options
|
131
|
+
end
|
132
|
+
|
133
|
+
def update_record(domain, record_id, name, type, value, options = {})
|
134
|
+
body = { "name" => name, "type" => type, "value" => value, "ttl" => 3600, "gtdLocation" => "DEFAULT", "id" => record_id}
|
135
|
+
put "/dns/managed/#{get_id_by_domain(domain)}/records/#{record_id}/", body.merge(options)
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def get(path)
|
141
|
+
request(path) do |uri|
|
142
|
+
Net::HTTP::Get.new(uri.path)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def delete(path, body = nil)
|
147
|
+
request(path) do |uri|
|
148
|
+
req = Net::HTTP::Delete.new(uri.path)
|
149
|
+
req.body = body.to_json if body
|
150
|
+
req
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def put(path, body = nil)
|
155
|
+
request(path) do |uri|
|
156
|
+
req = Net::HTTP::Put.new(uri.path)
|
157
|
+
req.body = body.to_json if body
|
158
|
+
req
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def post(path, body)
|
163
|
+
request(path) do |uri|
|
164
|
+
req = Net::HTTP::Post.new(uri.path)
|
165
|
+
req.body = body.to_json
|
166
|
+
req
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def request(path)
|
171
|
+
uri = URI("#{base_uri}#{path}")
|
172
|
+
|
173
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
174
|
+
http.use_ssl = true
|
175
|
+
|
176
|
+
request = yield(uri)
|
177
|
+
|
178
|
+
request_headers.each do |key, value|
|
179
|
+
request[key] = value
|
180
|
+
end
|
181
|
+
|
182
|
+
response = http.request(request)
|
183
|
+
|
184
|
+
JSON.parse(response.body)
|
185
|
+
end
|
186
|
+
|
187
|
+
def request_headers
|
188
|
+
request_date = Time.now.httpdate
|
189
|
+
hmac = OpenSSL::HMAC.hexdigest('sha1', @api_secret, request_date)
|
190
|
+
{
|
191
|
+
'Accept' => 'application/json',
|
192
|
+
'x-dnsme-apiKey' => @api_key,
|
193
|
+
'x-dnsme-requestDate' => request_date,
|
194
|
+
'x-dnsme-hmac' => hmac
|
195
|
+
}
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,248 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/dnsmadeeasy-rest-api'
|
3
|
+
|
4
|
+
describe DnsMadeEasy do
|
5
|
+
let(:api_key) { 'soooo secret' }
|
6
|
+
let(:secret_key) { 'soooo secret' }
|
7
|
+
let(:request_headers) do
|
8
|
+
{'Accept' => 'application/json',
|
9
|
+
'X-Dnsme-Apikey' => 'soooo secret',
|
10
|
+
'X-Dnsme-Hmac' => 'ff6e87e78ff909573362c9a38df13ccc5fa01846',
|
11
|
+
'X-Dnsme-Requestdate' => 'Wed, 21 May 2014 18:08:37 GMT'}
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { DnsMadeEasy.new(api_key, secret_key) }
|
15
|
+
|
16
|
+
before do
|
17
|
+
Time.stub(:now).and_return(Time.parse('Wed, 21 May 2014 18:08:37 GMT'))
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#get_id_by_domain' do
|
21
|
+
|
22
|
+
let(:response) do
|
23
|
+
"{\"name\":\"something.wanelo.com\",\"id\":1130967}"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the id of the domain' do
|
27
|
+
stub_request(:get, "https://api.dnsmadeeasy.com/V2.0/dns/managed/id/something.wanelo.com").
|
28
|
+
with(:headers => request_headers).
|
29
|
+
to_return(:status => 200, :body => response, :headers => {})
|
30
|
+
|
31
|
+
expect(subject.get_id_by_domain('something.wanelo.com')).to eq(1130967)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#domains' do
|
36
|
+
let(:response) { "{}" }
|
37
|
+
|
38
|
+
it 'returns all the domains' do
|
39
|
+
stub_request(:get, "https://api.dnsmadeeasy.com/V2.0/dns/managed/").
|
40
|
+
with(:headers => request_headers).
|
41
|
+
to_return(:status => 200, :body => response, :headers => {})
|
42
|
+
|
43
|
+
expect(subject.domains).to eq({})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#domain" do
|
48
|
+
let(:response) { "{}" }
|
49
|
+
|
50
|
+
before do
|
51
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the domain given a domain name" do
|
55
|
+
stub_request(:get, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123").
|
56
|
+
with(:headers => request_headers).
|
57
|
+
to_return(:status => 200, :body => response, :headers => {})
|
58
|
+
|
59
|
+
expect(subject.domain('something.wanelo.com')).to eq({})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#delete_domain' do
|
64
|
+
let(:response) { "{}" }
|
65
|
+
|
66
|
+
before do
|
67
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'deletes the domain' do
|
71
|
+
stub_request(:delete, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123").
|
72
|
+
with(:headers => request_headers).
|
73
|
+
to_return(:status => 200, :body => response, :headers => {})
|
74
|
+
|
75
|
+
expect(subject.delete_domain('something.wanelo.com')).to eq({})
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#create_domains' do
|
80
|
+
let(:response) { "{}" }
|
81
|
+
|
82
|
+
it 'creates the domains' do
|
83
|
+
stub_request(:post, "https://api.dnsmadeeasy.com/V2.0/dns/managed/").
|
84
|
+
with(:headers => request_headers, :body => '{"names":["something.wanelo.com"]}').
|
85
|
+
to_return(:status => 200, :body => response, :headers => {})
|
86
|
+
|
87
|
+
expect(subject.create_domains(['something.wanelo.com'])).to eq({})
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#create_domain' do
|
92
|
+
it 'calls create_domains with the one domain' do
|
93
|
+
expect(subject).to receive(:create_domains).with(['something.wanelo.com'])
|
94
|
+
subject.create_domain('something.wanelo.com')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#records_for' do
|
99
|
+
let(:response) { "{}" }
|
100
|
+
|
101
|
+
before do
|
102
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns all records for a given domain' do
|
106
|
+
stub_request(:get, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123/records").
|
107
|
+
with(:headers => request_headers).
|
108
|
+
to_return(:status => 200, :body => response, :headers => {})
|
109
|
+
|
110
|
+
expect(subject.records_for('something.wanelo.com')).to eq({})
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#find_record_id' do
|
115
|
+
let(:records_for_response) do
|
116
|
+
{
|
117
|
+
'data' => [
|
118
|
+
{ 'name' => 'demo', 'type' => 'A', 'id' => 123},
|
119
|
+
{ 'name' => 'demo', 'type' => 'A', 'id' => 143}
|
120
|
+
]
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
before do
|
125
|
+
subject.stub(:records_for).with('something.wanelo.com').and_return(records_for_response)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'finds the specified record given a name and a type' do
|
129
|
+
expect(subject.find_record_id('something.wanelo.com', 'demo', 'A')).to eq([123, 143])
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#delete_records' do
|
134
|
+
let(:response) { "{}" }
|
135
|
+
|
136
|
+
before do
|
137
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'deletes a list of records from a given domain' do
|
141
|
+
stub_request(:delete, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123/records/").
|
142
|
+
with(headers: request_headers, body: "[147,159]").
|
143
|
+
to_return(:status => 200, :body => response, :headers => {})
|
144
|
+
|
145
|
+
expect(subject.delete_records('something.wanelo.com', [147, 159])).to eq({})
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#delete_record' do
|
150
|
+
let(:response) { "{}" }
|
151
|
+
|
152
|
+
before do
|
153
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'deletes a record' do
|
157
|
+
stub_request(:delete, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123/records/42/").
|
158
|
+
with(headers: request_headers).
|
159
|
+
to_return(:status => 200, :body => response, :headers => {})
|
160
|
+
|
161
|
+
expect(subject.delete_record('something.wanelo.com', 42)).to eq({})
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#create_record' do
|
166
|
+
let(:response) { "{}" }
|
167
|
+
|
168
|
+
before do
|
169
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
170
|
+
end
|
171
|
+
|
172
|
+
let(:domain_name) { 'something.wanelo.com' }
|
173
|
+
let(:name) { 'test' }
|
174
|
+
|
175
|
+
it 'creates a record' do
|
176
|
+
stub_request(:post, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123/records/").
|
177
|
+
with(headers: request_headers, body: {"name" => 'test', "type" => 'A', "value" => '192.168.1.1', "ttl" => 3600, "gtdLocation" => "DEFAULT"}.to_json).
|
178
|
+
to_return(:status => 200, :body => response, :headers => {})
|
179
|
+
|
180
|
+
|
181
|
+
expect(subject.create_record(domain_name, 'test', 'A', '192.168.1.1')).to eq({})
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
["a", "aaaa", "ptr", "txt", "cname", "ns", "spf"].each do |record_type|
|
186
|
+
method_name = "create_#{record_type}_record"
|
187
|
+
describe "##{method_name}" do
|
188
|
+
upper_record_type = record_type.upcase
|
189
|
+
|
190
|
+
it "calls through to create record with \"#{upper_record_type}\"" do
|
191
|
+
expect(subject).to receive(:create_record).with('something.wanelo.com', 'smellyface', upper_record_type, '192.168.1.1', {}).and_return({})
|
192
|
+
expect(subject.send(method_name, 'something.wanelo.com', 'smellyface', '192.168.1.1')).to eq({})
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "#create_mx_record" do
|
198
|
+
it 'creates an mx record' do
|
199
|
+
expect(subject).to receive(:create_record).with('something.wanelo.com', 'mail', 'MX', '192.168.1.1', {'mxLevel' => 50}).and_return({})
|
200
|
+
expect(subject.create_mx_record('something.wanelo.com', 'mail', 50, '192.168.1.1')).to eq({})
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe "#create_srv_record" do
|
205
|
+
let(:weight) { '50' }
|
206
|
+
let(:priority) { '42' }
|
207
|
+
let(:port) { '4040' }
|
208
|
+
|
209
|
+
it 'creates an srv record' do
|
210
|
+
expect(subject).to receive(:create_record).with('something.wanelo.com', 'serv', 'SRV', '192.168.1.1', {"priority" => priority, "weight" => weight, "port" => port}).and_return({})
|
211
|
+
|
212
|
+
expect(subject.create_srv_record('something.wanelo.com', 'serv', priority, weight, port, '192.168.1.1')).to eq({})
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "#create_httpred_record" do
|
217
|
+
let(:description) { 'hunky dory redirect description' }
|
218
|
+
let(:keywords) { 'omg,keywords,redirect' }
|
219
|
+
let(:redirect_type) { 'STANDARD - 302' }
|
220
|
+
let(:title) { 'wat' }
|
221
|
+
|
222
|
+
it 'creates an srv record' do
|
223
|
+
expect(subject).to receive(:create_record).with('something.wanelo.com', 'redirect', 'HTTPRED', '192.168.1.1', {"redirectType" => redirect_type, "description" => description, "keywords" => keywords, "title" => title}).and_return({})
|
224
|
+
|
225
|
+
expect(subject.create_httpred_record('something.wanelo.com', 'redirect', '192.168.1.1', redirect_type, description, keywords, title)).to eq({})
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "#update_record" do
|
230
|
+
let(:response) { "{}" }
|
231
|
+
|
232
|
+
before do
|
233
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'updates a record' do
|
237
|
+
body = '{"name":"mail","type":"A","value":"1.1.1.1","ttl":3600,"gtdLocation":"DEFAULT","id":21}'
|
238
|
+
|
239
|
+
|
240
|
+
stub_request(:put, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123/records/21/").
|
241
|
+
with(headers: request_headers, body: body).
|
242
|
+
to_return(:status => 200, :body => response, :headers => {})
|
243
|
+
|
244
|
+
|
245
|
+
expect(subject.update_record('something.wanelo.com', 21, 'mail', 'A', '1.1.1.1', options = {})).to eq({})
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
|
5
|
+
config.filter_run :focus => true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
|
8
|
+
if config.files_to_run.one?
|
9
|
+
config.full_backtrace = true
|
10
|
+
config.formatter = 'doc' if config.formatters.none?
|
11
|
+
end
|
12
|
+
|
13
|
+
config.profile_examples = 10
|
14
|
+
|
15
|
+
config.order = :random
|
16
|
+
|
17
|
+
Kernel.srand config.seed
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dnsmadeeasy-rest-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Henry
|
8
|
+
- James Hart
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: webmock
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: DNS Made Easy V2.0 REST API client for Ruby, but better. With tests and
|
43
|
+
no dependencies.
|
44
|
+
email: ops@wanelo.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- dnsmadeeasy-rest-api.gemspec
|
55
|
+
- lib/dnsmadeeasy-rest-api.rb
|
56
|
+
- spec/lib/dnsmadeeasyapi-rest-api_spec.rb
|
57
|
+
- spec/spec_helper.rb
|
58
|
+
homepage: https://github.com/wanelo/dnsmadeeasy-rest-api
|
59
|
+
licenses:
|
60
|
+
- Apache
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: DNS Made Easy V2.0 REST API client for Ruby
|
82
|
+
test_files: []
|
83
|
+
has_rdoc:
|