dnsimple 3.0.0.pre.beta2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -0
  3. data/.rubocop_dnsimple.yml +216 -0
  4. data/.rubocop_todo.yml +14 -0
  5. data/CHANGELOG.md +16 -1
  6. data/Gemfile +1 -0
  7. data/Rakefile +8 -3
  8. data/lib/dnsimple/client.rb +9 -12
  9. data/lib/dnsimple/client/clients.rb +36 -2
  10. data/lib/dnsimple/client/contacts.rb +6 -6
  11. data/lib/dnsimple/client/domains.rb +5 -5
  12. data/lib/dnsimple/client/identity.rb +2 -2
  13. data/lib/dnsimple/client/oauth.rb +2 -2
  14. data/lib/dnsimple/client/registrar.rb +1 -1
  15. data/lib/dnsimple/client/registrar_auto_renewal.rb +2 -2
  16. data/lib/dnsimple/client/registrar_delegation.rb +49 -0
  17. data/lib/dnsimple/client/registrar_whois_privacy.rb +1 -1
  18. data/lib/dnsimple/client/services.rb +68 -0
  19. data/lib/dnsimple/client/templates.rb +139 -0
  20. data/lib/dnsimple/client/tlds.rb +3 -3
  21. data/lib/dnsimple/client/webhooks.rb +4 -4
  22. data/lib/dnsimple/client/zones.rb +2 -2
  23. data/lib/dnsimple/client/zones_records.rb +1 -1
  24. data/lib/dnsimple/default.rb +2 -2
  25. data/lib/dnsimple/error.rb +14 -1
  26. data/lib/dnsimple/struct.rb +3 -1
  27. data/lib/dnsimple/struct/contact.rb +2 -2
  28. data/lib/dnsimple/struct/extended_attribute.rb +5 -1
  29. data/lib/dnsimple/struct/service.rb +64 -0
  30. data/lib/dnsimple/struct/template.rb +22 -0
  31. data/lib/dnsimple/struct/tld.rb +1 -1
  32. data/lib/dnsimple/version.rb +1 -1
  33. data/spec/dnsimple/client/client_service_spec.rb +6 -6
  34. data/spec/dnsimple/client/contacts_spec.rb +30 -30
  35. data/spec/dnsimple/client/domains_email_forwards_spec.rb +25 -25
  36. data/spec/dnsimple/client/domains_spec.rb +27 -27
  37. data/spec/dnsimple/client/identity_spec.rb +8 -8
  38. data/spec/dnsimple/client/oauth_spec.rb +9 -9
  39. data/spec/dnsimple/client/registrar_auto_renewal_spec.rb +13 -13
  40. data/spec/dnsimple/client/registrar_delegation_spec.rb +55 -0
  41. data/spec/dnsimple/client/registrar_spec.rb +29 -29
  42. data/spec/dnsimple/client/registrar_whois_privacy_spec.rb +16 -16
  43. data/spec/dnsimple/client/services_spec.rb +78 -0
  44. data/spec/dnsimple/client/templates_spec.rb +163 -0
  45. data/spec/dnsimple/client/tlds_spec.rb +22 -23
  46. data/spec/dnsimple/client/webhooks_spec.rb +22 -22
  47. data/spec/dnsimple/client/zones_records_spec.rb +40 -40
  48. data/spec/dnsimple/client/zones_spec.rb +12 -12
  49. data/spec/dnsimple/client_spec.rb +52 -44
  50. data/spec/dnsimple/extra_spec.rb +3 -3
  51. data/spec/fixtures.http/changeDomainDelegation/success.http +17 -0
  52. data/spec/fixtures.http/createTemplate/created.http +17 -0
  53. data/spec/fixtures.http/deleteTemplate/success.http +13 -0
  54. data/spec/fixtures.http/getDomainDelegation/success-empty.http +17 -0
  55. data/spec/fixtures.http/getDomainDelegation/success.http +17 -0
  56. data/spec/fixtures.http/getService/success.http +17 -0
  57. data/spec/fixtures.http/getTemplate/success.http +17 -0
  58. data/spec/fixtures.http/listServices/success.http +17 -0
  59. data/spec/fixtures.http/listTemplates/success.http +17 -0
  60. data/spec/fixtures.http/method-not-allowed.http +11 -0
  61. data/spec/fixtures.http/updateTemplate/success.http +17 -0
  62. metadata +41 -5
@@ -23,8 +23,8 @@ module Dnsimple
23
23
 
