dnsimple 8.0.0 → 8.1.0

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
  SHA256:
3
- metadata.gz: 54546cd64cb573f075ed2538cebd73573708a1f9919364b4b963a082b1dc97bf
4
- data.tar.gz: 9e86592b7ff194316f5466d2b0a4cf0f988df1e90973bc29cfc30a4b7e2bccd8
3
+ metadata.gz: 926c26b50cdc2958b19e86a45cd6eb0394f5d884bcc12e45e8fda88b194c8fac
4
+ data.tar.gz: 930e5d25b213d496faa3268b3af1a0a1a407e0b632ad9a4a7f16fc8cb2a72256
5
5
  SHA512:
6
- metadata.gz: 997ac7555b02778d5bb10c03aa97640a5a2b3e2a55064785657774da5032a8b11cf009b0de1d47dc4864c5835ea1426bc46bed082119d7aae1c87dc5058d44ed
7
- data.tar.gz: 7fee63c8c4f9ae899023989de18fc920b45bd5405b2075040ef167f1b7f82e0b8ddf7b6364dd23f42ac9f6ff5a53a900493af42eb489f7fa0f6acc17be74fd3b
6
+ metadata.gz: 94cb5d1a3c141069d239d26a95e097b016b008acca7dcb2c14ff7040ed325a896e0ceaea4139344e22de6fb72360c7709df016de5aba668eab5b9afba17db8fc
7
+ data.tar.gz: 0c975b2a65075d1df91923e26d1604600d6fa595634fd3b1ec85aa31fedef28627774340cca6b2d63b09bae96731d4895745a4a040943a835cab4387cb94acb4
data/.gitignore CHANGED
@@ -1,3 +1,6 @@
1
+ # ASDF
2
+ .tool-versions
3
+
1
4
  # Bundler
2
5
  .bundle
