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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3987a44ee6657d03fe2746d75007b772672c1899
4
- data.tar.gz: 9b94abad19f6ebc718369b1be6ac7aabf68e738b
3
+ metadata.gz: 94e04a4f64f815ebff828a7e5eb958d59d7f4268
4
+ data.tar.gz: 82bfa9aadda0ce4510a77b81bf07828989171c3a
5
5
  SHA512:
6
- metadata.gz: 17ba812ec3bad74eacfbd157a8b8b8697b1b2d7ebf60379d8141a6b51d1bbf240440788daf2c344196ed64c6fe9d461943231f69178f1bb502427f722a80d8b4
7
- data.tar.gz: 6f2873e2ad365e6a0f3125f053762887019834fea444d0db5e1f78178f510ca39bf1e6ff79ca79897f974e7c96e7e36f86a07fa729517bed8120e8e99b046d3a
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/wp-content/themes/appdev/pdf/API-Documentationv2.pdf](http://www.dnsmadeeasy.com/wp-content/themes/appdev/pdf/API-Documentationv2.pdf)
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dnsmadeeasy-rest-api'
3
- s.version = '1.0.4'
3
+ s.version = '1.0.5'
4
4
  s.authors = ['Arnoud Vermeer', 'Paul Henry', 'James Hart']
5
5
  s.email = ['a.vermeer@freshway.biz', 'ops@wanelo.com']
6
6
  s.license = 'Apache'
@@ -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://api.sandbox.dnsmadeeasy.com/V2.0'
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.stub(:now).and_return(Time.parse('Wed, 21 May 2014 18:08:37 GMT'))
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
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: 2016-06-28 00:00:00.000000000 Z
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.4.5.1
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