24
24
  Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Contact.new(r) })
25
25
  end
26
- alias :list :contacts
27
- alias :list_contacts :contacts
26
+ alias list contacts
27
+ alias list_contacts contacts
28
28
 
29
29
  # Lists ALL the contacts in the account.
30
30
  #
@@ -45,7 +45,7 @@ module Dnsimple
45
45
  def all_contacts(account_id, options = {})
46
46
  paginate(:contacts, account_id, options)
47
47
  end
48
- alias :all :all_contacts
48
+ alias all all_contacts
49
49
 
50
50
  # Creates a contact in the account.
51
51
  #
@@ -63,7 +63,7 @@ module Dnsimple
63
63
 
64
64
  Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
65
65
  end
66
- alias :create :create_contact
66
+ alias create create_contact
67
67
 
68
68
  # Gets a contact from the account.
69
69
  #
@@ -98,7 +98,7 @@ module Dnsimple
98
98
 
99
99
  Dnsimple::Response.new(response, Struct::Contact.new(response["data"]))
100
100
  end
101
- alias :update :update_contact
101
+ alias update update_contact
102
102
 
103
103
  # Deletes a contact from the account.
104
104
  #
@@ -118,7 +118,7 @@ module Dnsimple
118
118
 
119
119
  Dnsimple::Response.new(response, nil)
120
120
  end
121
- alias :delete :delete_contact
121
+ alias delete delete_contact
122
122
 
123
123
  end
124
124
  end
@@ -23,8 +23,8 @@ module Dnsimple
23
23
 
24
24
  Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Domain.new(r) })
25
25
  end
26
- alias :list :domains
27
- alias :list_domains :domains
26
+ alias list domains
27
+ alias list_domains domains
28
28
 
29
29
  # Lists ALL the domains in the account.
30
30
  #
@@ -45,7 +45,7 @@ module Dnsimple
45
45
  def all_domains(account_id, options = {})
46
46
  paginate(:domains, account_id, options)
47
47
  end
48
- alias :all :all_domains
48
+ alias all all_domains
49
49
 
50
50
  # Creates a domain in the account.
51
51
  #
@@ -64,7 +64,7 @@ module Dnsimple
64
64
 
65
65
  Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
66
66
  end
67
- alias :create :create_domain
67
+ alias create create_domain
68
68
 
69
69
  # Gets a domain from the account.
70
70
  #
@@ -101,7 +101,7 @@ module Dnsimple
101
101
 
102
102
  Dnsimple::Response.new(response, nil)
103
103
  end
104
- alias :delete :delete_domain
104
+ alias delete delete_domain
105
105
 
106
106
  # Resets the domain token.
107
107
  #
@@ -15,7 +15,7 @@ module Dnsimple
15
15
  data = response["data"]
16
16
  account = data["account"] ? Struct::Account.new(data["account"]) : nil
17
17
  user = data["user"] ? Struct::User.new(data["user"]) : nil
18
- Response.new(response, { account: account, user: user })
18
+ Response.new(response, account: account, user: user)
19
19
  end
20
20
 
21
21
 
@@ -35,4 +35,4 @@ module Dnsimple
35
35
 
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -13,8 +13,8 @@ module Dnsimple
13
13
  # @return [String] The url to redirect the user to authorize.
14
14
  def exchange_authorization_for_token(code, client_id, client_secret, options = {})
15
15
  attributes = { code: code, client_id: client_id, client_secret: client_secret, grant_type: "authorization_code" }
16
- attributes[:state] = options.delete(:state) if options.has_key?(:state)
17
- attributes[:redirect_uri] = options.delete(:redirect_uri) if options.has_key?(:redirect_uri)
16
+ attributes[:state] = options.delete(:state) if options.key?(:state)
17
+ attributes[:redirect_uri] = options.delete(:redirect_uri) if options.key?(:redirect_uri)
18
18
  response = client.post(Client.versioned("/oauth/access_token"), attributes, options)
19
19
  Struct::OauthToken.new(response)
20
20
  end
@@ -60,7 +60,7 @@ module Dnsimple
60
60
  #
61
61
  # @raise [RequestError] When the request fails.
62
62
  def renew_domain(account_id, domain_name, attributes = nil, options = {})
63
- endpoint = Client.versioned("/%s/registrar/domains/%s/renew" % [account_id, domain_name])
63
+ endpoint = Client.versioned("/%s/registrar/domains/%s/renewal" % [account_id, domain_name])
64
64
  response = client.post(endpoint, attributes, options)