3
6
  pkg/*
@@ -7,6 +10,3 @@ Gemfile.lock
7
10
  .yardoc
8
11
  yardoc/
9
12
  doc/
10
-
11
- #ASDF
12
- .tool-versions
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-08-09 14:54:31 UTC using RuboCop version 1.34.1.
3
+ # on 2022-09-01 12:27:48 UTC using RuboCop version 1.36.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 71
9
+ # Offense count: 70
10
10
  # Configuration parameters: CountAsOne.
11
11
  RSpec/ExampleLength:
12
12
  Max: 17
@@ -22,11 +22,11 @@ RSpec/LeakyConstantDeclaration:
22
22
  RSpec/MessageSpies:
23
23
  EnforcedStyle: receive
24
24
 
25
- # Offense count: 112
25
+ # Offense count: 111
26
26
  RSpec/MultipleExpectations:
27
27
  Max: 15
28
28
 
29
- # Offense count: 375
29
+ # Offense count: 371
30
30
  # Configuration parameters: IgnoreSharedExamples.
31
31
  RSpec/NamedSubject:
32
32
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/).
4
4
 
5
5
  ## main
6
6
 
7
+ ## 8.1.0
8
+
9
+ - CHANGED: Fixed and updated documentation for domain endpoints (dnsimple/dnsimple-ruby#300)
10
+ - CHANGED: Expose all information available in error responses (dnsimple/dnsimple-ruby#298)
11
+
7
12
  ## 8.0.0
8
13
 
9
14
  - CHANGED: Minimum Ruby version is now 2.7
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  gem 'coveralls', require: false
8
- gem 'rubocop', '1.34.1', require: false
9
- gem 'rubocop-performance', require: false
10
- gem 'rubocop-rake', require: false
11
- gem 'rubocop-rspec', require: false
8
+ gem 'rubocop', '1.36.0', require: false
9
+ gem 'rubocop-performance', '1.15.0', require: false
10
+ gem 'rubocop-rake', '0.6.0', require: false
11
+ gem 'rubocop-rspec', '2.13.1', require: false
data/README.md CHANGED
@@ -8,6 +8,10 @@ A Ruby client for the [DNSimple API v2](https://developer.dnsimple.com/v2/).
8
8
  [DNSimple](https://dnsimple.com/) provides DNS hosting and domain registration that is simple and friendly.
9
9
  We provide a full API and an easy-to-use web interface so you can get your domain registered and set up with a minimal amount of effort.
10
10
 
11
+ ## Requirements
12
+
13
+ - Ruby: MRI > 2.7+
14
+
11
15
  ## Installation
12
16
 
13
17
  You can install the gem manually:
@@ -22,13 +26,50 @@ Or use Bundler and define it as a dependency in your Gemfile:
22
26
  gem 'dnsimple', '~> 6.0'
23
27
  ```
24
28
 
25
- ## Usage
29
+ ## Documentation
30
+
31
+ ### Relevant links
32
+
33
+ - [`dnsimple-ruby` RDocs](https://www.rubydoc.info/gems/dnsimple/).
34
+ - [DNSimple API documentation](https://developer.dnsimple.com).
35
+ - [DNSimple API examples repository](https://github.com/dnsimple/dnsimple-api-examples).
36
+ - [DNSimple support documentation](https://support.dnsimple.com).
26
37
 
27
- This library is a Ruby client you can use to interact with the [DNSimple API v2](https://developer.dnsimple.com/v2/). Here are some examples.
38
+ ### Sandbox Environment
39
+
40
+ We highly recommend testing against our [sandbox environment](https://developer.dnsimple.com/sandbox/) before using our production environment. This will allow you to avoid real purchases, live charges on your credit card, and reduce the chance of your running up against rate limits.
41
+
42
+ The client supports both the production and sandbox environment. To switch to sandbox pass the sandbox API host using the `base_url` option when you construct the client:
43
+
44
+ ```ruby
45
+ client = Dnsimple::Client.new(base_url: "https://api.sandbox.dnsimple.com", access_token: "a1b2c3")
46
+ ```
47
+
48
+ You will need to ensure that you are using an access token created in the sandbox environment. Production tokens will *not* work in the sandbox environment.
49
+
50
+ ### Examples
51
+
52
+ Be sure to require the gem before trying any of the examples:
28
53
 
29
54
  ```ruby
30
55
  require 'dnsimple'
56
+ ```
57
+
58
+ #### Setting a custom `User-Agent` header
59
+
60
+ You can customize the `User-Agent` header for the calls made to the DNSimple API:
61
+
62
+ ```ruby
63
+ client = Dnsimple::Client.new(user_agent: "my-app/1.0")
64
+ ```
65
+
66
+ The value you provide will be prepended to the default `User-Agent` the client uses. For example, if you use `my-app/1.0`, the final header value will be `my-app/1.0 dnsimple-ruby/0.14.0` (note that it will vary depending on the client version).
67
+
68
+ We recommend to customize the user agent. If you are building a library or integration on top of the official client, customizing the client will help us to understand what is this client used for, and allow to contribute back or get in touch.
69
+
70
+ #### Authentication
31
71
 
72
+ ```ruby
32
73
  client = Dnsimple::Client.new(access_token: "a1b2c3")
33
74
 
34
75
  # Fetch your details
@@ -43,47 +84,30 @@ account_id = 1010
43
84
  # as long as you authenticate with an Account access token
44
85
  whoami = client.identity.whoami.data
45
86
  account_id = whoami.account.id
87
+ ```
46
88
 
47
- # List your domains
89
+ #### Listing your domains
90
+
91
+ ```ruby
48
92
  puts client.domains.list_domains(account_id).data # => domains from the account 1234, first page
49
93
  puts client.domains.list_domains(account_id, query: { page: 3 }).data # => domains from the account 1234, third page
50
94
  puts client.domains.all_domains(account_id).data # => all domains from the account 1234 (use carefully)
51
-
52
- # Create a domain
53
- response = client.domains.create_domain(account_id, name: "example.com")
54
- puts response.data
55
-
56
- # Get a domain
57
- response = client.domains.domain(account_id, "example.com")
58
- puts response.data
59
95
  ```
60
96
 
61
- For the full library documentation visit <http://rubydoc.info/gems/dnsimple>
62
-
63
- ## Sandbox Environment
64
-
65
- We highly recommend testing against our [sandbox environment](https://developer.dnsimple.com/sandbox/) before using our production environment. This will allow you to avoid real purchases, live charges on your credit card, and reduce the chance of your running up against rate limits.
66
-
67
- The client supports both the production and sandbox environment. To switch to sandbox pass the sandbox API host using the `base_url` option when you construct the client:
97
+ #### Create a domain
68
98
 
69
99
  ```ruby
70
- client = Dnsimple::Client.new(base_url: "https://api.sandbox.dnsimple.com", access_token: "a1b2c3")
100
+ response = client.domains.create_domain(account_id, name: "example.com")
101
+ puts response.data
71
102
  ```
72
103
 
73
- You will need to ensure that you are using an access token created in the sandbox environment. Production tokens will *not* work in the sandbox environment.
74
-
75
- ## Setting a custom `User-Agent` header
76
-
77
- You can customize the `User-Agent` header for the calls made to the DNSimple API:
104
+ #### Get a domain
78
105
 
79
106
  ```ruby
80
- client = Dnsimple::Client.new(user_agent: "my-app/1.0")
107
+ response = client.domains.domain(account_id, "example.com")
108
+ puts response.data
81
109
  ```
82
110
 
83
- The value you provide will be prepended to the default `User-Agent` the client uses. For example, if you use `my-app/1.0`, the final header value will be `my-app/1.0 dnsimple-ruby/0.14.0` (note that it will vary depending on the client version).
84
-
85
- We recommend to customize the user agent. If you are building a library or integration on top of the official client, customizing the client will help us to understand what is this client used for, and allow to contribute back or get in touch.
86
-
87
111
  ## License
88
112
 
89
113
  Copyright (c) 2010-2022 DNSimple Corporation. This is Free Software distributed under the MIT license.
@@ -6,20 +6,20 @@ module Dnsimple
6
6
 
7
7
  # Lists the domains in the account.
8
8
  #
9
- # @see https://developer.dnsimple.com/v2/domains/#list
9
+ # @see https://developer.dnsimple.com/v2/domains/#listDomains
10
10
  # @see #all_domains
11
11
  #
12
12
  # @example List domains in the first page
13
- # client.domains.list(1010)
13
+ # client.domains.domains(1010)
14
14
  #
15
15
  # @example List domains, provide a specific page
16
- # client.domains.list(1010, page: 2)
16
+ # client.domains.domains(1010, page: 2)
17
17
  #
18
18
  # @example List domains, provide a sorting policy
19
- # client.domains.list(1010, sort: "expiration:asc")
19
+ # client.domains.domains(1010, sort: "expiration:asc")
20
20
  #
21
21
  # @example List domains, provide a filtering policy
22
- # client.domains.list(1010, filter: { name_like: "example" })
22
+ # client.domains.domains(1010, filter: { name_like: "example" })
23
23
  #
24
24
  # @param [Integer] account_id the account ID
25
25
  # @param [Hash] options the filtering and sorting options
@@ -45,7 +45,7 @@ module Dnsimple
45
45
  # Please use this method carefully, as fetching the entire collection will increase the number of requests
46
46
  # you send to the API server and you may eventually risk to hit the throttle limit.
47
47
  #
48
- # @see https://developer.dnsimple.com/v2/domains/#list
48
+ # @see https://developer.dnsimple.com/v2/domains/#listDomains
49
49
  # @see #domains
50
50
  #
51
51
  # @param [Integer] account_id the account ID
@@ -63,7 +63,10 @@ module Dnsimple
63
63
 
64
64
  # Creates a domain in the account.
65
65
  #
66
- # @see https://developer.dnsimple.com/v2/domains/#create
66
+ # @see https://developer.dnsimple.com/v2/domains/#createDomain
67
+ #
68
+ # @example Creating a domain in a specific account. Does not register the domain
69
+ # client.domains.create_domain(1010, name: "example.com")
67
70
  #
68
71
  # @param [Integer] account_id the account ID
69
72
  # @param [Hash] attributes
@@ -81,7 +84,13 @@ module Dnsimple
81
84
 
82
85
  # Gets a domain from the account.
83
86
  #
84
- # @see https://developer.dnsimple.com/v2/domains/#get
87
+ # @see https://developer.dnsimple.com/v2/domains/#getDomain
88
+ #
89
+ #
90
+ # @example Getting a domain in a specific account, by domain id
91
+ # client.domains.domain(1010, 12345)
92
+ # @example Getting a domain in a specific account, by domain name
93
+ # client.domains.domain(1010, "example.com")
85
94
  #
86
95
  # @param [Integer] account_id the account ID
87
96
  # @param [#to_s] domain_id The domain ID or domain name
@@ -100,7 +109,12 @@ module Dnsimple
100
109
  #
101
110
  # WARNING: this cannot be undone.
102
111
  #
103
- # @see https://developer.dnsimple.com/v2/domains/#delete
112
+ # @see https://developer.dnsimple.com/v2/domains/#deleteDomain
113
+ #
114
+ # @example Deleting a domain in a specific account, by domain id
115
+ # client.domains.delete_domain(1010, 12345)
116
+ # @example Deleting a domain in a specific account, by domain name
117
+ # client.domains.delete_domain(1010, "example.com")
104
118
  #
105
119
  # @param [Integer] account_id the account ID
106
120
  # @param [#to_s] domain_id The domain ID or domain name
@@ -7,18 +7,24 @@ module Dnsimple
7
7
 
8
8
  # RequestError is raised when an API request fails for an client, a server error or invalid request information.
9
9
  class RequestError < Error
10
- attr_reader :http_response
10
+ attr_reader :http_response, :attribute_errors
11
11
 
12
12
  def initialize(http_response)
13
13
  @http_response = http_response
14
+ @attribute_errors = attribute_errors_from(http_response)
14
15
  super(message_from(http_response))
15
16
  end
16
17
 
17
18
  private
18
19
 
20
+ def attribute_errors_from(http_response)
21
+ return unless is_json_response?(http_response)
22
+
23
+ http_response.parsed_response["errors"]
24
+ end
25
+
19
26
  def message_from(http_response)
20
- content_type = http_response.headers["Content-Type"]
21
- if content_type&.start_with?("application/json")
27
+ if is_json_response?(http_response)
22
28
  http_response.parsed_response["message"]
23
29
  else
24
30
  net_http_response = http_response.response
@@ -26,6 +32,11 @@ module Dnsimple
26
32
  end
27
33
  end
28
34
 
35
+ def is_json_response?(http_response)
36
+ content_type = http_response.headers["Content-Type"]
37
+ content_type&.start_with?("application/json")
38
+ end
39
+
29
40
  end
30
41
 
31
42
  class NotFoundError < RequestError
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dnsimple
4
- VERSION = "8.0.0"
4
+ VERSION = "8.1.0"
5
5
  end
@@ -28,9 +28,9 @@ describe Dnsimple::Client, ".registrar" do
28
28
 
29
29
  result = response.data
30
30
  expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
31
- expect(result.domain_id).to be_kind_of(Integer)
31
+ expect(result.domain_id).to be_a(Integer)
32
32
  expect(result.enabled).to be(true)
33
- expect(result.expires_on).to be_kind_of(String)
33
+ expect(result.expires_on).to be_a(String)
34
34
  end
35
35
  end
36
36
 
@@ -57,9 +57,9 @@ describe Dnsimple::Client, ".registrar" do
57
57
 
58
58
  result = response.data
59
59
  expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
60
- expect(result.domain_id).to be_kind_of(Integer)
60
+ expect(result.domain_id).to be_a(Integer)
61
61
  expect(result.enabled).to be(true)
62
- expect(result.expires_on).to be_kind_of(String)
62
+ expect(result.expires_on).to be_a(String)
63
63
  end
64
64
  end
65
65
 
@@ -83,7 +83,7 @@ describe Dnsimple::Client, ".registrar" do
83
83
 
84
84
  result = response.data
85
85
  expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
86
- expect(result.domain_id).to be_kind_of(Integer)
86
+ expect(result.domain_id).to be_a(Integer)
87
87
  expect(result.enabled).to be_nil
88
88
  expect(result.expires_on).to be_nil
89
89
  end
@@ -112,9 +112,9 @@ describe Dnsimple::Client, ".registrar" do
112
112
 
113
113
  result = response.data
114
114
  expect(result).to be_a(Dnsimple::Struct::WhoisPrivacy)
115
- expect(result.domain_id).to be_kind_of(Integer)
115
+ expect(result.domain_id).to be_a(Integer)
116
116
  expect(result.enabled).to be(false)
117
- expect(result.expires_on).to be_kind_of(String)
117
+ expect(result.expires_on).to be_a(String)
118
118
  end
119
119
  end
120
120
 
@@ -140,10 +140,10 @@ describe Dnsimple::Client, ".registrar" do
140
140
 
141
141
  result = response.data
142
142
  expect(result).to be_a(Dnsimple::Struct::WhoisPrivacyRenewal)
143
- expect(result.domain_id).to be_kind_of(Integer)
144
- expect(result.whois_privacy_id).to be_kind_of(Integer)
143
+ expect(result.domain_id).to be_a(Integer)
144
+ expect(result.whois_privacy_id).to be_a(Integer)
145
145
  expect(result.enabled).to be(true)
146
- expect(result.expires_on).to be_kind_of(String)
146
+ expect(result.expires_on).to be_a(String)
147
147
  end
148
148
 
149
149
  context "when whois privacy was't previously purchased" do
@@ -90,7 +90,22 @@ describe Dnsimple::Client do
90
90
 
91
91
  expect {
92
92
  subject.execute(:post, "foo", {})
93
- }.to raise_error(Dnsimple::RequestError, "The domain google.com is already in DNSimple and cannot be added")
93
+ }.to raise_error(Dnsimple::RequestError, "The domain google.com is already in DNSimple and cannot be added") do |exception|
94
+ expect(exception.attribute_errors).to be_nil
95
+ end
96
+ end
97
+
98
+ it "raises a Request error in case of an error with a JSON response with attribute errors" do
99
+ stub_request(:post, %r{/foo}).to_return(read_http_fixture("validation-error.http"))
100
+
101
+ expect {
102
+ subject.execute(:post, "foo", {})
103
+ }.to raise_error(Dnsimple::RequestError, "Validation failed") do |exception|
104
+ expect(exception).to respond_to(:attribute_errors)
105
+ expect(exception.attribute_errors).to be_a(Hash)
106
+ expect(exception.attribute_errors["email"]).to eq(["can't be blank", "is an invalid email address"])
107
+ expect(exception.attribute_errors["address1"]).to eq(["can't be blank"])
108
+ end
94
109
  end
95
110
 
96
111
  it "raises RequestError in case of error with an HTML response" do
@@ -98,7 +113,9 @@ describe Dnsimple::Client do
98
113
 
99
114
  expect {
100
115
  subject.execute(:get, "foo", {})
101
- }.to raise_error(Dnsimple::RequestError, "502 Bad Gateway")
116
+ }.to raise_error(Dnsimple::RequestError, "502 Bad Gateway") do |exception|
117
+ expect(exception.attribute_errors).to be_nil
118
+ end
102
119
  end
103
120
 
104
121
  it "raises RequestError in absence of content types" do
@@ -106,7 +123,9 @@ describe Dnsimple::Client do
106
123
 
107
124
  expect {
108
125
  subject.execute(:put, "foo", {})
109
- }.to raise_error(Dnsimple::RequestError, "405 Method Not Allowed")
126
+ }.to raise_error(Dnsimple::RequestError, "405 Method Not Allowed") do |exception|
127
+ expect(exception.attribute_errors).to be_nil
128
+ end
110
129
  end
111
130
  end
112
131
 
@@ -126,7 +145,7 @@ describe Dnsimple::Client do
126
145
  it "delegates to HTTParty" do
127
146
  stub_request(:get, %r{/foo})
128
147
 
129
- allow(HTTParty).to receive(:get)
148
+ expect(HTTParty).to receive(:get)
130
149
  .with(
131
150
  "#{subject.base_url}foo", {
132
151
  format: :json,
@@ -150,7 +169,9 @@ describe Dnsimple::Client do
150
169
  }
151
170
  )
152
171
 
153
- subject.request(:put, 'foo', { something: "else" }, { query: { foo: "bar" }, headers: { "Custom" => "Header" } })
172
+ expect {
173
+ subject.request(:put, 'foo', { something: "else" }, { query: { foo: "bar" }, headers: { "Custom" => "Header" } })
174
+ }.not_to raise_error
154
175
  end
155
176
 
156
177
  it "handles non application/json content types" do
@@ -164,7 +185,9 @@ describe Dnsimple::Client do
164
185
  }
165
186
  )
166
187
 
167
- subject.request(:post, 'foo', { something: "else" }, { headers: { "Content-Type" => "application/x-www-form-urlencoded" } })
188
+ expect {
189
+ subject.request(:post, 'foo', { something: "else" }, { headers: { "Content-Type" => "application/x-www-form-urlencoded" } })
190
+ }.not_to raise_error
168
191
  end
169
192
 
170
193
  it "includes options for proxy support" do
@@ -178,8 +201,10 @@ describe Dnsimple::Client do
178
201
  }
179
202
  )
180
203
 
181
- subject = described_class.new(proxy: "example-proxy.com:4321")
182
- subject.request(:get, "test", nil, {})
204
+ expect {
205
+ subject = described_class.new(proxy: "example-proxy.com:4321")
206
+ subject.request(:get, "test", nil, {})
207
+ }.not_to raise_error
183
208
  end
184
209
 
185
210
  it "supports custom user agent" do
@@ -190,8 +215,10 @@ describe Dnsimple::Client do
190
215
  headers: hash_including("User-Agent" => "customAgent #{Dnsimple::Default::USER_AGENT}"), }
191
216
  )
192
217
 
193
- subject = described_class.new(user_agent: "customAgent")
194
- subject.request(:get, "test", nil)
218
+ expect {
219
+ subject = described_class.new(user_agent: "customAgent")
220
+ subject.request(:get, "test", nil)
221
+ }.not_to raise_error
195
222
  end
196
223
  end
197
224
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnsimple
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - DNSimple
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-10 00:00:00.000000000 Z
11
+ date: 2022-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty