dnsmadeeasy-rest-api 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -1
- data/dnsmadeeasy-rest-api.gemspec +1 -1
- data/lib/dnsmadeeasy-rest-api.rb +25 -1
- data/spec/lib/dnsmadeeasyapi-rest-api_spec.rb +40 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94e04a4f64f815ebff828a7e5eb958d59d7f4268
|
4
|
+
data.tar.gz: 82bfa9aadda0ce4510a77b81bf07828989171c3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2074ec07e346e42e1bb0e0fc11f56486871923faf6882b7411effdbe283d8bbcd6a6b47d23d183de92660011589cf915db059953a024488debec774d8a7a713
|
7
|
+
data.tar.gz: 35af1954a5ba238dd2ae56cbb57cd2e658585283223d15f130801f48cac8577870eb9f4b82da9c78f54f7f6d0f1493e81e2f5a1cfe9a28255bcf4897fbfe9467
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ api = DnsMadeEasy.new('awesome-api-key', 'super-secret-and-awesome-api-secret')
|
|
31
31
|
|
32
32
|
All return values are the direct JSON responses from DNS Made Easy converted into a Hash.
|
33
33
|
|
34
|
-
See: [http://www.dnsmadeeasy.com/
|
34
|
+
See: [http://www.dnsmadeeasy.com/integration/pdf/API-Docv2.pdf](http://www.dnsmadeeasy.com/integration/pdf/API-Docv2.pdf)
|
35
35
|
|
36
36
|
### Managing Domains
|
37
37
|
|
@@ -134,6 +134,26 @@ To update a record:
|
|
134
134
|
api.update_record('hello.example.com', 123, 'woah', 'A', '127.0.1.1', { 'ttl' => '60' })
|
135
135
|
```
|
136
136
|
|
137
|
+
To update several records:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
api.update_records('hello.example.com', [{'id'=>123, 'name'=>'buddy', 'type'=>'A','value'=>'127.0.0.1'}], { 'ttl' => '60' })
|
141
|
+
```
|
142
|
+
|
143
|
+
To get the number of API requests remaining after a call:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
api.requests_remaining
|
147
|
+
```
|
148
|
+
>Information is not available until an API call has been made
|
149
|
+
|
150
|
+
|
151
|
+
To get the API request total limit after a call:
|
152
|
+
```ruby
|
153
|
+
api.request_limit
|
154
|
+
```
|
155
|
+
>Information is not available until an API call has been made
|
156
|
+
|
137
157
|
## Contributing
|
138
158
|
|
139
159
|
1. Fork it
|
data/lib/dnsmadeeasy-rest-api.rb
CHANGED
@@ -7,6 +7,8 @@ require 'net/http'
|
|
7
7
|
# A class to interact with the DNSMadeEasy REST API v2.0
|
8
8
|
class DnsMadeEasy
|
9
9
|
attr_accessor :base_uri
|
10
|
+
attr_reader :requests_remaining
|
11
|
+
attr_reader :request_limit
|
10
12
|
|
11
13
|
def initialize(api_key, api_secret, sandbox = false, options = {})
|
12
14
|
fail 'api_key is undefined' unless api_key
|
@@ -15,9 +17,11 @@ class DnsMadeEasy
|
|
15
17
|
@api_key = api_key
|
16
18
|
@api_secret = api_secret
|
17
19
|
@options = options
|
20
|
+
@requests_remaining = -1
|
21
|
+
@request_limit = -1
|
18
22
|
|
19
23
|
if sandbox
|
20
|
-
self.base_uri = 'https://
|
24
|
+
self.base_uri = 'https://sandboxapi.dnsmadeeasy.com/V2.0'
|
21
25
|
else
|
22
26
|
self.base_uri = 'https://api.dnsmadeeasy.com/V2.0'
|
23
27
|
end
|
@@ -146,6 +150,20 @@ class DnsMadeEasy
|
|
146
150
|
put "/dns/managed/#{get_id_by_domain(domain)}/records/#{record_id}/", body.merge(options)
|
147
151
|
end
|
148
152
|
|
153
|
+
def update_records(domain, records, options = {})
|
154
|
+
body = records.map do |record|
|
155
|
+
{
|
156
|
+
'id' => record['id'],
|
157
|
+
'name' => record['name'],
|
158
|
+
'type' => record['type'],
|
159
|
+
'value' => record['value'],
|
160
|
+
'gtdLocation' => record['gtdLocation'],
|
161
|
+
'ttl' => record['ttl']
|
162
|
+
}.merge(options)
|
163
|
+
end
|
164
|
+
put "/dns/managed/#{get_id_by_domain(domain)}/records/updateMulti/", body
|
165
|
+
end
|
166
|
+
|
149
167
|
private
|
150
168
|
|
151
169
|
def get(path)
|
@@ -183,6 +201,7 @@ class DnsMadeEasy
|
|
183
201
|
|
184
202
|
http = Net::HTTP.new(uri.host, uri.port)
|
185
203
|
http.use_ssl = true
|
204
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @options.key?(:ssl_verify_none)
|
186
205
|
http.open_timeout = @options[:open_timeout] if @options.key?(:open_timeout)
|
187
206
|
http.read_timeout = @options[:read_timeout] if @options.key?(:read_timeout)
|
188
207
|
|
@@ -195,6 +214,11 @@ class DnsMadeEasy
|
|
195
214
|
response = http.request(request)
|
196
215
|
response.value # raise Net::HTTPServerException unless response was 2xx
|
197
216
|
|
217
|
+
response.each_header do |header, value|
|
218
|
+
@requests_remaining = value.to_i if header == 'x-dnsme-requestsremaining'
|
219
|
+
@request_limit = value.to_i if header == 'x-dnsme-requestlimit'
|
220
|
+
end
|
221
|
+
|
198
222
|
unparsed_json = response.body.to_s.empty? ? '{}' : response.body
|
199
223
|
|
200
224
|
JSON.parse(unparsed_json)
|
@@ -14,7 +14,7 @@ describe DnsMadeEasy do
|
|
14
14
|
subject { DnsMadeEasy.new(api_key, secret_key) }
|
15
15
|
|
16
16
|
before do
|
17
|
-
Time.
|
17
|
+
allow(Time).to receive(:now).and_return(Time.parse('Wed, 21 May 2014 18:08:37 GMT'))
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#get_id_by_domain' do
|
@@ -295,6 +295,45 @@ describe DnsMadeEasy do
|
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
|
+
describe '#update_records' do
|
299
|
+
let(:response) { '{}' }
|
300
|
+
|
301
|
+
before do
|
302
|
+
subject.stub(:get_id_by_domain).with('something.wanelo.com').and_return(123)
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'updates a record' do
|
306
|
+
records = [
|
307
|
+
{
|
308
|
+
'id' => 21,
|
309
|
+
'name' => 'mail',
|
310
|
+
'type' => 'A',
|
311
|
+
'value' => '1.1.1.1',
|
312
|
+
'gtdLocation' => 'DEFAULT',
|
313
|
+
'ttl' => 300
|
314
|
+
},
|
315
|
+
{
|
316
|
+
'id' => 22,
|
317
|
+
'name' => 'post',
|
318
|
+
'type' => 'A',
|
319
|
+
'value' => '1.1.1.2',
|
320
|
+
'gtdLocation' => 'DEFAULT',
|
321
|
+
'ttl' => 300
|
322
|
+
}
|
323
|
+
]
|
324
|
+
|
325
|
+
body = '[{"id":21,"name":"mail","type":"A","value":"1.1.1.1","gtdLocation":"DEFAULT","ttl":3600},{"id":22,"name":"post","type":"A","value":"1.1.1.2","gtdLocation":"DEFAULT","ttl":3600}]'
|
326
|
+
|
327
|
+
|
328
|
+
stub_request(:put, "https://api.dnsmadeeasy.com/V2.0/dns/managed/123/records/updateMulti/").
|
329
|
+
with(headers: request_headers, body: body).
|
330
|
+
to_return(status: 200, body: response, headers: {})
|
331
|
+
|
332
|
+
|
333
|
+
expect(subject.update_records('something.wanelo.com', records, { 'ttl' => 3600 })).to eq({})
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
298
337
|
describe "#request" do
|
299
338
|
before do
|
300
339
|
stub_request(:get, "https://api.dnsmadeeasy.com/V2.0/some_path").
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnsmadeeasy-rest-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnoud Vermeer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.5.2
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: DNS Made Easy V2.0 REST API client for Ruby
|