65
65
 
66
66
  Dnsimple::Response.new(response, Struct::Domain.new(response["data"]))
@@ -13,7 +13,7 @@ module Dnsimple
13
13
  #
14
14
  # @raise [Dnsimple::NotFoundError]
15
15
  # @raise [Dnsimple::RequestError]
16
- def enable_auto_renewal(account_id, domain_name, options={})
16
+ def enable_auto_renewal(account_id, domain_name, options = {})
17
17
  response = client.put(Client.versioned("/%s/registrar/domains/%s/auto_renewal" % [account_id, domain_name]), nil, options)
18
18
 
19
19
  Dnsimple::Response.new(response, nil)
@@ -30,7 +30,7 @@ module Dnsimple
30
30
  #
31
31
  # @raise [Dnsimple::NotFoundError]
32
32
  # @raise [Dnsimple::RequestError]
33
- def disable_auto_renewal(account_id, domain_name, options={})
33
+ def disable_auto_renewal(account_id, domain_name, options = {})
34
34
  response = client.delete(Client.versioned("/%s/registrar/domains/%s/auto_renewal" % [account_id, domain_name]), nil, options)
35
35
 
36
36
  Dnsimple::Response.new(response, nil)
@@ -0,0 +1,49 @@
1
+ module Dnsimple
2
+ class Client
3
+ module RegistrarDelegation
4
+
5
+ # Lists name servers the domain is delegating to.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/registrar/delegation/#list
8
+ #
9
+ # @example List the name servers example.com is delegating to:
10
+ # client.registrar.domain_delegation(1010, "example.com")
11
+ #
12
+ # @param [Fixnum] account_id the account ID
13
+ # @param [#to_s] domain_name the domain name to check
14
+ # @param [Hash] options
15
+ # @return [Dnsimple::Response<Array>]
16
+ #
17
+ # @raise [RequestError] When the request fails.
18
+ def domain_delegation(account_id, domain_name, options = {})
19
+ endpoint = Client.versioned("/%s/registrar/domains/%s/delegation" % [account_id, domain_name])
20
+ response = client.get(endpoint, options)
21
+
22
+ Dnsimple::Response.new(response, response["data"])
23
+ end
24
+
25
+ # Chagne name servers the domain is delegating to.
26
+ #
27
+ # @see https://developer.dnsimple.com/v2/registrar/delegation/#update
28
+ #
29
+ # @example Change the name servers example.com is delegating to:
30
+ # client.registrar.change_domain_delegation(1010, "example.com",
31
+ # ["ns1.dnsimple.com", "ns2.dnsimple.com", "ns3.dnsimple.com", "ns4.dnsimple.com"])
32
+ #
33
+ # @param [Fixnum] account_id the account ID
34
+ # @param [#to_s] domain_name the domain name to check
35
+ # @param [Array] attributes
36
+ # @param [Hash] options
37
+ # @return [Dnsimple::Response<Array>]
38
+ #
39
+ # @raise [RequestError] When the request fails.
40
+ def change_domain_delegation(account_id, domain_name, attributes, options = {})
41
+ endpoint = Client.versioned("/%s/registrar/domains/%s/delegation" % [account_id, domain_name])
42
+ response = client.put(endpoint, attributes, options)
43
+
44
+ Dnsimple::Response.new(response, response["data"])
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -7,7 +7,7 @@ module Dnsimple
7
7
  # @see https://developer.dnsimple.com/v2/registrar/whois-privacy/#get
8
8
  #
9
9
  # @example Get the whois privacy for "example.com":
10
- # client.registrar.get_whois_privacy(1010, "example.com")
10
+ # client.registrar.whois_privacy(1010, "example.com")
11
11
  #
12
12
  # @param [Fixnum] account_id the account ID
13
13
  # @param [#to_s] domain_name the domain name
