dnsimpler 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YWJkZDc5MTk3NDc5ZTg5MjZiYmYzZjNjZmJkOWRiOGJjNDMzMzE0Ng==
4
+ Yzk3MzdmOGUxNTk4NWIxMmEzY2E5NzcyOTYyMGU0ZGNlOGZmNjQ2YQ==
5
5
  data.tar.gz: !binary |-
6
- Y2FmNmIxMTEzYTc1NjY4ZmExM2EyMjc2ZTQ2ODJlMjI1ZDU5YTNhMQ==
6
+ Y2Q1NDFiMDUyMzBmOWRjOGNhYTJiNzI2Y2E5OGMzNTUzY2U1MmQ1Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmY5YzExMDQyZmI5NDZkN2U2NDU1ODBkYjFiNTMyMzc3NzFlNDFlNzZlYjM1
10
- NmE4MDBlMmJjYzQyNmExYTNhOGRkYzkzZWY1YzlkNjhhZTI3YjZmMWJmZWQ2
11
- ODVjODUzZjlmNDM5YWYzOTZjMTU5Nzk0NmRjNGEzZWRmZjBiNjQ=
9
+ Njc4OTUxNTIwMjBkNTAzYzVkZjU1ZTA0NWM0N2ZmOTYxMWYxNGI1ZTMzYTQy
10
+ Y2JjM2JjOGNjMGM0ZDBmMDkzMGQzMGVkZGZlOTk5NTdiZDVmYmUzMzEyYjUw
11
+ YTgxNDJkOTA1YTM5Zjc4ZmMyNmU1ZjUxY2E3OTM1NzkzNGQwM2M=
12
12
  data.tar.gz: !binary |-
13
- NDVhOWVjMjk3OGQ1ZWY3NDdmM2NjZTBkZGRkZmYxZTJjMjllNzM1YjQyOTBl
14
- YzBlOGI0MGJjOGY2N2ZmOTVlZDVkZWEyYmQ2NjFhNTI1MGNlZTVmM2IzNGVj
15
- OTNhM2ZiMjNhYTE2MmE1YWMyNDU1ZmY0NDY5ZWEyYTE2YzE1ZmU=
13
+ MGI4YjcwN2Q3NGU1MTYyNjAwZjU2YWFjNGFhNTg4ZTVmOTdkMGRmMDI3NWNk
14
+ YjYzZmQxZWEwNzUyMzRlMjhlZjNjYjQyMTBjOTgxY2Y3MjY1MmIzNjZhNTdi
15
+ NzQ2NzJjYTIxNzVjOTY0ODFlYzFkYzdjZTNhM2RhODU3N2VjMDc=
@@ -0,0 +1,12 @@
1
+ module DNSimpler
2
+ class Error < StandardError
3
+ attr_reader :code, :body, :response
4
+
5
+ def initialize(code, body, response)
6
+ @code = code
7
+ @body = body
8
+ @response = response
9
+ end
10
+
11
+ end
12
+ end
@@ -37,15 +37,19 @@ module DNSimpler
37
37
 
38
38
  req = super path, opts, &blk
39
39
 
40
- response = OpenStruct.new(code: req.code, body: req.parsed_response)
40
+ if (200...400).include? req.code
41
+ response = OpenStruct.new(code: req.code, body: req.parsed_response)
41
42
 
42
- if DNSimpler.debug
43
- response.request = req
43
+ if DNSimpler.debug
44
+ response.request = req
44
45
 
45
- puts "Request Options: " + opts.to_s
46
- end
46
+ puts "Request Options: " + opts.to_s
47
+ end
47
48
 
48
- return response
49
+ return response
50
+ else
51
+ raise Error.new(req.code, req.parsed_response, req)
52
+ end
49
53
  end
50
54
 
51
55
  RUBY_EVAL
data/lib/dnsimpler/try.rb CHANGED
@@ -2,7 +2,7 @@ unless Hash.instance_methods.include? :try
2
2
  class Hash
3
3
 
4
4
  def try(key)
5
- return send("[]", key)
5
+ return self[key]
6
6
  end
7
7
 
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module DNSimpler
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/dnsimpler.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ostruct'
2
2
  require "dnsimpler/version"
3
3
  require 'dnsimpler/http'
4
+ require 'dnsimpler/error'
4
5
  require 'dnsimpler/try'
5
6
 
6
7
  module DNSimpler
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class DNSimpler::ErrorTest < MiniTest::Test
4
+
5
+ test "initialize" do
6
+ assert_raises DNSimpler::Error do
7
+ raise DNSimpler::Error.new(200, {body: 'blah'}, nil)
8
+ end
9
+ end
10
+
11
+ %w[code body response].each do |attr|
12
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__
13
+
14
+ test "##{attr}" do
15
+ error = DNSimpler::Error.new(200, {body: 'blah'}, true)
16
+ refute_nil error.#{attr}
17
+ end
18
+
19
+ RUBY_EVAL
20
+ end
21
+
22
+ end
@@ -3,10 +3,23 @@ require 'test_helper'
3
3
  module DNSimpler
4
4
  class HTTPTest < MiniTest::Test
5
5
 
6
+ def setup
7
+ super
8
+ stub_request(:get, "#{DNSimpler.base_uri}v1/domains/example.com").to_return(status: 404, body: {"message"=>"Domain `example.com' not found"}.to_json)
9
+ end
10
+
6
11
  test "#base_options" do
7
12
  assert_instance_of Hash, HTTP.base_options
8
13
  end
9
14
 
15
+ test "an error is raised for a failed request" do
16
+ error = assert_raises ::DNSimpler::Error do
17
+ HTTP.get("v1/domains/example.com")
18
+ end
19
+
20
+ refute (200...400).include? error.code
21
+ end
22
+
10
23
  %w[get post head delete patch put].each do |method|
11
24
  class_eval <<-RUBY_EVAL
12
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnsimpler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Westendorf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-07 00:00:00.000000000 Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -83,9 +83,11 @@ files:
83
83
  - Rakefile
84
84
  - dnsimpler.gemspec
85
85
  - lib/dnsimpler.rb
86
+ - lib/dnsimpler/error.rb
86
87
  - lib/dnsimpler/http.rb
87
88
  - lib/dnsimpler/try.rb
88
89
  - lib/dnsimpler/version.rb
90
+ - test/dnsimpler/error_test.rb
89
91
  - test/dnsimpler/http_test.rb
90
92
  - test/dnsimpler/try_test.rb
91
93
  - test/dnsimpler_test.rb
@@ -116,6 +118,7 @@ specification_version: 4
116
118
  summary: A simple DNSimple API wrapper that always provides the response you're looking
117
119
  for.
118
120
  test_files:
121
+ - test/dnsimpler/error_test.rb
119
122
  - test/dnsimpler/http_test.rb
120
123
  - test/dnsimpler/try_test.rb
121
124
  - test/dnsimpler_test.rb