dnsimple-ruby 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/dnsimple.rb +56 -46
- data/lib/dnsimple/cli.rb +5 -1
- data/lib/dnsimple/commands/describe_record.rb +16 -0
- data/lib/dnsimple/commands/update_record.rb +23 -0
- data/lib/dnsimple/contact.rb +6 -5
- data/lib/dnsimple/record.rb +36 -1
- metadata +7 -6
data/Rakefile
CHANGED
@@ -25,6 +25,7 @@ begin
|
|
25
25
|
gemspec.homepage = "http://github.com/aetrion/dnsimple-ruby"
|
26
26
|
gemspec.authors = ["Anthony Eden"]
|
27
27
|
gemspec.add_dependency "httparty"
|
28
|
+
gemspec.executables = 'dnsimple'
|
28
29
|
end
|
29
30
|
rescue LoadError
|
30
31
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.2
|
data/bin/dnsimple.rb
CHANGED
@@ -41,13 +41,16 @@ create [--template=short_name] domain.com # Add the given doma
|
|
41
41
|
register [--template=short_name] domain.com registrant_id \ # Register the given domain with DNSimple
|
42
42
|
[[name:value] [name:value]] # name:value pairs can be given for extended attributes
|
43
43
|
transfer domain.com registrant_id [authinfo] \ # Transfer the given domain into DNSimple
|
44
|
-
[[name:value] [name:value]]
|
44
|
+
[[name:value] [name:value] ...] # name:value pairs can be given for extended attributes
|
45
45
|
delete domain.com # Delete the given domain
|
46
46
|
apply domain.com template_short_name # Apply a template to the domain
|
47
47
|
|
48
|
+
record:describe domain.com record_id # Describe the given record
|
48
49
|
record:create [--prio=priority] domain.com name type \\
|
49
50
|
content [ttl] # Create the DNS record on the domain
|
50
51
|
record:list domain.com # List all records for the domain
|
52
|
+
record:update domain.com record_id \ # Update a specific record
|
53
|
+
[[name:value] [name:value] ...] # name:value pairs are given for updateable attributes
|
51
54
|
record:delete domain.com record_id # Delete the given domain
|
52
55
|
|
53
56
|
template:create name short_name [description] # Create a template
|
@@ -60,59 +63,66 @@ template:add_record [--prio=priority] short_name name \\
|
|
60
63
|
template:delete_record short_name template_record_id # Delete the given template record
|
61
64
|
|
62
65
|
|
66
|
+
Please see the DNSimple documentation at https://dnsimple.com/documentation/api for additional
|
67
|
+
information on the commands that are available to DNSimple customers.
|
68
|
+
|
63
69
|
EOF
|
64
70
|
end
|
65
71
|
|
66
|
-
|
72
|
+
if $0.split("/").last == 'dnsimple'
|
67
73
|
|
68
|
-
|
69
|
-
opts.on("-s", "--site [ARG]") do |site|
|
70
|
-
DNSimple::Client.base_uri = site
|
71
|
-
end
|
72
|
-
opts.on("-u", "--username [ARG]") do |username|
|
73
|
-
DNSimple::Client.username = username
|
74
|
-
end
|
75
|
-
opts.on("-p", "--password [ARG]") do |password|
|
76
|
-
DNSimple::Client.password = password
|
77
|
-
end
|
78
|
-
opts.on("-d") do
|
79
|
-
DNSimple::Client.debug = true
|
80
|
-
end
|
81
|
-
end
|
74
|
+
options = {}
|
82
75
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
options[:template] = opt
|
76
|
+
global = OptionParser.new do |opts|
|
77
|
+
opts.on("-s", "--site [ARG]") do |site|
|
78
|
+
DNSimple::Client.base_uri = site
|
87
79
|
end
|
88
|
-
|
89
|
-
|
90
|
-
opts.on("--template [ARG]") do |opt|
|
91
|
-
options[:template] = opt
|
80
|
+
opts.on("-u", "--username [ARG]") do |username|
|
81
|
+
DNSimple::Client.username = username
|
92
82
|
end
|
93
|
-
|
94
|
-
|
95
|
-
opts.on("--prio [ARG]") do |prio|
|
96
|
-
options[:prio] = prio
|
83
|
+
opts.on("-p", "--password [ARG]") do |password|
|
84
|
+
DNSimple::Client.password = password
|
97
85
|
end
|
98
|
-
|
99
|
-
|
100
|
-
opts.on("--prio [ARG]") do |prio|
|
101
|
-
options[:prio] = prio
|
86
|
+
opts.on("-d") do
|
87
|
+
DNSimple::Client.debug = true
|
102
88
|
end
|
103
|
-
end,
|
104
|
-
}
|
105
|
-
|
106
|
-
global.order!
|
107
|
-
command = ARGV.shift
|
108
|
-
if command.nil? || command == 'help'
|
109
|
-
usage
|
110
|
-
else
|
111
|
-
options_parser = subcommands[command]
|
112
|
-
options_parser.order! if options_parser
|
113
|
-
begin
|
114
|
-
cli.execute(command, ARGV, options)
|
115
|
-
rescue DNSimple::CommandNotFound => e
|
116
|
-
puts e.message
|
117
89
|
end
|
90
|
+
|
91
|
+
subcommands = {
|
92
|
+
'create' => OptionParser.new do |opts|
|
93
|
+
opts.on("--template [ARG]") do |opt|
|
94
|
+
options[:template] = opt
|
95
|
+
end
|
96
|
+
end,
|
97
|
+
'register' => OptionParser.new do |opts|
|
98
|
+
opts.on("--template [ARG]") do |opt|
|
99
|
+
options[:template] = opt
|
100
|
+
end
|
101
|
+
end,
|
102
|
+
'record:create' => OptionParser.new do |opts|
|
103
|
+
opts.on("--prio [ARG]") do |prio|
|
104
|
+
options[:prio] = prio
|
105
|
+
end
|
106
|
+
end,
|
107
|
+
'template:add_record' => OptionParser.new do |opts|
|
108
|
+
opts.on("--prio [ARG]") do |prio|
|
109
|
+
options[:prio] = prio
|
110
|
+
end
|
111
|
+
end,
|
112
|
+
}
|
113
|
+
|
114
|
+
global.order!
|
115
|
+
command = ARGV.shift
|
116
|
+
if command.nil? || command == 'help'
|
117
|
+
usage
|
118
|
+
else
|
119
|
+
options_parser = subcommands[command]
|
120
|
+
options_parser.order! if options_parser
|
121
|
+
begin
|
122
|
+
cli.execute(command, ARGV, options)
|
123
|
+
rescue DNSimple::CommandNotFound => e
|
124
|
+
puts e.message
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
118
128
|
end
|
data/lib/dnsimple/cli.rb
CHANGED
@@ -40,9 +40,11 @@ module DNSimple
|
|
40
40
|
'delete' => DNSimple::Commands::DeleteDomain,
|
41
41
|
'clear' => DNSimple::Commands::ClearDomain,
|
42
42
|
'apply' => DNSimple::Commands::ApplyTemplate,
|
43
|
-
|
43
|
+
|
44
|
+
'record:describe' => DNSimple::Commands::DescribeRecord,
|
44
45
|
'record:create' => DNSimple::Commands::CreateRecord,
|
45
46
|
'record:list' => DNSimple::Commands::ListRecords,
|
47
|
+
'record:update' => DNSimple::Commands::UpdateRecord,
|
46
48
|
'record:delete' => DNSimple::Commands::DeleteRecord,
|
47
49
|
|
48
50
|
'template:create' => DNSimple::Commands::CreateTemplate,
|
@@ -81,8 +83,10 @@ require 'dnsimple/commands/delete_domain'
|
|
81
83
|
require 'dnsimple/commands/clear_domain'
|
82
84
|
require 'dnsimple/commands/apply_template'
|
83
85
|
|
86
|
+
require 'dnsimple/commands/describe_record'
|
84
87
|
require 'dnsimple/commands/create_record'
|
85
88
|
require 'dnsimple/commands/list_records'
|
89
|
+
require 'dnsimple/commands/update_record'
|
86
90
|
require 'dnsimple/commands/delete_record'
|
87
91
|
|
88
92
|
require 'dnsimple/commands/create_template'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class DescribeRecord
|
4
|
+
def execute(args, options={})
|
5
|
+
name = args.shift
|
6
|
+
id = args.shift
|
7
|
+
record = Record.find(name, id)
|
8
|
+
puts "Record #{record.fqdn}:"
|
9
|
+
puts "\tID: #{record.id}"
|
10
|
+
puts "\tTTL: #{record.ttl}"
|
11
|
+
puts "\tPrio: #{record.prio}"
|
12
|
+
puts "\tContent: #{record.content}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class UpdateRecord
|
4
|
+
def execute(args, options={})
|
5
|
+
attributes = {}
|
6
|
+
domain_name = args.shift
|
7
|
+
id = args.shift
|
8
|
+
args.each do |arg|
|
9
|
+
name, value = arg.split(":")
|
10
|
+
attributes[Record.resolve(name)] = value
|
11
|
+
end
|
12
|
+
|
13
|
+
domain = Domain.find(domain_name)
|
14
|
+
record = Record.find(domain.name, id)
|
15
|
+
attributes.each do |name, value|
|
16
|
+
record.send("#{name}=", value)
|
17
|
+
end
|
18
|
+
record.save
|
19
|
+
puts "Updated record #{record.fqdn} (id: #{record.id})"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/dnsimple/contact.rb
CHANGED
@@ -96,17 +96,18 @@ module DNSimple #:nodoc:
|
|
96
96
|
options.merge!({:basic_auth => Client.credentials})
|
97
97
|
self.class.delete("#{Client.base_uri}/contacts/#{id}.json", options)
|
98
98
|
end
|
99
|
+
alias :destroy :delete
|
99
100
|
|
100
101
|
# Map an aliased field name to it's real name. For example, if you
|
101
102
|
# pass "first" it will be resolved to "first_name", "email" is resolved
|
102
103
|
# to "email_address" and so on.
|
103
104
|
def self.resolve(name)
|
104
105
|
aliases = {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
'first' => 'first_name',
|
107
|
+
'last' => 'last_name',
|
108
|
+
'state' => 'state_province',
|
109
|
+
'province' => 'state_province',
|
110
|
+
'email' => 'email_address',
|
110
111
|
}
|
111
112
|
aliases[name] || name
|
112
113
|
end
|
data/lib/dnsimple/record.rb
CHANGED
@@ -23,6 +23,33 @@ module DNSimple
|
|
23
23
|
self.send(m, value) if self.respond_to?(m)
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
def fqdn
|
28
|
+
[name, domain.name].delete_if { |v| v.blank? }.join(".")
|
29
|
+
end
|
30
|
+
|
31
|
+
def save(options={})
|
32
|
+
record_hash = {}
|
33
|
+
%w(name content ttl prio).each do |attribute|
|
34
|
+
record_hash[Record.resolve(attribute)] = self.send(attribute)
|
35
|
+
end
|
36
|
+
|
37
|
+
options.merge!(:basic_auth => Client.credentials)
|
38
|
+
options.merge!(:body => {:record => record_hash})
|
39
|
+
|
40
|
+
response = self.class.put("#{Client.base_uri}/domains/#{domain.id}/records/#{id}.json", options)
|
41
|
+
|
42
|
+
pp response if Client.debug?
|
43
|
+
|
44
|
+
case response.code
|
45
|
+
when 200
|
46
|
+
return self
|
47
|
+
when 401
|
48
|
+
raise RuntimeError, "Authentication failed"
|
49
|
+
else
|
50
|
+
raise RuntimeError, "Failed to update record: #{response.inspect}"
|
51
|
+
end
|
52
|
+
end
|
26
53
|
|
27
54
|
def delete(options={})
|
28
55
|
options.merge!({:basic_auth => Client.credentials})
|
@@ -30,6 +57,14 @@ module DNSimple
|
|
30
57
|
end
|
31
58
|
alias :destroy :delete
|
32
59
|
|
60
|
+
def self.resolve(name)
|
61
|
+
aliases = {
|
62
|
+
'priority' => 'prio',
|
63
|
+
'time-to-live' => 'ttl'
|
64
|
+
}
|
65
|
+
aliases[name] || name
|
66
|
+
end
|
67
|
+
|
33
68
|
def self.create(domain_name, name, record_type, content, options={})
|
34
69
|
domain = Domain.find(domain_name)
|
35
70
|
|
@@ -57,7 +92,7 @@ module DNSimple
|
|
57
92
|
def self.find(domain_name, id, options={})
|
58
93
|
domain = Domain.find(domain_name)
|
59
94
|
options.merge!({:basic_auth => Client.credentials})
|
60
|
-
response = self.get("#{Client.base_uri}/domains/#{domain.id}/records/#{id}", options)
|
95
|
+
response = self.get("#{Client.base_uri}/domains/#{domain.id}/records/#{id}.json", options)
|
61
96
|
|
62
97
|
pp response if Client.debug?
|
63
98
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnsimple-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 2
|
10
|
+
version: 0.8.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Anthony Eden
|
@@ -15,8 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
19
|
-
default_executable:
|
18
|
+
date: 2010-11-29 00:00:00 +01:00
|
19
|
+
default_executable: dnsimple
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
type: :runtime
|
@@ -107,7 +107,6 @@ dependencies:
|
|
107
107
|
description: A ruby wrapper for the DNSimple API that also includes a command-line client.
|
108
108
|
email: anthony.eden@dnsimple.com
|
109
109
|
executables:
|
110
|
-
- dnsimple.rb
|
111
110
|
- dnsimple
|
112
111
|
extensions: []
|
113
112
|
|
@@ -146,6 +145,7 @@ files:
|
|
146
145
|
- lib/dnsimple/commands/delete_template_record.rb
|
147
146
|
- lib/dnsimple/commands/describe_contact.rb
|
148
147
|
- lib/dnsimple/commands/describe_domain.rb
|
148
|
+
- lib/dnsimple/commands/describe_record.rb
|
149
149
|
- lib/dnsimple/commands/describe_user.rb
|
150
150
|
- lib/dnsimple/commands/list_contacts.rb
|
151
151
|
- lib/dnsimple/commands/list_domains.rb
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- lib/dnsimple/commands/register_domain.rb
|
157
157
|
- lib/dnsimple/commands/transfer_domain.rb
|
158
158
|
- lib/dnsimple/commands/update_contact.rb
|
159
|
+
- lib/dnsimple/commands/update_record.rb
|
159
160
|
- lib/dnsimple/contact.rb
|
160
161
|
- lib/dnsimple/domain.rb
|
161
162
|
- lib/dnsimple/error.rb
|