@@ -0,0 +1,68 @@
1
+ module Dnsimple
2
+ class Client
3
+ module Services
4
+
5
+ # Lists the available one-click services.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/services/#list
8
+ #
9
+ # @example List one-click services:
10
+ # client.services.list_services
11
+ #
12
+ # @param [Hash] options
13
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Service>]
14
+ #
15
+ # @raise [RequestError] When the request fails.
16
+ def services(options = {})
17
+ endpoint = Client.versioned("/services")
18
+ response = client.get(endpoint, options)
19
+
20
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Service.new(r) })
21
+ end
22
+ alias list services
23
+ alias list_services services
24
+
25
+ # Lists ALL the available one-click services.
26
+ #
27
+ # This method is similar to {#services}, but instead of returning the results of a specific page
28
+ # it iterates all the pages and returns the entire collection.
29
+ #
30
+ # Please use this method carefully, as fetching the entire collection will increase the number of
31
+ # requests you send to the API server and you may eventually risk to hit the throttle limit.
32
+ #
33
+ # @example List all the one-click services:
34
+ # client.services.all_services
35
+ #
36
+ # @see https://developer.dnsimple.com/v2/services/#list
37
+ # @see #services
38
+ #
39
+ # @param [Hash] options
40
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Service>]
41
+ #
42
+ # @raise [RequestError] When the request fails.
43
+ def all_services(options = {})
44
+ paginate(:services, options)
45
+ end
46
+ alias all all_services
47
+
48
+ # Gets the service with specified ID.
49
+ #
50
+ # @see https://developer.dnsimple.com/v2/services/#get
51
+ #
52
+ # @example Get service 43:
53
+ # client.services.service(43)
54
+ #
55
+ # @param [#to_s] service_id The service ID
56
+ # @param [Hash] options
57
+ # @return [Dnsimple::Response<Dnsimple::Struct::Service>]
58
+ #
59
+ # @raise [RequestError] When the request fails.
60
+ def service(service_id, options = {})
61
+ endpoint = Client.versioned("/services/%s" % [service_id])
62
+ response = client.get(endpoint, options)
63
+
64
+ Dnsimple::Response.new(response, Struct::Service.new(response["data"]))
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,139 @@
1
+ module Dnsimple
2
+ class Client
3
+ module Templates
4
+
5
+ # Lists the templates in the account.
6
+ #
7
+ # @see https://developer.dnsimple.com/v2/templates/#list
8
+ #
9
+ # @example List the templates for account 1010:
10
+ # client.templates.list_templates(1010)
11
+ #
12
+ # @param [Fixnum] account_id the account ID
13
+ # @param [Hash] options
14
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Template>]
15
+ #
16
+ # @raise [RequestError] When the request fails.
17
+ def templates(account_id, options = {})
18
+ endpoint = Client.versioned("/%s/templates" % [account_id])
19
+ response = client.get(endpoint, options)
20
+
21
+ Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Template.new(r) })
22
+ end
23
+ alias list templates
24
+ alias list_templates templates
25
+
26
+ # Lists ALL the templates in the account.
27
+ #
28
+ # This method is similar to {#templates}, but instead of returning the results of a specific page
29
+ # it iterates all the pages and returns the entire collection.
30
+ #
31
+ # Please use this method carefully, as fetching the entire collection will increase the number of
32
+ # requests you send to the API server and you may eventually risk to hit the throttle limit.
33
+ #
34
+ # @example List all the templates for account 1010:
35
+ # client.templates.all_templates(1010)
36
+ #
37
+ # @see https://developer.dnsimple.com/v2/templates/#list
38
+ # @see #templates
39
+ #
40
+ # @param [Fixnum] account_id the account ID
41
+ # @param [Hash] options
42
+ # @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Template>]
43
+ #
44
+ # @raise [RequestError] When the request fails.
45
+ def all_templates(account_id, options = {})
46
+ paginate(:templates, account_id, options)
47
+ end
48
+ alias all all_templates
49
+
50
+ # Creates a template in the account.
51
+ #
52
+ # @see https://developer.dnsimple.com/v2/templates/#create
53
+ #
54
+ # @example Creating a template:
55
+ # client.templates.create_template(1010, name: "Pi", short_name: "pi", description: "Pi template")
56
+ #
57
+ # @param [Fixnum] account_id the account ID
58
+ # @param [Hash] attributes
59
+ # @param [Hash] options
60
+ # @return [Dnsimple::Response<Dnsimple::Struct::Template>]
61
+ #
62
+ # @raise [Dnsimple::RequestError]
63
+ def create_template(account_id, attributes, options = {})
64
+ endpoint = Client.versioned("/%s/templates" % [account_id])
65
+ response = client.post(endpoint, attributes, options)
66
+
67
+ Dnsimple::Response.new(response, Struct::Template.new(response["data"]))
68
+ end
69
+ alias create create_template
70
+
71
+ # Gets the template with specified ID.
72
+ #
73
+ # @see https://developer.dnsimple.com/v2/templates/#get
74
+ #
75
+ # @example Get template 5401 in account 1010:
76
+ # client.templates.template(1010, 5401)
77
+ #
78
+ # @param [Fixnum] account_id the account ID
79
+ # @param [#to_s] template_id The template ID
80
+ # @param [Hash] options
81
+ # @return [Dnsimple::Response<Dnsimple::Struct::Template>]
82
+ #
83
+ # @raise [RequestError] When the request fails.
84
+ def template(account_id, template_id, options = {})
85
+ endpoint = Client.versioned("/%s/templates/%s" % [account_id, template_id])
86
+ response = client.get(endpoint, options)
87
+
88
+ Dnsimple::Response.new(response, Struct::Template.new(response["data"]))
89
+ end
90
+
91
+ # Updates template with specified ID with provided data.
92
+ #
93
+ # @see https://developer.dnsimple.com/v2/templates/#update
94
+ #
95
+ # @example Change the name of template 1 in account 1010:
96
+ # client.templates.update_template(1010, 1, name: "New name")
97
+ #
98
+ # @param [Fixnum] account_iduthe account ID
99
+ # @param [#to_s] template_id The template ID
100
+ # @param [Hash] attributes
101
+ # @param [Hash] options
102
+ # @return [Dnsimple::Response<Dnsimple::Struct::Template>]
103
+ #
104
+ # @raise [RequestError] When the request fails.
105
+ def update_template(account_id, template_id, attributes, options = {})
106
+ endpoint = Client.versioned("/%s/templates/%s" % [account_id, template_id])
107
+ response = client.patch(endpoint, attributes, options)
108
+
109
+ Dnsimple::Response.new(response, Struct::Template.new(response["data"]))
110
+ end
111
+ alias update update_template
112
+
113
+ # Deletes a template from the account.
114
+ #
115
+ # WARNING: this cannot be undone.
116
+ #
117
+ # @see https://developer.dnsimple.com/v2/templates/#delete
118
+ #
119
+ # @example Delete template 5401 in account 1010:
120
+ # client.templates.delete_template(1010, 5401)
121
+ #
122
+ # @param [Fixnum] account_id The account ID
123
+ # @param [#to_s] template_id The template ID
124
+ # @param [Hash] options
125
+ # @return [Dnsimple::Response<nil>]
126
+ #
127
+ # @raise [Dnsimple::NotFoundError]
128
+ # @raise [Dnsimple::RequestError]
129
+ def delete_template(account_id, template_id, options = {})
130
+ endpoint = Client.versioned("/%s/templates/%s" % [account_id, template_id])
131
+ response = client.delete(endpoint, options)
132
+
133
+ Dnsimple::Response.new(response, nil)
134
+ end
135
+ alias delete delete_template
136
+
137
+ end
138
+ end
139
+ end
@@ -20,8 +20,8 @@ module Dnsimple
20
20
 
