glare 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7176b88b94cbb8eb1635f374010d3781c9abcb92
4
- data.tar.gz: 23dfafaf1b6c0fd137615c3bf6671a43f9c28ec9
3
+ metadata.gz: 1375fe0ef33d737b01e0dece0f214b7fa235a8c6
4
+ data.tar.gz: d24dd0a4e9a7b2d6862fc111e835512390487c16
5
5
  SHA512:
6
- metadata.gz: b48e09275b67e1246760bec68ec00a55e0ee59034bc6a09501e814c792ee532321170a3fdbda25d16c41c139f0802c1d6e537fe20fdf85259f63a1549fcdc5b7
7
- data.tar.gz: 93b4c521285065f59d378dd0cc6713ba65ed3b724895097975a464b51b83c2e35aa5448a11d1f748f36500daff52c8e7161a9075837e29bb4356c185aa761bbc
6
+ metadata.gz: fa4b548a630e1166cb668829da854571655042ada1636edb7d874b712a8c22a4e8ad0df61054ba99cad206176cc5b031d1f48554467271154165cdf56528d7a4
7
+ data.tar.gz: 406d2c08de74f586c3007c50cc6fbea13738ca585cd5dbfaee7cce5ef22e91504c21bc25eedc2174d3a87f45500de549575a4e770355152bf1a184a324a97447
@@ -1,3 +1,5 @@
1
+ require 'glare/errors'
2
+
1
3
  module Glare
2
4
  class ApiResponse
3
5
  def initialize(response)
@@ -9,7 +11,7 @@ module Glare
9
11
  end
10
12
 
11
13
  def valid!
12
- raise Glare::Errors::ApiError unless success?
14
+ raise Glare::Errors::ApiError.new(errors) unless success?
13
15
  self
14
16
  end
15
17
 
@@ -22,5 +24,9 @@ module Glare
22
24
  def content
23
25
  @response.content
24
26
  end
27
+
28
+ def errors
29
+ content['errors'].map { |e| e['message'] }.join(',')
30
+ end
25
31
  end
26
32
  end
data/lib/glare/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Glare
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
@@ -0,0 +1,17 @@
1
+ {
2
+ "errors": [
3
+ {
4
+ "code": 1004,
5
+ "error_chain": [
6
+ {
7
+ "code": 9007,
8
+ "message": "Content for CNAME record is invalid"
9
+ }
10
+ ],
11
+ "message": "DNS Validation Error"
12
+ }
13
+ ],
14
+ "messages": [],
15
+ "result": null,
16
+ "success": false
17
+ }
data/spec/spec_helper.rb CHANGED
@@ -95,3 +95,9 @@ 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
@@ -0,0 +1,30 @@
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
@@ -220,10 +220,4 @@ 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
229
223
  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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Luis Salas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-28 00:00:00.000000000 Z
12
+ date: 2016-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -109,10 +109,12 @@ files:
109
109
  - lib/glare/version.rb
110
110
  - spec/delete_domain_spec.rb
111
111
  - spec/fixtures/empty_result.json
112
+ - spec/fixtures/error_response.json
112
113
  - spec/fixtures/list_zone.json
113
114
  - spec/fixtures/wadus_records.json
114
115
  - spec/resolve_domain_spec.rb
115
116
  - spec/spec_helper.rb
117
+ - spec/units/api_response_spec.rb
116
118
  - spec/units/glare_spec.rb
117
119
  homepage: https://github.com/peertransfer/glare
118
120
  licenses:
@@ -139,6 +141,7 @@ signing_key:
139
141
  specification_version: 4
140
142
  summary: API client for CloudFlare v4 API
141
143
  test_files:
144
+ - spec/units/api_response_spec.rb
142
145
  - spec/units/glare_spec.rb
143
146
  - spec/delete_domain_spec.rb
144
147
  - spec/resolve_domain_spec.rb
@@ -146,3 +149,4 @@ test_files:
146
149
  - spec/fixtures/wadus_records.json
147
150
  - spec/fixtures/empty_result.json
148
151
  - spec/fixtures/list_zone.json
152
+ - spec/fixtures/error_response.json