dnsimple 2.0.0.alpha2 → 2.0.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +6 -2
- data/README.markdown +32 -30
- data/dnsimple.gemspec +1 -2
- data/lib/dnsimple.rb +2 -13
- data/lib/dnsimple/client.rb +164 -53
- data/lib/dnsimple/client/certificates_service.rb +98 -0
- data/lib/dnsimple/client/client_service.rb +8 -0
- data/lib/dnsimple/client/contacts_service.rb +82 -0
- data/lib/dnsimple/client/domains_service.rb +333 -0
- data/lib/dnsimple/client/name_servers_service.rb +69 -0
- data/lib/dnsimple/client/registrars_service.rb +105 -0
- data/lib/dnsimple/client/services_service.rb +95 -0
- data/lib/dnsimple/client/templates_service.rb +180 -0
- data/lib/dnsimple/client/users_service.rb +37 -0
- data/lib/dnsimple/compatibility.rb +46 -0
- data/lib/dnsimple/default.rb +86 -0
- data/lib/dnsimple/error.rb +7 -11
- data/lib/dnsimple/extra.rb +54 -0
- data/lib/dnsimple/struct.rb +29 -0
- data/lib/dnsimple/struct/certificate.rb +56 -0
- data/lib/dnsimple/struct/contact.rb +61 -0
- data/lib/dnsimple/struct/domain.rb +40 -0
- data/lib/dnsimple/struct/email_forward.rb +14 -0
- data/lib/dnsimple/struct/extended_attribute.rb +39 -0
- data/lib/dnsimple/struct/membership.rb +22 -0
- data/lib/dnsimple/struct/price.rb +16 -0
- data/lib/dnsimple/struct/record.rb +22 -0
- data/lib/dnsimple/struct/service.rb +19 -0
- data/lib/dnsimple/struct/template.rb +19 -0
- data/lib/dnsimple/struct/template_record.rb +24 -0
- data/lib/dnsimple/struct/transfer_order.rb +10 -0
- data/lib/dnsimple/struct/user.rb +17 -0
- data/lib/dnsimple/struct/whois_privacy.rb +19 -0
- data/lib/dnsimple/version.rb +1 -1
- data/spec/dnsimple/client/certificates_service_spec.rb +196 -0
- data/spec/dnsimple/client/contacts_service_spec.rb +179 -0
- data/spec/dnsimple/client/domains_service_spec.rb +662 -0
- data/spec/dnsimple/client/name_servers_service_spec.rb +131 -0
- data/spec/dnsimple/client/registrars_service_spec.rb +160 -0
- data/spec/dnsimple/client/services_service_spec.rb +162 -0
- data/spec/dnsimple/client/templates_service_spec.rb +371 -0
- data/spec/dnsimple/client/users_service_spec.rb +70 -0
- data/spec/dnsimple/client_spec.rb +108 -99
- data/spec/dnsimple/compatibility_spec.rb +57 -0
- data/spec/files/2fa/exchange-token.http +8 -11
- data/spec/files/badgateway.http +14 -0
- data/spec/files/certificates/configure/success.http +19 -0
- data/spec/files/certificates/index/success.http +1 -1
- data/spec/files/certificates/notfound.http +19 -0
- data/spec/files/certificates/purchase/success.http +19 -0
- data/spec/files/certificates/show/success.http +1 -1
- data/spec/files/certificates/submit/success.http +19 -0
- data/spec/files/contacts/create/badrequest-missingcontact.http +19 -0
- data/spec/files/contacts/create/badrequest-validationerror.http +19 -0
- data/spec/files/contacts/create/created.http +22 -0
- data/spec/files/contacts/delete/success-204.http +18 -0
- data/spec/files/{extended_attributes/com.http → contacts/delete/success.http} +5 -5
- data/spec/files/{domains/auto_renewal_enable → contacts/index}/success.http +6 -6
- data/spec/files/contacts/notfound.http +19 -0
- data/spec/files/contacts/update/success.http +21 -0
- data/spec/files/domains/create/created.http +21 -0
- data/spec/files/domains/index/success.http +11 -9
- data/spec/files/domains/notfound.http +11 -9
- data/spec/files/domains/show/success.http +12 -10
- data/spec/files/domains_autorenewal/disable/success.http +21 -0
- data/spec/files/domains_autorenewal/enable/success.http +21 -0
- data/spec/files/domains_autorenewal/notfound-domain.http +19 -0
- data/spec/files/domains_forwards/create/created.http +22 -0
- data/spec/files/domains_forwards/delete/success.http +17 -0
- data/spec/files/domains_forwards/get/success.http +21 -0
- data/spec/files/domains_forwards/list/success.http +21 -0
- data/spec/files/domains_forwards/notfound-domain.http +19 -0
- data/spec/files/domains_forwards/notfound.http +19 -0
- data/spec/files/domains_records/create/created.http +21 -0
- data/spec/files/domains_records/delete/success-204.http +18 -0
- data/spec/files/{contacts/show/notfound.http → domains_records/delete/success.http} +9 -7
- data/spec/files/{records → domains_records}/index/success.http +0 -0
- data/spec/files/{records/show → domains_records}/notfound.http +1 -1
- data/spec/files/{records → domains_records}/show/success.http +0 -0
- data/spec/files/domains_records/update/success.http +21 -0
- data/spec/files/domains_sharing/create/success.http +21 -0
- data/spec/files/domains_sharing/delete/success.http +17 -0
- data/spec/files/domains_sharing/list/success.http +21 -0
- data/spec/files/domains_sharing/notfound-domain.http +19 -0
- data/spec/files/domains_sharing/notfound.http +19 -0
- data/spec/files/domains_whois_privacy/disable/success.http +21 -0
- data/spec/files/domains_whois_privacy/enable/success.http +22 -0
- data/spec/files/domains_zones/get/success.http +21 -0
- data/spec/files/domains_zones/notfound-domain.http +19 -0
- data/spec/files/{domains/auto_renewal_disable/notfound.http → nameservers/change/success.http} +23 -21
- data/spec/files/nameservers/deregister/success.http +17 -0
- data/spec/files/{domains/auto_renewal_enable/notfound.http → nameservers/list/success.http} +23 -21
- data/spec/files/nameservers/notfound-domain.http +19 -0
- data/spec/files/nameservers/register/badrequest-valueerror.http +19 -0
- data/spec/files/nameservers/register/success.http +21 -0
- data/spec/files/registrars/check/available.http +19 -0
- data/spec/files/registrars/check/registered.http +21 -0
- data/spec/files/registrars/register/badrequest-missingdomain.http +19 -0
- data/spec/files/registrars/register/badrequest-missingregistrant.http +19 -0
- data/spec/files/registrars/register/success.http +21 -0
- data/spec/files/registrars/renew/badrequest-missingrenewal.http +19 -0
- data/spec/files/registrars/renew/badrequest-unable.http +19 -0
- data/spec/files/registrars/renew/success.http +21 -0
- data/spec/files/registrars/transfer/success.http +21 -0
- data/spec/files/registrars_extended_attributes/list/success.http +21 -0
- data/spec/files/registrars_prices/list/success.http +21 -0
- data/spec/files/services/applied/success.http +21 -0
- data/spec/files/services/apply/success.http +21 -0
- data/spec/files/services/available/success.http +21 -0
- data/spec/files/services/index/success.http +21 -0
- data/spec/files/services/notfound.http +19 -0
- data/spec/files/services/show/success.http +21 -0
- data/spec/files/services/unapply/success.http +21 -0
- data/spec/files/subscription/show/success.http +21 -0
- data/spec/files/templates/apply/success.http +21 -0
- data/spec/files/templates/create/created.http +22 -0
- data/spec/files/templates/delete/success-204.http +21 -0
- data/spec/files/templates/delete/success.http +21 -0
- data/spec/files/templates/index/success.http +21 -0
- data/spec/files/templates/notfound.http +19 -0
- data/spec/files/templates/show/success.http +12 -10
- data/spec/files/templates/update/success.http +21 -0
- data/spec/files/templates_records/create/created.http +22 -0
- data/spec/files/templates_records/delete/success-204.http +19 -0
- data/spec/files/templates_records/delete/success.http +21 -0
- data/spec/files/templates_records/index/success.http +21 -0
- data/spec/files/templates_records/notfound.http +19 -0
- data/spec/files/templates_records/show/success.http +21 -0
- data/spec/files/templates_records/update/success.http +21 -0
- data/spec/files/users/user/success.http +21 -0
- data/spec/spec_helper.rb +0 -2
- metadata +206 -73
- data/lib/dnsimple/base.rb +0 -10
- data/lib/dnsimple/certificate.rb +0 -143
- data/lib/dnsimple/contact.rb +0 -157
- data/lib/dnsimple/domain.rb +0 -252
- data/lib/dnsimple/extended_attribute.rb +0 -52
- data/lib/dnsimple/record.rb +0 -94
- data/lib/dnsimple/service.rb +0 -42
- data/lib/dnsimple/template.rb +0 -65
- data/lib/dnsimple/template_record.rb +0 -80
- data/lib/dnsimple/transfer_order.rb +0 -34
- data/lib/dnsimple/user.rb +0 -50
- data/spec/dnsimple/certificate_spec.rb +0 -59
- data/spec/dnsimple/contact_spec.rb +0 -45
- data/spec/dnsimple/domain_spec.rb +0 -241
- data/spec/dnsimple/extended_attributes_spec.rb +0 -54
- data/spec/dnsimple/record_spec.rb +0 -51
- data/spec/dnsimple/template_spec.rb +0 -31
- data/spec/dnsimple/user_spec.rb +0 -70
- data/spec/files/account/user/success.http +0 -19
- data/spec/files/certificates/show/notfound.http +0 -17
- data/spec/files/domains/auto_renewal_disable/success.http +0 -23
- data/spec/files/domains/create/success.http +0 -19
- data/spec/files/extended_attributes/ca.http +0 -19
- data/spec/files/extended_attributes/success.http +0 -19
- data/spec/files/templates/show/notfound.http +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59bd049e932b2627935ec1c20b461c044a469db7
|
4
|
+
data.tar.gz: 339e7ddd3c26886983121c50b9f0600d4e91d458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18d6712c612148898493bacc510a5686233407b670125cc8da40a5152b7b19dca74217b316ffd7f81a6e62ebf678f502213dcaf3887a999a96ee0fafec171337
|
7
|
+
data.tar.gz: b8342199df7bee17d7483f09b9b32a22e076e694a69a12c43e06718f3392f6197bd4f06f838f67382cc911b776daa250ccc98152d7f6ab9f37ee2fcdd7e81327
|
data/CHANGELOG.markdown
CHANGED
@@ -2,19 +2,23 @@
|
|
2
2
|
|
3
3
|
#### 2.0.0.alpha
|
4
4
|
|
5
|
+
- NEW: Add support changing name servers (GH-52). Thanks @rosscooperman
|
6
|
+
|
5
7
|
- CHANGED: Drop 1.8.7 support.
|
6
8
|
|
7
9
|
- CHANGED: This package no longer provides a CLI. The CLI has been extracted to [aetrion/dnsimple-ruby-cli](https://github.com/aetrion/dnsimple-ruby-cli)
|
8
10
|
|
9
|
-
- CHANGED: Renamed the Gem from "dnsimple-ruby" to "dnsimple"
|
11
|
+
- CHANGED: Renamed the Gem from "dnsimple-ruby" to "dnsimple" (GH-23).
|
10
12
|
|
11
13
|
- CHANGED: Renamed the namespace from DNSimple to Dnsimple.
|
12
14
|
|
15
|
+
- CHANGED: Redesigned client API.
|
16
|
+
|
13
17
|
- REMOVED: The library no longer provides built-in support for loading the credentials from a config file.
|
14
18
|
|
15
19
|
#### Release 1.7.1
|
16
20
|
|
17
|
-
- FIXED: Updated Certificate to match the serialized attributes (GH-53)
|
21
|
+
- FIXED: Updated Certificate to match the serialized attributes (GH-53).
|
18
22
|
|
19
23
|
#### Release 1.7.0
|
20
24
|
|
data/README.markdown
CHANGED
@@ -11,48 +11,50 @@ We provide a full API and an easy-to-use web interface so you can get your domai
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
|
14
|
+
```
|
15
|
+
$ gem install dnsimple
|
16
|
+
```
|
17
|
+
|
15
18
|
|
19
|
+
## Getting Started
|
16
20
|
|
17
|
-
|
21
|
+
This library is a Ruby client you can use to interact with the [DNSimple API](http://developer.dnsimple.com/).
|
18
22
|
|
19
|
-
|
23
|
+
Here's a short example.
|
20
24
|
|
21
25
|
```ruby
|
22
26
|
require 'dnsimple'
|
23
27
|
|
24
|
-
|
25
|
-
DNSimple::Client.password = 'YOUR_PASSWORD'
|
28
|
+
client = Dnsimple::Client.new(username: 'YOUR_USERNAME', api_token: 'YOUR_TOKEN')
|
26
29
|
|
27
|
-
user
|
28
|
-
|
30
|
+
# Fetch your user details
|
31
|
+
user = client.users.user
|
32
|
+
puts "My email is #{user.email}"
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
# Get a list of your domains
|
35
|
+
domains = client.domains.list
|
36
|
+
domains.each do |domain|
|
37
|
+
puts "Domain: %s (id: %d)" % [domain.name, domain.id]
|
33
38
|
end
|
34
39
|
|
35
|
-
|
36
|
-
domain.
|
37
|
-
|
38
|
-
domain = DNSimple::Domain.create("newdomain.com")
|
39
|
-
puts "Added #{domain.name}"
|
40
|
-
domain.delete # removes from DNSimple
|
40
|
+
# Create a domain
|
41
|
+
domain = client.domains.create("example.com")
|
42
|
+
puts "Domain: %s (id: %d)" % [domain.name, domain.id]
|
41
43
|
```
|
42
44
|
|
43
|
-
For the full
|
45
|
+
For the full library documentation visit http://rubydoc.info/gems/dnsimple
|
46
|
+
|
44
47
|
|
45
|
-
|
48
|
+
## Authentication
|
46
49
|
|
47
50
|
This client supports both the HTTP Basic and API Token authentication mechanism.
|
48
51
|
|
49
52
|
#### HTTP Basic
|
50
53
|
|
51
54
|
```ruby
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
user = DNSimple::User.me
|
55
|
+
client = Dnsimple::Client.new(username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD')
|
56
|
+
client.users.user
|
57
|
+
# => Dnsimple::Struct::User
|
56
58
|
```
|
57
59
|
|
58
60
|
#### HTTP Basic with two-factor authentication enabled
|
@@ -61,20 +63,20 @@ See the [2FA API documentation](http://developer.dnsimple.com/authentication/#tw
|
|
61
63
|
|
62
64
|
```ruby
|
63
65
|
# Request the 2FA exchange token
|
64
|
-
|
65
|
-
|
66
|
-
token = DNSimple::User.two_factor_exchange_token('otp-token')
|
66
|
+
client = Dnsimple::Client.new(username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD')
|
67
|
+
token = client.users.exchange_token('otp-token')
|
67
68
|
|
68
69
|
# Authenticate with the exchange token
|
69
|
-
|
70
|
-
user
|
70
|
+
client.exchange_token = token
|
71
|
+
client.users.user
|
72
|
+
# => Dnsimple::Struct::User
|
71
73
|
```
|
72
74
|
|
73
75
|
#### API Token
|
74
76
|
|
75
77
|
```ruby
|
76
|
-
|
77
|
-
DNSimple::Client.api_token = 'API_TOKEN'
|
78
|
+
client = Dnsimple::Client.new(username: 'YOUR_USERNAME', api_token: 'YOUR_TOKEN')
|
78
79
|
|
79
|
-
user
|
80
|
+
client.users.user
|
81
|
+
# => Dnsimple::Struct::User
|
80
82
|
```
|
data/dnsimple.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ['anthony.eden@dnsimple.com', 'simone.carletti@dnsimple.com']
|
10
10
|
s.homepage = 'http://github.com/aetrion/dnsimple-ruby'
|
11
11
|
s.summary = 'A Ruby client for the DNSimple API'
|
12
|
-
s.description = 'A Ruby client for the DNSimple API
|
12
|
+
s.description = 'A Ruby client for the DNSimple API.'
|
13
13
|
|
14
14
|
s.required_ruby_version = ">= 1.9.3"
|
15
15
|
|
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency 'httparty'
|
22
22
|
|
23
23
|
s.add_development_dependency 'rake'
|
24
|
-
s.add_development_dependency 'mocha'
|
25
24
|
s.add_development_dependency 'rspec'
|
26
25
|
s.add_development_dependency 'yard'
|
27
26
|
s.add_development_dependency 'webmock'
|
data/lib/dnsimple.rb
CHANGED
@@ -2,8 +2,6 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
module Dnsimple
|
4
4
|
|
5
|
-
BLANK_REGEX = /\S+/
|
6
|
-
|
7
5
|
# Echoes a deprecation warning message.
|
8
6
|
#
|
9
7
|
# @param [String] message The message to display.
|
@@ -18,16 +16,7 @@ module Dnsimple
|
|
18
16
|
|
19
17
|
end
|
20
18
|
|
21
|
-
require 'dnsimple/
|
19
|
+
require 'dnsimple/version'
|
20
|
+
require 'dnsimple/default'
|
22
21
|
require 'dnsimple/client'
|
23
22
|
require 'dnsimple/error'
|
24
|
-
require 'dnsimple/user'
|
25
|
-
require 'dnsimple/contact'
|
26
|
-
require 'dnsimple/domain'
|
27
|
-
require 'dnsimple/record'
|
28
|
-
require 'dnsimple/template'
|
29
|
-
require 'dnsimple/template_record'
|
30
|
-
require 'dnsimple/transfer_order'
|
31
|
-
require 'dnsimple/extended_attribute'
|
32
|
-
require 'dnsimple/service'
|
33
|
-
require 'dnsimple/certificate'
|
data/lib/dnsimple/client.rb
CHANGED
@@ -1,96 +1,207 @@
|
|
1
|
-
require 'dnsimple/
|
2
|
-
require '
|
1
|
+
require 'dnsimple/compatibility'
|
2
|
+
require 'dnsimple/extra'
|
3
|
+
require 'dnsimple/struct'
|
4
|
+
require 'dnsimple/client/client_service'
|
5
|
+
require 'dnsimple/client/certificates_service'
|
6
|
+
require 'dnsimple/client/contacts_service'
|
7
|
+
require 'dnsimple/client/domains_service'
|
8
|
+
require 'dnsimple/client/name_servers_service'
|
9
|
+
require 'dnsimple/client/registrars_service'
|
10
|
+
require 'dnsimple/client/services_service'
|
11
|
+
require 'dnsimple/client/templates_service'
|
12
|
+
require 'dnsimple/client/users_service'
|
3
13
|
|
4
14
|
module Dnsimple
|
15
|
+
|
16
|
+
# Client for the DNSimple API
|
17
|
+
#
|
18
|
+
# @see http://developer.dnsimple.com
|
5
19
|
class Client
|
20
|
+
include Dnsimple::Compatibility
|
6
21
|
|
7
|
-
DEFAULT_BASE_URI = "https://api.dnsimple.com/"
|
8
22
|
HEADER_2FA_STRICT = "X-DNSimple-2FA-Strict"
|
9
23
|
HEADER_API_TOKEN = "X-DNSimple-Token"
|
10
24
|
HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token"
|
11
25
|
HEADER_OTP_TOKEN = "X-DNSimple-OTP"
|
12
26
|
HEADER_EXCHANGE_TOKEN = "X-DNSimple-OTP-Token"
|
13
27
|
|
14
|
-
class << self
|
15
|
-
# @return [Boolean] if the debug mode is enabled.
|
16
|
-
# Defaults to false.
|
17
|
-
attr_accessor :debug
|
18
28
|
|
19
|
-
|
29
|
+
# @!attribute api_endpoint
|
30
|
+
# @return [String] Base URL for API requests. (default: https://api.dnsimple.com/)
|
31
|
+
# @!attribute username
|
32
|
+
# @return [String] DNSimple username for Basic Authentication
|
33
|
+
# @!attribute password
|
34
|
+
# @see http://developer.dnsimple.com/authentication/
|
35
|
+
# @return [String] DNSimple password for Basic Authentication
|
36
|
+
# @!attribute exchange_token
|
37
|
+
# @see http://developer.dnsimple.com/authentication/
|
38
|
+
# @return [String] Exchange Token for Basic Authentication with 2FA
|
39
|
+
# @!attribute api_token
|
40
|
+
# @see http://developer.dnsimple.com/authentication/
|
41
|
+
# @return [String] API access token for authentication
|
42
|
+
# @!attribute domain_api_token
|
43
|
+
# @see http://developer.dnsimple.com/authentication/
|
44
|
+
# @return [String] Domain API access token for authentication
|
45
|
+
# @!attribute user_agent
|
46
|
+
# @return [String] Configure User-Agent header for requests.
|
47
|
+
# @!attribute proxy
|
48
|
+
# @return [String,nil] Configure address:port values for proxy server
|
49
|
+
|
50
|
+
attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
|
51
|
+
:user_agent, :proxy
|
52
|
+
|
53
|
+
|
54
|
+
def initialize(options = {})
|
55
|
+
defaults = Dnsimple::Default.options
|
56
|
+
|
57
|
+
Dnsimple::Default.keys.each do |key|
|
58
|
+
instance_variable_set(:"@#{key}", options[key] || defaults[key])
|
59
|
+
end
|
60
|
+
|
61
|
+
@services = {}
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# Make a HTTP GET request.
|
66
|
+
#
|
67
|
+
# @param [String] url The path, relative to {#api_endpoint}
|
68
|
+
# @param [Hash] options Query and header params for request
|
69
|
+
# @return [HTTParty::Response]
|
70
|
+
def get(path, options = {})
|
71
|
+
request :get, path, options
|
20
72
|
end
|
21
73
|
|
22
|
-
#
|
74
|
+
# Make a HTTP POST request.
|
23
75
|
#
|
24
|
-
# @
|
25
|
-
|
26
|
-
|
76
|
+
# @param [String] url The path, relative to {#api_endpoint}
|
77
|
+
# @param [Hash] options Body and header params for request
|
78
|
+
# @return [HTTParty::Response]
|
79
|
+
def post(path, options = {})
|
80
|
+
request :post, path, options
|
27
81
|
end
|
28
82
|
|
29
|
-
#
|
83
|
+
# Make a HTTP PUT request.
|
30
84
|
#
|
31
|
-
# @param
|
32
|
-
|
33
|
-
|
85
|
+
# @param [String] url The path, relative to {#api_endpoint}
|
86
|
+
# @param [Hash] options Body and header params for request
|
87
|
+
# @return [HTTParty::Response]
|
88
|
+
def put(path, options = {})
|
89
|
+
request :put, path, options
|
34
90
|
end
|
35
91
|
|
36
|
-
|
37
|
-
|
92
|
+
# Make a HTTP DELETE request.
|
93
|
+
#
|
94
|
+
# @param [String] url The path, relative to {#api_endpoint}
|
95
|
+
# @param [Hash] options Query and header params for request
|
96
|
+
# @return [HTTParty::Response]
|
97
|
+
def delete(path, options = {})
|
98
|
+
request :delete, path, options
|
38
99
|
end
|
39
100
|
|
40
|
-
def self.base_options
|
41
|
-
options = {
|
42
|
-
:format => :json,
|
43
|
-
:headers => { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{VERSION}" },
|
44
|
-
}
|
45
101
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
102
|
+
# Make a HTTP request.
|
103
|
+
#
|
104
|
+
# @param [String] method The HTTP method
|
105
|
+
# @param [String] url The path, relative to {#api_endpoint}
|
106
|
+
# @param [Hash] options Query and header params for request
|
107
|
+
# @return [HTTParty::Response]
|
108
|
+
def request(method, path, data, options = {})
|
109
|
+
if data.is_a?(Hash)
|
110
|
+
options[:query] = data.delete(:query) if data.key?(:query)
|
111
|
+
options[:headers] = data.delete(:headers) if data.key?(:headers)
|
112
|
+
end
|
113
|
+
if !data.empty?
|
114
|
+
options[:body] = data
|
51
115
|
end
|
52
116
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
117
|
+
response = HTTParty.send(method, api_endpoint + path, Extra.deep_merge!(base_options, options))
|
118
|
+
|
119
|
+
case response.code
|
120
|
+
when 200..299
|
121
|
+
response
|
122
|
+
when 401
|
123
|
+
raise (response.headers[HEADER_OTP_TOKEN] == "required" ? TwoFactorAuthenticationRequired : AuthenticationFailed), response["message"]
|
124
|
+
when 404
|
125
|
+
raise RecordNotFound.new(response)
|
61
126
|
else
|
62
|
-
raise
|
127
|
+
raise RequestError.new(response)
|
63
128
|
end
|
129
|
+
end
|
64
130
|
|
65
|
-
|
131
|
+
|
132
|
+
# @return [Dnsimple::Client::CertificatesService] The certificate-related API proxy.
|
133
|
+
def certificates
|
134
|
+
@services[:certificates] ||= Client::CertificatesService.new(self)
|
66
135
|
end
|
67
136
|
|
68
|
-
|
69
|
-
|
137
|
+
# @return [Dnsimple::Client::ContactsService] The contact-related API proxy.
|
138
|
+
def contacts
|
139
|
+
@services[:contacts] ||= Client::ContactsService.new(self)
|
70
140
|
end
|
71
141
|
|
72
|
-
|
73
|
-
|
142
|
+
# @return [Dnsimple::Client::DomainsService] The domain-related API proxy.
|
143
|
+
def domains
|
144
|
+
@services[:domains] ||= Client::DomainsService.new(self)
|
74
145
|
end
|
75
146
|
|
76
|
-
|
77
|
-
|
147
|
+
# @return [Dnsimple::Client::NameServersService] The name server-related API proxy.
|
148
|
+
def name_servers
|
149
|
+
@services[:name_servers] ||= Client::NameServersService.new(self)
|
78
150
|
end
|
79
151
|
|
80
|
-
|
81
|
-
|
152
|
+
# @return [Dnsimple::Client::RegistrarsService] The registrar-related API proxy.
|
153
|
+
def registrars
|
154
|
+
@services[:registrars] ||= Client::RegistrarsService.new(self)
|
155
|
+
end
|
156
|
+
|
157
|
+
# @return [Dnsimple::Client::ServicesService] The service-related API proxy.
|
158
|
+
def services
|
159
|
+
@services[:services] ||= Client::ServicesService.new(self)
|
160
|
+
end
|
161
|
+
|
162
|
+
# @return [Dnsimple::Client::TemplatesService] The template-related API proxy.
|
163
|
+
def templates
|
164
|
+
@services[:templates] ||= Client::TemplatesService.new(self)
|
82
165
|
end
|
83
166
|
|
84
|
-
|
85
|
-
|
167
|
+
# @return [Dnsimple::Client::UsersService] The user-related API proxy.
|
168
|
+
def users
|
169
|
+
@services[:users] ||= Client::UsersService.new(self)
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
# @return [String] Base URL for API requests.
|
174
|
+
def api_endpoint
|
175
|
+
File.join(@api_endpoint, "")
|
176
|
+
end
|
86
177
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
178
|
+
|
179
|
+
private
|
180
|
+
|
181
|
+
def base_options
|
182
|
+
options = {
|
183
|
+
format: :json,
|
184
|
+
headers: { 'Accept' => 'application/json', 'User-Agent' => user_agent },
|
185
|
+
}
|
186
|
+
|
187
|
+
if proxy
|
188
|
+
address, port = proxy.split(":")
|
189
|
+
options.merge!(http_proxyaddr: address, http_proxyport: port)
|
91
190
|
end
|
92
191
|
|
93
|
-
|
192
|
+
if exchange_token
|
193
|
+
options[:basic_auth] = { username: exchange_token, password: "x-2fa-basic" }
|
194
|
+
elsif password
|
195
|
+
options[:basic_auth] = { username: username, password: password }
|
196
|
+
elsif domain_api_token
|
197
|
+
options[:headers][HEADER_DOMAIN_API_TOKEN] = domain_api_token
|
198
|
+
elsif api_token
|
199
|
+
options[:headers][HEADER_API_TOKEN] = "#{username}:#{api_token}"
|
200
|
+
else
|
201
|
+
raise Error, 'A password or API token is required for all API requests.'
|
202
|
+
end
|
203
|
+
|
204
|
+
options
|
94
205
|
end
|
95
206
|
|
96
207
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Dnsimple
|
2
|
+
class Client
|
3
|
+
class CertificatesService < ClientService
|
4
|
+
|
5
|
+
# Lists the certificates for a domain.
|
6
|
+
#
|
7
|
+
# @see http://developer.dnsimple.com/domains/certificates/#list
|
8
|
+
#
|
9
|
+
# @param [#to_s] domain The domain id or domain name.
|
10
|
+
# @param [Hash] options
|
11
|
+
#
|
12
|
+
# @return [Array<Struct::Certificate>]
|
13
|
+
# @raise [RecordNotFound]
|
14
|
+
# @raise [RequestError] When the request fails.
|
15
|
+
def list(domain, options = {})
|
16
|
+
response = client.get("v1/domains/#{domain}/certificates", options)
|
17
|
+
|
18
|
+
response.map { |r| Struct::Certificate.new(r["certificate"]) }
|
19
|
+
end
|
20
|
+
|
21
|
+
# Gets a certificate for a domain.
|
22
|
+
#
|
23
|
+
# @see http://developer.dnsimple.com/domains/certificates/#get
|
24
|
+
#
|
25
|
+
# @param [#to_s] domain The domain id or domain name.
|
26
|
+
# @param [Fixnum] certificate_id The certificate ID.
|
27
|
+
#
|
28
|
+
# @return [Struct::Certificate]
|
29
|
+
# @raise [RecordNotFound]
|
30
|
+
# @raise [RequestError] When the request fails.
|
31
|
+
def find(domain, certificate_id)
|
32
|
+
response = client.get("v1/domains/#{domain}/certificates/#{certificate_id}")
|
33
|
+
|
34
|
+
Struct::Certificate.new(response["certificate"])
|
35
|
+
end
|
36
|
+
|
37
|
+
# Purchases a certificate under the given domain with the given name.
|
38
|
+
#
|
39
|
+
# The name will be appended to the domain name, and thus should only be the subdomain part.
|
40
|
+
#
|
41
|
+
# Invoking this method DNSimple will immediately charge
|
42
|
+
# your credit card on file at DNSimple for the full certificate price.
|
43
|
+
#
|
44
|
+
# For wildcard certificates an asterisk must appear in the name.
|
45
|
+
#
|
46
|
+
# @example Purchase a single-hostname certificate
|
47
|
+
# Dnsimple::Certificate.purchase(domain, 'www', contact)
|
48
|
+
#
|
49
|
+
# @example Purchase a wildcard certificate
|
50
|
+
# Dnsimple::Certificate.purchase(domain, '*', contact)
|
51
|
+
#
|
52
|
+
# @param [#to_s] domain The domain id or domain name.
|
53
|
+
# @param [String] name The certificate name.
|
54
|
+
# @param [Fixnum] contact_id The ID of the contact associated to the certificate.
|
55
|
+
#
|
56
|
+
# @return [Struct::Certificate]
|
57
|
+
# @raise [RecordNotFound]
|
58
|
+
# @raise [RequestError] When the request fails.
|
59
|
+
def purchase(domain, name, contact_id, options = {})
|
60
|
+
options = Extra.deep_merge(options, { certificate: { name: name, contact_id: contact_id }})
|
61
|
+
response = client.post("v1/domains/#{domain}/certificates", options)
|
62
|
+
|
63
|
+
Struct::Certificate.new(response["certificate"])
|
64
|
+
end
|
65
|
+
|
66
|
+
# Configures a certificate.
|
67
|
+
#
|
68
|
+
# @param [#to_s] domain The domain id or domain name.
|
69
|
+
# @param [Fixnum] certificate_id The certificate ID.
|
70
|
+
#
|
71
|
+
# @return [Struct::Certificate]
|
72
|
+
# @raise [RecordNotFound]
|
73
|
+
# @raise [RequestError] When the request fails.
|
74
|
+
def configure(domain, certificate_id)
|
75
|
+
response = client.put("v1/domains/#{domain}/certificates/#{certificate_id}/configure")
|
76
|
+
|
77
|
+
Struct::Certificate.new(response["certificate"])
|
78
|
+
end
|
79
|
+
|
80
|
+
# Submits a certificate for approval.
|
81
|
+
#
|
82
|
+
# @param [#to_s] domain The domain id or domain name.
|
83
|
+
# @param [Fixnum] certificate_id The certificate ID.
|
84
|
+
# @param [Fixnum] email The approver email.
|
85
|
+
#
|
86
|
+
# @return [Struct::Certificate]
|
87
|
+
# @raise [RecordNotFound]
|
88
|
+
# @raise [RequestError] When the request fails.
|
89
|
+
def submit(domain, certificate_id, email)
|
90
|
+
options = { certificate: { approver_email: email }}
|
91
|
+
response = client.put("v1/domains/#{domain}/certificates/#{certificate_id}/submit", options)
|
92
|
+
|
93
|
+
Struct::Certificate.new(response["certificate"])
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|