sparqcode-dnsimple-ruby 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/.bundle/config +3 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +71 -0
  5. data/LICENSE +22 -0
  6. data/README +125 -0
  7. data/README.rdoc +125 -0
  8. data/README.textile +161 -0
  9. data/Rakefile +33 -0
  10. data/VERSION +1 -0
  11. data/bin/dnsimple +4 -0
  12. data/bin/dnsimple.rb +153 -0
  13. data/dnsimple-ruby.gemspec +191 -0
  14. data/features/README +12 -0
  15. data/features/cli/certificates/purchase_certificate.feature +10 -0
  16. data/features/cli/contacts/create_contact.feature +10 -0
  17. data/features/cli/domains/check_domain.feature +10 -0
  18. data/features/cli/domains/create_domain.feature +10 -0
  19. data/features/cli/domains/delete_domain.feature +11 -0
  20. data/features/cli/domains/register_domain.feature +10 -0
  21. data/features/cli/records/create_ptr_record.feature +11 -0
  22. data/features/cli/records/create_record.feature +12 -0
  23. data/features/cli/records/delete_record.feature +14 -0
  24. data/features/cli/templates/apply_template.feature +11 -0
  25. data/features/step_definitions/certificate_steps.rb +3 -0
  26. data/features/step_definitions/cli_steps.rb +8 -0
  27. data/features/step_definitions/domain_steps.rb +32 -0
  28. data/features/step_definitions/record_steps.rb +38 -0
  29. data/features/step_definitions/template_steps.rb +9 -0
  30. data/features/support/env.rb +17 -0
  31. data/fixtures/vcr_cassettes/DNSimple_Certificate/_all.yml +44 -0
  32. data/fixtures/vcr_cassettes/DNSimple_Certificate/_purchase.yml +44 -0
  33. data/fixtures/vcr_cassettes/DNSimple_Certificate/_submit.yml +44 -0
  34. data/fixtures/vcr_cassettes/DNSimple_Contact/a_new_contact.yml +42 -0
  35. data/fixtures/vcr_cassettes/DNSimple_Contact/an_existing_contact.yml +42 -0
  36. data/fixtures/vcr_cassettes/DNSimple_Domain/_all.yml +130 -0
  37. data/fixtures/vcr_cassettes/DNSimple_Domain/applying_templates.yml +216 -0
  38. data/fixtures/vcr_cassettes/DNSimple_Domain/creating_a_new_domain.yml +44 -0
  39. data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_id.yml +44 -0
  40. data/fixtures/vcr_cassettes/DNSimple_Domain/finding_an_existing_domain/by_name.yml +44 -0
  41. data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_a_new_registrant_contact.yml +44 -0
  42. data/fixtures/vcr_cassettes/DNSimple_Domain/registration/with_an_existing_contact.yml +44 -0
  43. data/fixtures/vcr_cassettes/DNSimple_Domain/setting_name_servers.yml +30 -0
  44. data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_ca.yml +40 -0
  45. data/fixtures/vcr_cassettes/DNSimple_ExtendedAttribute/list_extended_attributes/for_com.yml +40 -0
  46. data/fixtures/vcr_cassettes/DNSimple_Record/_all.yml +173 -0
  47. data/fixtures/vcr_cassettes/DNSimple_Record/creating_a_new_record.yml +44 -0
  48. data/fixtures/vcr_cassettes/DNSimple_Record/find_a_record.yml +44 -0
  49. data/fixtures/vcr_cassettes/DNSimple_Template/a_template.yml +44 -0
  50. data/fixtures/vcr_cassettes/DNSimple_User/_me.yml +42 -0
  51. data/lib/dnsimple.rb +19 -0
  52. data/lib/dnsimple/certificate.rb +158 -0
  53. data/lib/dnsimple/cli.rb +122 -0
  54. data/lib/dnsimple/client.rb +74 -0
  55. data/lib/dnsimple/command.rb +10 -0
  56. data/lib/dnsimple/commands/add_service.rb +16 -0
  57. data/lib/dnsimple/commands/add_template_record.rb +18 -0
  58. data/lib/dnsimple/commands/apply_template.rb +15 -0
  59. data/lib/dnsimple/commands/check_domain.rb +11 -0
  60. data/lib/dnsimple/commands/clear_domain.rb +16 -0
  61. data/lib/dnsimple/commands/create_contact.rb +21 -0
  62. data/lib/dnsimple/commands/create_domain.rb +16 -0
  63. data/lib/dnsimple/commands/create_record.rb +20 -0
  64. data/lib/dnsimple/commands/create_template.rb +14 -0
  65. data/lib/dnsimple/commands/delete_contact.rb +14 -0
  66. data/lib/dnsimple/commands/delete_domain.rb +14 -0
  67. data/lib/dnsimple/commands/delete_record.rb +16 -0
  68. data/lib/dnsimple/commands/delete_template.rb +13 -0
  69. data/lib/dnsimple/commands/delete_template_record.rb +16 -0
  70. data/lib/dnsimple/commands/describe_certificate.rb +34 -0
  71. data/lib/dnsimple/commands/describe_contact.rb +25 -0
  72. data/lib/dnsimple/commands/describe_domain.rb +14 -0
  73. data/lib/dnsimple/commands/describe_record.rb +16 -0
  74. data/lib/dnsimple/commands/describe_service.rb +12 -0
  75. data/lib/dnsimple/commands/describe_user.rb +18 -0
  76. data/lib/dnsimple/commands/list_applied_services.rb +16 -0
  77. data/lib/dnsimple/commands/list_available_services.rb +16 -0
  78. data/lib/dnsimple/commands/list_certificates.rb +15 -0
  79. data/lib/dnsimple/commands/list_contacts.rb +13 -0
  80. data/lib/dnsimple/commands/list_domains.rb +13 -0
  81. data/lib/dnsimple/commands/list_extended_attributes.rb +25 -0
  82. data/lib/dnsimple/commands/list_records.rb +21 -0
  83. data/lib/dnsimple/commands/list_services.rb +14 -0
  84. data/lib/dnsimple/commands/list_template_records.rb +17 -0
  85. data/lib/dnsimple/commands/list_templates.rb +13 -0
  86. data/lib/dnsimple/commands/purchase_certificate.rb +19 -0
  87. data/lib/dnsimple/commands/register_domain.rb +33 -0
  88. data/lib/dnsimple/commands/remove_service.rb +14 -0
  89. data/lib/dnsimple/commands/submit_certificate.rb +19 -0
  90. data/lib/dnsimple/commands/transfer_domain.rb +21 -0
  91. data/lib/dnsimple/commands/update_contact.rb +25 -0
  92. data/lib/dnsimple/commands/update_record.rb +23 -0
  93. data/lib/dnsimple/contact.rb +181 -0
  94. data/lib/dnsimple/domain.rb +246 -0
  95. data/lib/dnsimple/error.rb +32 -0
  96. data/lib/dnsimple/extended_attribute.rb +73 -0
  97. data/lib/dnsimple/record.rb +128 -0
  98. data/lib/dnsimple/service.rb +58 -0
  99. data/lib/dnsimple/template.rb +91 -0
  100. data/lib/dnsimple/template_record.rb +103 -0
  101. data/lib/dnsimple/transfer_order.rb +45 -0
  102. data/lib/dnsimple/user.rb +44 -0
  103. data/spec/README +10 -0
  104. data/spec/certificate_spec.rb +46 -0
  105. data/spec/command_spec.rb +19 -0
  106. data/spec/commands/add_service_spec.rb +29 -0
  107. data/spec/commands/create_record_spec.rb +23 -0
  108. data/spec/commands/list_records_spec.rb +34 -0
  109. data/spec/commands/purchase_certificate_spec.rb +24 -0
  110. data/spec/commands/submit_certificate_spec.rb +19 -0
  111. data/spec/contact_spec.rb +35 -0
  112. data/spec/domain_spec.rb +97 -0
  113. data/spec/extended_attributes_spec.rb +19 -0
  114. data/spec/record_spec.rb +59 -0
  115. data/spec/spec_helper.rb +22 -0
  116. data/spec/template_spec.rb +11 -0
  117. data/spec/user_spec.rb +23 -0
  118. metadata +353 -0