21
21
  Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Tld.new(r) })
22
22
  end
23
- alias :list :tlds
24
- alias :list_tlds :tlds
23
+ alias list tlds
24
+ alias list_tlds tlds
25
25
 
26
26
  # Lists ALL the TLDs in DNSimple.
27
27
  #
@@ -44,7 +44,7 @@ module Dnsimple
44
44
  def all_tlds(options = {})
45
45
  paginate(:tlds, options)
46
46
  end
47
- alias :all :all_tlds
47
+ alias all all_tlds
48
48
 
49
49
  # Gets a TLD's details
50
50
  #
@@ -19,8 +19,8 @@ module Dnsimple
19
19
 
20
20
  Dnsimple::CollectionResponse.new(response, response["data"].map { |r| Struct::Webhook.new(r) })
21
21
  end
22
- alias :list :webhooks
23
- alias :list_webhooks :webhooks
22
+ alias list webhooks
23
+ alias list_webhooks webhooks
24
24
 
25
25
  # Creates a webhook in the account.
26
26
  #
@@ -38,7 +38,7 @@ module Dnsimple
38
38
 
39
39
  Dnsimple::Response.new(response, Struct::Webhook.new(response["data"]))
40
40
  end
41
- alias :create :create_webhook
41
+ alias create create_webhook
42
42
 
43
43
  # Gets a webhook from the account.
44
44
  #
@@ -75,7 +75,7 @@ module Dnsimple
75
75
 
76
76
  Dnsimple::Response.new(response, nil)
77
77
  end
78
- alias :delete :delete_webhook
78
+ alias delete delete_webhook
79
79
 
80
80
  end
81
81
  end