glare 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/lib/glare.rb +0 -1
- data/lib/glare/api_response.rb +1 -15
- data/lib/glare/cf_dns_records.rb +6 -12
- data/lib/glare/client.rb +4 -5
- data/lib/glare/domain/cf_zones.rb +4 -5
- data/lib/glare/domain/record.rb +4 -4
- data/lib/glare/domain/zone.rb +1 -1
- data/lib/glare/version.rb +1 -1
- data/spec/resolve_domain_spec.rb +3 -16
- data/spec/spec_helper.rb +0 -6
- data/spec/units/glare_spec.rb +9 -3
- metadata +1 -6
- data/lib/glare/errors.rb +0 -6
- data/spec/fixtures/error_response.json +0 -17
- data/spec/units/api_response_spec.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8578b25f97445a55d9f6c54dbdf8c5dc261fac5
|
4
|
+
data.tar.gz: eac8475ba924ae0aaaefccfa4cd356fe654be477
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 915652c5f9414bc54ecd1ed031973c3c8466bbf5412f1806a312171057f4e1e3c22ab4c4ce2fdee48bcaa4e42fd40d432f611c760d9274bf27970069ee36f378
|
7
|
+
data.tar.gz: 322574e10153826cf4442a4f8946986439ddc1ac2c4b2d888f35452255c49f4147c24457b69e3b29d30949aee1943b519e9fa82be69220219859bda523c8f8e2
|
data/.gitignore
CHANGED
data/lib/glare.rb
CHANGED
data/lib/glare/api_response.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'glare/errors'
|
2
|
-
|
3
1
|
module Glare
|
4
2
|
class ApiResponse
|
5
3
|
def initialize(response)
|
@@ -10,23 +8,11 @@ module Glare
|
|
10
8
|
content['result']
|
11
9
|
end
|
12
10
|
|
13
|
-
def valid!
|
14
|
-
raise Glare::Errors::ApiError.new(errors) unless success?
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
11
|
private
|
19
12
|
|
20
|
-
def success?
|
21
|
-
content['success']
|
22
|
-
end
|
23
|
-
|
24
13
|
def content
|
25
14
|
@response.content
|
26
15
|
end
|
27
|
-
|
28
|
-
def errors
|
29
|
-
content['errors'].map { |e| e['message'] }.join(',')
|
30
|
-
end
|
31
16
|
end
|
17
|
+
private_constant :ApiResponse
|
32
18
|
end
|
data/lib/glare/cf_dns_records.rb
CHANGED
@@ -11,8 +11,9 @@ module Glare
|
|
11
11
|
|
12
12
|
class CfDnsRecords
|
13
13
|
class << self
|
14
|
-
def from_result(
|
15
|
-
|
14
|
+
def from_result(api_result)
|
15
|
+
response = ApiResponse.new(api_result)
|
16
|
+
result = response.result
|
16
17
|
|
17
18
|
records = result.map do |item|
|
18
19
|
CfDnsRecord.new(
|
@@ -36,16 +37,9 @@ module Glare
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def to_update(desired_records)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def -(records)
|
44
|
-
@records.reject { |record| records.any? { |r| r.content == record.content } }
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_a
|
48
|
-
@records.dup
|
40
|
+
@records.reject do |record|
|
41
|
+
desired_records.any? { |r| r.content == record.content }
|
42
|
+
end
|
49
43
|
end
|
50
44
|
|
51
45
|
def count
|
data/lib/glare/client.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'jsonclient'
|
2
|
-
require 'glare/api_response'
|
3
2
|
|
4
3
|
module Glare
|
5
4
|
class Client
|
@@ -15,19 +14,19 @@ module Glare
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def get(query, params)
|
18
|
-
|
17
|
+
@http.get(BASE_URL + query, params, @headers)
|
19
18
|
end
|
20
19
|
|
21
20
|
def post(query, data)
|
22
|
-
|
21
|
+
@http.post(BASE_URL + query, data, @headers)
|
23
22
|
end
|
24
23
|
|
25
24
|
def put(query, data)
|
26
|
-
|
25
|
+
@http.put(BASE_URL + query, data, @headers)
|
27
26
|
end
|
28
27
|
|
29
28
|
def delete(query, params=nil)
|
30
|
-
|
29
|
+
@http.delete(BASE_URL + query, params, @headers)
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'glare/domain/cf_zones'
|
2
|
-
require 'glare/errors'
|
3
2
|
|
4
3
|
module Glare
|
5
4
|
class Domain
|
6
5
|
class CfZones
|
7
6
|
def self.from_result(api_response)
|
8
|
-
|
7
|
+
response = ApiResponse.new(api_response)
|
8
|
+
result = response.result
|
9
9
|
|
10
10
|
zones = result.map do |item|
|
11
11
|
CfZone.new(
|
@@ -21,9 +21,8 @@ module Glare
|
|
21
21
|
@zones = zones
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
26
|
-
@zones.first.id
|
24
|
+
def first
|
25
|
+
@zones.first
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
data/lib/glare/domain/record.rb
CHANGED
@@ -26,14 +26,14 @@ module Glare
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def update(zone_id, dns_records, existing_records)
|
29
|
-
delete_uneeded_records(zone_id, dns_records, existing_records)
|
30
29
|
update_current_records(zone_id, dns_records, existing_records)
|
30
|
+
delete_uneeded_records(zone_id, dns_records, existing_records)
|
31
31
|
create_new_records(zone_id, dns_records, existing_records)
|
32
32
|
end
|
33
33
|
|
34
|
-
def update_current_records(zone_id,
|
35
|
-
records_to_update = existing_records.to_update(
|
36
|
-
updates = records_to_update.zip(
|
34
|
+
def update_current_records(zone_id, dns_records, existing_records)
|
35
|
+
records_to_update = existing_records.to_update(dns_records)
|
36
|
+
updates = records_to_update.zip(dns_records)
|
37
37
|
updates.each do |existing_record, dns_record|
|
38
38
|
@client.put("/zones/#{zone_id}/dns_records/#{existing_record.id}", dns_record.to_h)
|
39
39
|
end
|
data/lib/glare/domain/zone.rb
CHANGED
data/lib/glare/version.rb
CHANGED
data/spec/resolve_domain_spec.rb
CHANGED
@@ -5,25 +5,12 @@ RSpec.describe 'Resolve domain' do
|
|
5
5
|
let(:domain) { 'cname.flywire.cc' }
|
6
6
|
let(:destination) { ['peertransfer.me'] }
|
7
7
|
let(:type) { 'CNAME' }
|
8
|
-
|
9
|
-
it 'resolves to right destination' do
|
10
|
-
register_domain(domain, destination)
|
11
|
-
|
12
|
-
expect(resolve(domain)).to eq(destination)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'raises an exception if domain does not exist in account' do
|
8
|
+
before do
|
16
9
|
register_domain(domain, destination)
|
17
|
-
|
18
|
-
expect do
|
19
|
-
resolve('error.ojete.cc')
|
20
|
-
end.to raise_error(Glare::Errors::NotExistingZoneError)
|
21
10
|
end
|
22
11
|
|
23
|
-
it '
|
24
|
-
expect
|
25
|
-
register_domain('error.flywire.cc', '1.1.1.1')
|
26
|
-
end.to raise_error(Glare::Errors::ApiError)
|
12
|
+
it 'resolves to right destination' do
|
13
|
+
expect(resolve(domain)).to eq(destination)
|
27
14
|
end
|
28
15
|
end
|
29
16
|
|
data/spec/spec_helper.rb
CHANGED
@@ -95,9 +95,3 @@ RSpec.configure do |config|
|
|
95
95
|
# as the one that triggered the failure.
|
96
96
|
Kernel.srand config.seed
|
97
97
|
end
|
98
|
-
|
99
|
-
def load_fixture(fixture)
|
100
|
-
fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
101
|
-
json = IO.read(File.join(fixture_dir, "#{fixture}.json"))
|
102
|
-
::HTTP::Message.new_response(JSON.parse(json))
|
103
|
-
end
|
data/spec/units/glare_spec.rb
CHANGED
@@ -8,9 +8,9 @@ RSpec.describe Glare do
|
|
8
8
|
allow(Glare::Client).to receive(:new).and_return(client)
|
9
9
|
end
|
10
10
|
let(:client) { spy(Glare::Client) }
|
11
|
-
let(:zone_list) {
|
12
|
-
let(:empty_result) {
|
13
|
-
let(:wadus_records) {
|
11
|
+
let(:zone_list) { load_fixture('list_zone') }
|
12
|
+
let(:empty_result) { load_fixture('empty_result') }
|
13
|
+
let(:wadus_records) { load_fixture('wadus_records') }
|
14
14
|
|
15
15
|
describe '.resolve' do
|
16
16
|
it 'resolves a fqdn' do
|
@@ -220,4 +220,10 @@ RSpec.describe Glare do
|
|
220
220
|
)
|
221
221
|
end
|
222
222
|
end
|
223
|
+
|
224
|
+
def load_fixture(fixture)
|
225
|
+
fixture_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
|
226
|
+
json = IO.read(File.join(fixture_dir, "#{fixture}.json"))
|
227
|
+
::HTTP::Message.new_response(JSON.parse(json))
|
228
|
+
end
|
223
229
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Luis Salas
|
@@ -105,16 +105,13 @@ files:
|
|
105
105
|
- lib/glare/domain/cf_zones.rb
|
106
106
|
- lib/glare/domain/record.rb
|
107
107
|
- lib/glare/domain/zone.rb
|
108
|
-
- lib/glare/errors.rb
|
109
108
|
- lib/glare/version.rb
|
110
109
|
- spec/delete_domain_spec.rb
|
111
110
|
- spec/fixtures/empty_result.json
|
112
|
-
- spec/fixtures/error_response.json
|
113
111
|
- spec/fixtures/list_zone.json
|
114
112
|
- spec/fixtures/wadus_records.json
|
115
113
|
- spec/resolve_domain_spec.rb
|
116
114
|
- spec/spec_helper.rb
|
117
|
-
- spec/units/api_response_spec.rb
|
118
115
|
- spec/units/glare_spec.rb
|
119
116
|
homepage: https://github.com/peertransfer/glare
|
120
117
|
licenses:
|
@@ -141,7 +138,6 @@ signing_key:
|
|
141
138
|
specification_version: 4
|
142
139
|
summary: API client for CloudFlare v4 API
|
143
140
|
test_files:
|
144
|
-
- spec/units/api_response_spec.rb
|
145
141
|
- spec/units/glare_spec.rb
|
146
142
|
- spec/delete_domain_spec.rb
|
147
143
|
- spec/resolve_domain_spec.rb
|
@@ -149,4 +145,3 @@ test_files:
|
|
149
145
|
- spec/fixtures/wadus_records.json
|
150
146
|
- spec/fixtures/empty_result.json
|
151
147
|
- spec/fixtures/list_zone.json
|
152
|
-
- spec/fixtures/error_response.json
|
data/lib/glare/errors.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'glare/api_response'
|
2
|
-
require 'httpclient/http'
|
3
|
-
|
4
|
-
RSpec.describe Glare::ApiResponse do
|
5
|
-
let(:error_response) { load_fixture('error_response') }
|
6
|
-
let(:empty_response) { load_fixture('empty_result') }
|
7
|
-
|
8
|
-
context 'when api returns success response' do
|
9
|
-
it 'returns api reponse' do
|
10
|
-
expect do
|
11
|
-
Glare::ApiResponse.new(empty_response).valid!
|
12
|
-
end.not_to raise_error
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when api returns error response' do
|
17
|
-
it 'raises an exception if api result is not success' do
|
18
|
-
expect do
|
19
|
-
Glare::ApiResponse.new(error_response).valid!
|
20
|
-
end.to raise_error(Glare::Errors::ApiError)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'shows error messages' do
|
24
|
-
expect do
|
25
|
-
Glare::ApiResponse.new(error_response).valid!
|
26
|
-
end.to raise_error(Glare::Errors::ApiError).
|
27
|
-
with_message('DNS Validation Error')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|