@@ -0,0 +1,32 @@
1
+ module DNSimple
2
+ class Error < StandardError
3
+ end
4
+
5
+ class DomainError < DNSimple::Error
6
+ def initialize(domain, messages)
7
+ @domain = domain
8
+ @messages = messages
9
+ super "An error occurred: #{messages}"
10
+ end
11
+ end
12
+
13
+ class RecordExists < DomainError
14
+ def initialize(domain, message)
15
+ super(domain, message)
16
+ end
17
+ end
18
+
19
+ class RecordNotFound < DNSimple::Error; end
20
+
21
+ class AuthenticationFailed < DNSimple::Error
22
+ def initialize(message="Authentication failed")
23
+ super(message)
24
+ end
25
+ end
26
+
27
+ class UserNotFound < DNSimple::Error; end
28
+
29
+ class CertificateExists < DNSimple::Error; end
30
+
31
+ class CertificateNotFound < DNSimple::Error; end
32
+ end
@@ -0,0 +1,73 @@
1
+ module DNSimple #:nodoc:
2
+ # Used for domains that require extended attributes.
3
+ class ExtendedAttribute
4
+ # An option for an extended attribute
5
+ class Option
6
+ # The option name
7
+ attr_accessor :title
8
+
9
+ # The option value
10
+ attr_accessor :value
11
+
12
+ # A long description of the option
13
+ attr_accessor :description
14
+
15
+ #:nodoc:
16
+ def initialize(attributes)
17
+ attributes.each do |key, value|
18
+ m = "#{key}=".to_sym
19
+ self.send(m, value) if self.respond_to?(m)
20
+ end
21
+ end
22
+ end
23
+
24
+ include HTTParty
25
+
26
+ # The extended attribute name
27
+ attr_accessor :name
28
+
29
+ # A description of the extended attribute
30
+ attr_accessor :description
31
+
32
+ # Boolean indicating if the extended attribute is required
33
+ attr_accessor :required
34
+
35
+ #:nodoc:
36
+ def initialize(attributes)
37
+ attributes.each do |key, value|
38
+ m = "#{key}=".to_sym
39
+ self.send(m, value) if self.respond_to?(m)
40
+ end
41
+ end
42
+
43
+ # An array of options for the extended attribute
44
+ def options
45
+ @options ||= []
46
+ end
47
+
48
+ def options=(opts)
49
+ @options = []
50
+ opts.each do |opt|
51
+ @options << Option.new(opt)
52
+ end
53
+ end
54
+
55
+ # Find the extended attributes for the given TLD
56
+ def self.find(tld, options={})
57
+ options.merge!({:basic_auth => Client.credentials})
58
+
59
+ response = self.get("#{Client.base_uri}/extended_attributes/#{tld}.json", options)
60
+
61
+ pp response if Client.debug?
62
+
63
+ case response.code
64
+ when 200
65
+ response.map { |r| ExtendedAttribute.new(r) }
66
+ when 401
67
+ raise RuntimeError, "Authentication failed"
68
+ else
69
+ raise RuntimeError, "Error: #{response.code}"
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,128 @@
1
+ module DNSimple
2
+ class Record
3
+ include HTTParty
4
+
5
+ attr_accessor :id
6
+
7
+ attr_accessor :domain
8
+
9
+ attr_accessor :name
10
+
11
+ attr_accessor :content
12
+
13
+ attr_accessor :record_type
14
+
15
+ attr_accessor :ttl
16
+
17
+ attr_accessor :prio
18
+
19
+ #:nodoc:
20
+ def initialize(attributes)
21
+ attributes.each do |key, value|
22
+ m = "#{key}=".to_sym
23
+ self.send(m, value) if self.respond_to?(m)
24
+ end
25
+ end
26
+
27
+ def fqdn
28
+ [name, domain.name].delete_if { |v| v !~ DNSimple::BLANK_REGEX }.join(".")
29
+ end
30
+
31
+ def save(options={})
32
+ record_hash = {}
33
+ %w(name content ttl prio).each do |attribute|
34
+ record_hash[DNSimple::Record.resolve(attribute)] = self.send(attribute)
35
+ end
36
+
37
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
38
+ options.merge!(:body => {:record => record_hash})
39
+
40
+ response = self.class.put("#{DNSimple::Client.base_uri}/domains/#{domain.id}/records/#{id}.json", options)
41
+
42
+ pp response if DNSimple::Client.debug?
43
+
44
+ case response.code
45
+ when 200
46
+ return self
47
+ when 401
48
+ raise DNSimple::AuthenticationFailed
49
+ else
50
+ raise DNSimple::Error, "Failed to update record: #{response.inspect}"
51
+ end
52
+ end
53
+
54
+ def delete(options={})
55
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
56
+ self.class.delete("#{DNSimple::Client.base_uri}/domains/#{domain.id}/records/#{id}", options)
57
+ end
58
+ alias :destroy :delete
59
+
60
+ def self.resolve(name)
61
+ aliases = {
62
+ 'priority' => 'prio',
63
+ 'time-to-live' => 'ttl'
64
+ }
65
+ aliases[name] || name
66
+ end
67
+
68
+ def self.create(domain, name, record_type, content, options={})
69
+ record_hash = {:name => name, :record_type => record_type, :content => content}
70
+ record_hash[:ttl] = options.delete(:ttl) || 3600
71
+ record_hash[:prio] = options.delete(:priority)
72
+ record_hash[:prio] = options.delete(:prio) || ''
73
+
74
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
75
+ options.merge!({:body => {:record => record_hash}})
76
+
77
+ response = self.post("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records", options)
78
+
79
+ pp response if DNSimple::Client.debug?
80
+
81
+ case response.code
82
+ when 201
83
+ return DNSimple::Record.new({:domain => domain}.merge(response["record"]))
84
+ when 401
85
+ raise DNSimple::AuthenticationFailed
86
+ when 406
87
+ raise DNSimple::RecordExists.new("#{name}.#{domain.name}", response["errors"])
88
+ else
89
+ raise DNSimple::Error, "Failed to create #{name}.#{domain.name}: #{response["errors"]}"
90
+ end
91
+ end
92
+
93
+ def self.find(domain, id, options={})
94
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
95
+ response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records/#{id}", options)
96
+
97
+ pp response if DNSimple::Client.debug?
98
+
99
+ case response.code
100
+ when 200
101
+ return DNSimple::Record.new({:domain => domain}.merge(response["record"]))
102
+ when 401
103
+ raise DNSimple::AuthenticationFailed
104
+ when 404
105
+ raise DNSimple::RecordNotFound, "Could not find record #{id} for domain #{domain.name}"
106
+ else
107
+ raise DNSimple::Error, "Failed to find domain #{domain.name}/#{id}: #{response["errors"]}"
108
+ end
109
+ end
110
+
111
+ def self.all(domain, options={})
112
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
113
+ response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/records", options)
114
+
115
+ pp response if DNSimple::Client.debug?
116
+
117
+ case response.code
118
+ when 200
119
+ response.map { |r| DNSimple::Record.new({:domain => domain}.merge(r["record"])) }
120
+ when 401
121
+ raise DNSimple::AuthenticationFailed, "Authentication failed"
122
+ else
123
+ raise DNSimple::Error, "Error listing domains: #{response.code}"
124
+ end
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,58 @@
1
+ module DNSimple #:nodoc:
2
+ # Class representing a service that can be applied to a domain
3
+ class Service
4
+ include HTTParty
5
+
6
+ attr_accessor :id
7
+
8
+ attr_accessor :name
9
+
10
+ attr_accessor :short_name
11
+
12
+ attr_accessor :description
13
+
14
+ #:nodoc:
15
+ def initialize(attributes)
16
+ attributes.each do |key, value|
17
+ m = "#{key}=".to_sym
18
+ self.send(m, value) if self.respond_to?(m)
19
+ end
20
+ end
21
+
22
+ # Find a service by its ID or short name
23
+ def self.find(id_or_short_name, options={})
24
+ options.merge!({:basic_auth => Client.credentials})
25
+ response = self.get("#{Client.base_uri}/services/#{id_or_short_name}.json", options)
26
+
27
+ pp response if Client.debug?
28
+
29
+ case response.code
30
+ when 200
31
+ return Service.new(response["service"])
32
+ when 401
33
+ raise RuntimeError, "Authentication failed"
34
+ when 404
35
+ raise RuntimeError, "Could not find service #{id_or_short_name}"
36
+ else
37
+ raise DNSimple::Error.new(id_or_short_name, response["errors"])
38
+ end
39
+ end
40
+
41
+ # Get all of the services that can be applied to a domain
42
+ def self.all(options={})
43
+ options.merge!({:basic_auth => Client.credentials})
44
+ response = self.get("#{Client.base_uri}/services.json", options)
45
+
46
+ pp response if Client.debug?
47
+
48
+ case response.code
49
+ when 200
50
+ response.map { |r| Service.new(r["service"]) }
51
+ when 401
52
+ raise RuntimeError, "Authentication failed"
53
+ else
54
+ raise RuntimeError, "Error: #{response.code}"
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,91 @@
1
+ module DNSimple
2
+ class Template
3
+ include HTTParty
4
+
5
+ # The template ID in DNSimple
6
+ attr_accessor :id
7
+
8
+ # The template name
9
+ attr_accessor :name
10
+
11
+ # The template short name
12
+ attr_accessor :short_name
13
+
14
+ # The template description
15
+ attr_accessor :description
16
+
17
+ #:nodoc:
18
+ def initialize(attributes)
19
+ attributes.each do |key, value|
20
+ m = "#{key}=".to_sym
21
+ self.send(m, value) if self.respond_to?(m)
22
+ end
23
+ end
24
+
25
+ # Delete the template from DNSimple. WARNING: this cannot
26
+ # be undone.
27
+ def delete(options={})
28
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
29
+ self.class.delete("#{Client.base_uri}/templates/#{id}", options)
30
+ end
31
+ alias :destroy :delete
32
+
33
+ def self.create(name, short_name, description=nil, options={})
34
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
35
+ template_hash = {
36
+ :name => name,
37
+ :short_name => short_name,
38
+ :description => description
39
+ }
40
+
41
+ options.merge!(:body => {:dns_template => template_hash})
42
+
43
+ response = self.post("#{Client.base_uri}/templates", options)
44
+
45
+ pp response if Client.debug?
46
+
47
+ case response.code
48
+ when 201
49
+ return Template.new(response["dns_template"])
50
+ when 401
51
+ raise RuntimeError, "Authentication failed"
52
+ else
53
+ raise DNSimple::Error.new(name, response["errors"])
54
+ end
55
+ end
56
+
57
+ def self.find(id_or_short_name, options={})
58
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
59
+ response = self.get("#{Client.base_uri}/templates/#{id_or_short_name}", options)
60
+
61
+ pp response if Client.debug?
62
+
63
+ case response.code
64
+ when 200
65
+ return Template.new(response["dns_template"])
66
+ when 401
67
+ raise RuntimeError, "Authentication failed"
68
+ when 404
69
+ raise RuntimeError, "Could not find template #{id_or_short_name}"
70
+ else
71
+ raise DNSimple::Error.new(id_or_short_name, response["errors"])
72
+ end
73
+ end
74
+
75
+ def self.all(options={})
76
+ options.merge!(DNSimple::Client.standard_options_with_credentials)
77
+ response = self.get("#{Client.base_uri}/templates", options)
78
+
79
+ pp response if Client.debug?
80
+
81
+ case response.code
82
+ when 200
83
+ response.map { |r| Template.new(r["dns_template"]) }
84
+ when 401
85
+ raise RuntimeError, "Authentication failed"
86
+ else
87
+ raise RuntimeError, "Error: #{response.code}"
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,103 @@
1
+ module DNSimple #:nodoc:
2
+ # A single record in a template
3
+ class TemplateRecord
4
+ include HTTParty
5
+
6
+ # The id of the template record
7
+ attr_accessor :id
8
+
9
+ # The template the record belongs to
10
+ attr_accessor :template
11
+
12
+ # The name the record points to. This may be blank.
13
+ attr_accessor :name
14
+
15
+ # The content for the record.
16
+ attr_accessor :content
17
+
18
+ # The record type
19
+ attr_accessor :record_type
20
+
21
+ # The time-to-live
22
+ attr_accessor :ttl
23
+
24
+ # The priority (only for MX records)
25
+ attr_accessor :prio
26
+
27
+ #:nodoc:
28
+ def initialize(attributes)
29
+ attributes.each do |key, value|
30
+ m = "#{key}=".to_sym
31
+ self.send(m, value) if self.respond_to?(m)
32
+ end
33
+ end
34
+
35
+ def delete(options={})
36
+ options.merge!(:basic_auth => Client.credentials)
37
+ self.class.delete("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", options)
38
+ end
39
+ alias :destroy :delete
40
+
41
+ def self.create(short_name, name, record_type, content, options={})
42
+ template = Template.find(short_name)
43
+
44
+ record_hash = {:name => name, :record_type => record_type, :content => content}
45
+ record_hash[:ttl] = options.delete(:ttl) || 3600
46
+ record_hash[:prio] = options.delete(:prio) || ''
47
+
48
+ options.merge!({:query => {:dns_template_record => record_hash}})
49
+ options.merge!({:basic_auth => Client.credentials})
50
+
51
+ response = self.post("#{Client.base_uri}/templates/#{template.id}/template_records.json", options)
52
+
53
+ pp response if Client.debug?
54
+
55
+ case response.code
56
+ when 201
57
+ return TemplateRecord.new({:template => template}.merge(response["dns_template_record"]))
58
+ when 401
59
+ raise RuntimeError, "Authentication failed"
60
+ else
61
+ raise DNSimple::Error.new("#{name}", response["errors"])
62
+ end
63
+ end
64
+
65
+ def self.find(short_name, id, options={})
66
+ template = Template.find(short_name)
67
+ options.merge!(:basic_auth => Client.credentials)
68
+ response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records/#{id}.json", options)
69
+
70
+ pp response if Client.debug?
71
+
72
+ case response.code
73
+ when 200
74
+ return TemplateRecord.new({:template => template}.merge(response["dns_template_record"]))
75
+ when 401
76
+ raise RuntimeError, "Authentication failed"
77
+ when 404
78
+ raise RuntimeError, "Could not find template record #{id} for template #{short_name}"
79
+ end
80
+ end
81
+
82
+ # Get all of the template records for the template with the
83
+ # given short name.
84
+ def self.all(short_name, options={})
85
+ template = Template.find(short_name)
86
+ options.merge!({:basic_auth => Client.credentials})
87
+ response = self.get("#{Client.base_uri}/templates/#{template.id}/template_records.json", options)
88
+
89
+ pp response if Client.debug?
90
+
91
+ case response.code
92
+ when 200
93
+ response.map { |r| TemplateRecord.new({:template => template}.merge(r["dns_template_record"])) }
94
+ when 401
95
+ raise RuntimeError, "Authentication failed"
96
+ else
97
+ raise RuntimeError, "Error: #{response.code}"
98
+ end
99
+ end
100
+ end
101
+
102
+
103
+ end