sant0sk1-dreamy 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +82 -0
- data/Rakefile +26 -0
- data/VERSION.yml +4 -0
- data/bin/dh +14 -0
- data/lib/dreamy.rb +19 -0
- data/lib/dreamy/command.rb +66 -0
- data/lib/dreamy/commands/base.rb +96 -0
- data/lib/dreamy/commands/dns.rb +26 -0
- data/lib/dreamy/commands/domains.rb +42 -0
- data/lib/dreamy/commands/help.rb +25 -0
- data/lib/dreamy/commands/users.rb +18 -0
- data/lib/dreamy/control.rb +79 -0
- data/lib/dreamy/dns.rb +20 -0
- data/lib/dreamy/domain.rb +33 -0
- data/lib/dreamy/easy_class_maker.rb +43 -0
- data/lib/dreamy/user.rb +21 -0
- data/test/control_test.rb +45 -0
- data/test/dns_test.rb +32 -0
- data/test/domain_test.rb +54 -0
- data/test/test_helper.rb +10 -0
- data/test/user_test.rb +36 -0
- metadata +86 -0
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
What is it?
|
2
|
+
===========
|
3
|
+
|
4
|
+
[Dreamy][1] is Ruby library and command line tool for interfacing with [DreamHost's API][2]. The API itself is still very young so this is by no means a comprehensive library. Please fork and contribute!
|
5
|
+
|
6
|
+
|
7
|
+
Install
|
8
|
+
=======
|
9
|
+
|
10
|
+
Grab the gem from GitHub
|
11
|
+
|
12
|
+
gem sources -a http://gems.github.com
|
13
|
+
gem install sant0sk1-dreamy
|
14
|
+
|
15
|
+
Library Usage
|
16
|
+
=============
|
17
|
+
|
18
|
+
DreamHost requires a username (email or webID) and API key (available from your DH Panel) to make API requests. When creating a Dreamy instance you'll need to provide this data. The Dreamy command line tool (dh) gathers the necessary info from a configuration file or environment variables, but you can do it however you'd like.
|
19
|
+
|
20
|
+
To get started with the library:
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'dreamy'
|
24
|
+
|
25
|
+
account = Dreamy::Control.new(username,api_key)
|
26
|
+
|
27
|
+
# fetch an array of Dreamy::Domain objects
|
28
|
+
account.domains
|
29
|
+
|
30
|
+
# fetch an array of Dreamy::User objects
|
31
|
+
account.users
|
32
|
+
|
33
|
+
# fetch an array of Dreamy::Dns objects
|
34
|
+
account.dns
|
35
|
+
|
36
|
+
Command Line Usage
|
37
|
+
==================
|
38
|
+
|
39
|
+
The Dreamy gem will install an executable called "dh". In order to use it, you'll need to set your DreamHost account username and API key. You can acquire an API key from the DreamHost panel. "dh" will fetch your API credentials from 2 places, respectively:
|
40
|
+
|
41
|
+
1) A file called .dreamyrc in your $HOME directory with username on line 1, api key on line 2
|
42
|
+
|
43
|
+
An example ~/.dreamyrc would look like:
|
44
|
+
|
45
|
+
dh_user@gmail.com
|
46
|
+
34TGGGKBRG3YD1EA
|
47
|
+
|
48
|
+
2) Environment variables DH\_USER and DH\_KEY. You can set these by typing this in your shell:
|
49
|
+
|
50
|
+
export DH_USER=dh_user@gmail.com
|
51
|
+
export DH_KEY=34TGGGKBRG3YD1EA
|
52
|
+
|
53
|
+
If you want to make those environment variables permanent, add those 2 lines to the bottom of your ~/.bashrc
|
54
|
+
|
55
|
+
|
56
|
+
Run this from the command line to print the usage:
|
57
|
+
|
58
|
+
dh help
|
59
|
+
|
60
|
+
=== Commands
|
61
|
+
|
62
|
+
help # show this usage
|
63
|
+
|
64
|
+
domains # list domains
|
65
|
+
domains:status # check availability of all domains
|
66
|
+
|
67
|
+
dns # list your DNS records
|
68
|
+
dns <name> # list DNS records for <ame>
|
69
|
+
|
70
|
+
users # list user accounts
|
71
|
+
|
72
|
+
That's it for now. New commands should be springing up as Dreamy and the DreamHost API mature!
|
73
|
+
|
74
|
+
TODO
|
75
|
+
====
|
76
|
+
|
77
|
+
* more tests
|
78
|
+
* create rdocs
|
79
|
+
* mailing lists
|
80
|
+
|
81
|
+
[1]:http://github.com/sant0sk1/dreamy
|
82
|
+
[2]:http://wiki.Dreamy.com/API
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
task :default => [:test_units]
|
5
|
+
|
6
|
+
desc "Run basic tests"
|
7
|
+
Rake::TestTask.new("test_units") { |t|
|
8
|
+
t.pattern = 'test/*_test.rb'
|
9
|
+
t.verbose = true
|
10
|
+
t.warning = true
|
11
|
+
}
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gemspec|
|
16
|
+
gemspec.name = "dreamy"
|
17
|
+
gemspec.summary = "A Ruby library and command line tool for accessing DreamHost's API"
|
18
|
+
gemspec.email = "jerod.santo@gmail.com"
|
19
|
+
gemspec.homepage = "http://github.com/sant0sk1/dreamy"
|
20
|
+
gemspec.authors = ["Jerod Santo"]
|
21
|
+
gemspec.add_dependency('visionmedia-terminal-table', '>= 1.0.5')
|
22
|
+
gemspec.files.exclude 'test/credentials.yml'
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
26
|
+
end
|
data/VERSION.yml
ADDED
data/bin/dh
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
6
|
+
|
7
|
+
require 'dreamy'
|
8
|
+
require 'dreamy/command'
|
9
|
+
|
10
|
+
args = ARGV.dup
|
11
|
+
ARGV.clear
|
12
|
+
command = args.shift.strip rescue 'help'
|
13
|
+
|
14
|
+
Dreamy::Command.run(command, args)
|
data/lib/dreamy.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'yaml'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'hpricot'
|
6
|
+
require 'uuid'
|
7
|
+
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + "/dreamy")
|
10
|
+
require 'dreamy/easy_class_maker'
|
11
|
+
require 'dreamy/control'
|
12
|
+
require 'dreamy/domain'
|
13
|
+
require 'dreamy/dns'
|
14
|
+
require 'dreamy/user'
|
15
|
+
|
16
|
+
module Dreamy
|
17
|
+
class CantConnect < StandardError; end
|
18
|
+
class Unavailable < StandardError; end
|
19
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'commands/base'
|
2
|
+
|
3
|
+
module Dreamy
|
4
|
+
module Command
|
5
|
+
class InvalidCommand < RuntimeError; end
|
6
|
+
class CommandFailed < RuntimeError; end
|
7
|
+
class Unauthorized < RuntimeError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def run(command, args, retries=0)
|
11
|
+
run_internal(command, args)
|
12
|
+
rescue InvalidCommand
|
13
|
+
error "Unknown command. Run 'dh help' for usage information."
|
14
|
+
rescue Unauthorized
|
15
|
+
if retries < 3
|
16
|
+
STDERR.puts "Authentication failure"
|
17
|
+
run(command, args, retries+1)
|
18
|
+
else
|
19
|
+
error "Authentication failure"
|
20
|
+
end
|
21
|
+
rescue CommandFailed => e
|
22
|
+
error e.message
|
23
|
+
rescue Interrupt => e
|
24
|
+
error "\n[canceled]"
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_internal(command, args)
|
28
|
+
namespace, command = parse(command)
|
29
|
+
require "commands/#{namespace}"
|
30
|
+
klass = Dreamy::Command.const_get(namespace.capitalize).new(args)
|
31
|
+
raise InvalidCommand unless klass.respond_to?(command)
|
32
|
+
klass.send(command)
|
33
|
+
end
|
34
|
+
|
35
|
+
def error(msg)
|
36
|
+
STDERR.puts(msg)
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse(command)
|
41
|
+
parts = command.split(':')
|
42
|
+
case parts.size
|
43
|
+
when 1
|
44
|
+
if namespaces.include? command
|
45
|
+
return command, 'index'
|
46
|
+
else
|
47
|
+
raise InvalidCommand
|
48
|
+
end
|
49
|
+
when 2
|
50
|
+
raise InvalidCommand unless namespaces.include? parts[0]
|
51
|
+
return parts
|
52
|
+
else
|
53
|
+
raise InvalidCommand
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def namespaces
|
58
|
+
@@namespaces ||= Dir["#{File.dirname(__FILE__)}/commands/*"].map do |namespace|
|
59
|
+
namespace.gsub(/.*\//, '').gsub(/\.rb/, '')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'terminal-table/import'
|
2
|
+
|
3
|
+
module Dreamy::Command
|
4
|
+
class Base
|
5
|
+
|
6
|
+
attr_accessor :args
|
7
|
+
def initialize(args)
|
8
|
+
@args = args
|
9
|
+
@account = configure_account
|
10
|
+
end
|
11
|
+
|
12
|
+
def display(msg, newline=true)
|
13
|
+
if newline
|
14
|
+
puts(msg)
|
15
|
+
else
|
16
|
+
print(msg)
|
17
|
+
STDOUT.flush
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def ask
|
22
|
+
gets.strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def shell(cmd)
|
26
|
+
`cd '#{Dir.pwd}' && #{cmd}`
|
27
|
+
end
|
28
|
+
|
29
|
+
def extract_option(options, default=true)
|
30
|
+
values = options.is_a?(Array) ? options : [options]
|
31
|
+
return unless opt_index = args.select { |a| values.include? a }.first
|
32
|
+
opt_position = args.index(opt_index) + 1
|
33
|
+
if args.size > opt_position && opt_value = args[opt_position]
|
34
|
+
if opt_value.include?('--')
|
35
|
+
opt_value = nil
|
36
|
+
else
|
37
|
+
args.delete_at(opt_position)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
opt_value ||= default
|
41
|
+
args.delete(opt_index)
|
42
|
+
block_given? ? yield(opt_value) : opt_value
|
43
|
+
end
|
44
|
+
|
45
|
+
def home_directory
|
46
|
+
running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
|
47
|
+
end
|
48
|
+
|
49
|
+
def running_on_windows?
|
50
|
+
RUBY_PLATFORM =~ /mswin32/
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def configure_account
|
56
|
+
Dreamy::Control.new(user,key)
|
57
|
+
end
|
58
|
+
|
59
|
+
def user
|
60
|
+
get_credentials
|
61
|
+
@credentials[0]
|
62
|
+
end
|
63
|
+
|
64
|
+
def key
|
65
|
+
get_credentials
|
66
|
+
@credentials[1]
|
67
|
+
end
|
68
|
+
|
69
|
+
def credentials_file
|
70
|
+
"#{home_directory}/.dreamyrc"
|
71
|
+
end
|
72
|
+
|
73
|
+
def read_credentials
|
74
|
+
if File.exists? credentials_file
|
75
|
+
return File.read(credentials_file).split("\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_credentials
|
80
|
+
return if @credentials
|
81
|
+
unless @credentials = read_credentials
|
82
|
+
@credentials = [ENV['DH_USER'], ENV['DH_KEY']]
|
83
|
+
end
|
84
|
+
if @credentials[0].nil? || @credentials[1].nil?
|
85
|
+
display "\nYou need to set your API credentials. You can do this 2 ways:\n"
|
86
|
+
display "\n1) set environment variables 'DH_USER' and 'DH_KEY'"
|
87
|
+
display "2) create file ~/.Dreamyrc with user on first line and key on second\n\n"
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
@credentials
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Dreamy::Command
|
2
|
+
class Dns < Base
|
3
|
+
|
4
|
+
def list
|
5
|
+
dns = @account.dns
|
6
|
+
|
7
|
+
if args.length > 0
|
8
|
+
filter = args.shift.downcase
|
9
|
+
dns = dns.select { |d| d.zone.match(filter) }
|
10
|
+
end
|
11
|
+
|
12
|
+
if dns.empty?
|
13
|
+
display "No DNS records for this account or requested zone not found"
|
14
|
+
else
|
15
|
+
dns_table = table do |t|
|
16
|
+
t.headings = 'Record', 'Type', 'Value'
|
17
|
+
dns.each { |d| t << [d.record,d.type,d.value] if d.type != "TXT" }
|
18
|
+
end
|
19
|
+
display "NOTE: TXT records not displayed (too long)"
|
20
|
+
display dns_table
|
21
|
+
end
|
22
|
+
end
|
23
|
+
alias :index :list
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'ping'
|
2
|
+
|
3
|
+
module Dreamy::Command
|
4
|
+
class Domains < Base
|
5
|
+
|
6
|
+
def index
|
7
|
+
domains = @account.domains
|
8
|
+
if domains.empty?
|
9
|
+
display "No domains on this account"
|
10
|
+
else
|
11
|
+
domain_table = table do |t|
|
12
|
+
t.headings = 'Domain Name', 'Server', 'Type', 'User', 'WWW or Not'
|
13
|
+
domains.each { |d| t << [d.domain,d.short_home,d.hosting_type,d.user,d.www_or_not]}
|
14
|
+
end
|
15
|
+
display domain_table
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def status
|
20
|
+
domains = @account.domains
|
21
|
+
domains.each do |d|
|
22
|
+
if host_available?(d.domain)
|
23
|
+
display "#{d.domain} is up"
|
24
|
+
else
|
25
|
+
display "#{d.domain} is down!"
|
26
|
+
if host_available?(d.home)
|
27
|
+
display " But its host server (#{d.home}) is up"
|
28
|
+
else
|
29
|
+
display " And its host server (#{d.home}) is down"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def host_available?(host)
|
38
|
+
Ping.pingecho host
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Dreamy::Command
|
2
|
+
class Help < Base
|
3
|
+
def index
|
4
|
+
display usage
|
5
|
+
end
|
6
|
+
|
7
|
+
def usage
|
8
|
+
usage = <<EOTXT
|
9
|
+
|
10
|
+
=== Commands
|
11
|
+
|
12
|
+
help # show this usage
|
13
|
+
|
14
|
+
domains # list domains
|
15
|
+
domains:status # check availability of all domains
|
16
|
+
|
17
|
+
dns # list your DNS records
|
18
|
+
dns <name> # list DNS records for <ame>
|
19
|
+
|
20
|
+
users # list user accounts
|
21
|
+
|
22
|
+
EOTXT
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Dreamy::Command
|
2
|
+
class Users < Base
|
3
|
+
|
4
|
+
def index
|
5
|
+
users = @account.users
|
6
|
+
if users.empty?
|
7
|
+
display "No users on this account"
|
8
|
+
else
|
9
|
+
user_table = table do |t|
|
10
|
+
t.headings = 'Name', 'Account Type', 'Server', 'Disk used (MB)', 'Quota (MB)'
|
11
|
+
users.each { |u| t << [u.gecos, u.type, u.home, u.disk_used_mb, u.quota_mb] }
|
12
|
+
end
|
13
|
+
display user_table
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Dreamy
|
2
|
+
class Control
|
3
|
+
|
4
|
+
@@host = "api.dreamhost.com"
|
5
|
+
|
6
|
+
def initialize(username, key)
|
7
|
+
@username = username
|
8
|
+
@key = key
|
9
|
+
end
|
10
|
+
|
11
|
+
# returns an array of domain objects
|
12
|
+
def domains
|
13
|
+
doc = request("domain-list_domains")
|
14
|
+
(doc/:data).inject([]) { |domains, domain| domains << Domain.new_from_xml(domain); domains }
|
15
|
+
end
|
16
|
+
|
17
|
+
# returns an array of user objects
|
18
|
+
def users(passwords=false)
|
19
|
+
if passwords
|
20
|
+
doc = request("user-list_users")
|
21
|
+
else
|
22
|
+
doc = request("user-list_users_no_pw")
|
23
|
+
end
|
24
|
+
|
25
|
+
(doc/:data).inject([]) { |users, user| users << User.new_from_xml(user); users }
|
26
|
+
end
|
27
|
+
|
28
|
+
# returns an array of dns objects
|
29
|
+
def dns
|
30
|
+
doc = request("dns-list_records")
|
31
|
+
(doc/:data).inject([]) { |records, dns| records << Dns.new_from_xml(dns); records }
|
32
|
+
end
|
33
|
+
|
34
|
+
def request(cmd,values={})
|
35
|
+
handle_response!(response(cmd,values))
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def response(cmd,values={})
|
41
|
+
params = [
|
42
|
+
"username=#{@username}",
|
43
|
+
"key=#{@key}",
|
44
|
+
"cmd=#{cmd}",
|
45
|
+
"format=xml",
|
46
|
+
"unique_id=#{UUID.new.generate}",
|
47
|
+
]
|
48
|
+
|
49
|
+
path = "/?#{params.join("&")}"
|
50
|
+
http = Net::HTTP.new(@@host, 443)
|
51
|
+
http.use_ssl = true
|
52
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
53
|
+
|
54
|
+
begin
|
55
|
+
response = http.get(path)
|
56
|
+
rescue => error
|
57
|
+
raise CantConnect, error.message
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def handle_response!(response)
|
62
|
+
if %w[200 304].include?(response.code)
|
63
|
+
response = parse(response.body)
|
64
|
+
elsif response.code == '503'
|
65
|
+
raise Unavailable, response.message
|
66
|
+
elsif response.code == '401'
|
67
|
+
raise CantConnect, 'Authentication failed. Check your username and password'
|
68
|
+
else
|
69
|
+
raise CantConnect, "Dreamy is returning a #{response.code}: #{response.message}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Converts a string response into an Hpricot xml element.
|
74
|
+
def parse(response)
|
75
|
+
Hpricot.XML(response || '')
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
data/lib/dreamy/dns.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Dreamy
|
2
|
+
class Dns
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :account_id, :comment, :editable, :record, :type, :value, :zone
|
6
|
+
|
7
|
+
def self.new_from_xml(xml)
|
8
|
+
d = new
|
9
|
+
d.account_id = (xml).at('account_id').innerHTML
|
10
|
+
d.comment = (xml).at('comment').innerHTML
|
11
|
+
# TODO - enable this if DH guys change the API as requested
|
12
|
+
# d.editable = (xml).at('editable').innerHTML
|
13
|
+
d.record = (xml).at('record').innerHTML
|
14
|
+
d.type = (xml).at('type').innerHTML
|
15
|
+
d.value = (xml).at('value').innerHTML
|
16
|
+
d.zone = (xml).at('zone').innerHTML
|
17
|
+
d
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Dreamy
|
2
|
+
class Domain
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :account_id, :domain, :fastcgi, :home, :hosting_type, :outside_url, :passenger,
|
6
|
+
:path, :php, :php_fcgid, :security, :type, :unique_ip, :user, :www_or_not, :xcache
|
7
|
+
|
8
|
+
def self.new_from_xml(xml)
|
9
|
+
d = new
|
10
|
+
d.account_id = (xml).at('account_id').innerHTML
|
11
|
+
d.domain = (xml).at('domain').innerHTML
|
12
|
+
d.fastcgi = (xml).at('fastcgi').innerHTML
|
13
|
+
d.home = (xml).at('home').innerHTML
|
14
|
+
d.hosting_type = (xml).at('hosting_type').innerHTML
|
15
|
+
d.outside_url = (xml).at('outside_url').innerHTML
|
16
|
+
d.passenger = (xml).at('passenger').innerHTML
|
17
|
+
d.path = (xml).at('path').innerHTML
|
18
|
+
d.php = (xml).at('php').innerHTML
|
19
|
+
d.php_fcgid = (xml).at('php_fcgid').innerHTML
|
20
|
+
d.security = (xml).at('security').innerHTML
|
21
|
+
d.type = (xml).at('type').innerHTML
|
22
|
+
d.unique_ip = (xml).at('unique_ip').innerHTML
|
23
|
+
d.user = (xml).at('user').innerHTML
|
24
|
+
d.www_or_not = (xml).at('www_or_not').innerHTML
|
25
|
+
d.xcache = (xml).at('xcache').innerHTML
|
26
|
+
d
|
27
|
+
end
|
28
|
+
|
29
|
+
def short_home
|
30
|
+
home.gsub(".Dreamy.com","")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This is pretty much just a macro for creating a class that allows
|
2
|
+
# using a block to initialize stuff and to define getters and setters
|
3
|
+
# really quickly.
|
4
|
+
module Dreamy
|
5
|
+
module EasyClassMaker
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# creates the attributes class variable and creates each attribute's accessor methods
|
13
|
+
def attributes(*attrs)
|
14
|
+
@@attributes = attrs
|
15
|
+
@@attributes.each { |a| attr_accessor a }
|
16
|
+
end
|
17
|
+
|
18
|
+
# read method for attributes class variable
|
19
|
+
def self.attributes; @@attributes end
|
20
|
+
end
|
21
|
+
|
22
|
+
# allows for any class that includes this to use a block to initialize
|
23
|
+
# variables instead of assigning each one seperately
|
24
|
+
#
|
25
|
+
# Example:
|
26
|
+
#
|
27
|
+
# instead of...
|
28
|
+
#
|
29
|
+
# s = Status.new
|
30
|
+
# s.foo = 'thing'
|
31
|
+
# s.bar = 'another thing'
|
32
|
+
#
|
33
|
+
# you can ...
|
34
|
+
#
|
35
|
+
# Status.new do |s|
|
36
|
+
# s.foo = 'thing'
|
37
|
+
# s.bar = 'another thing'
|
38
|
+
# end
|
39
|
+
def initialize
|
40
|
+
yield self if block_given?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/dreamy/user.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Dreamy
|
2
|
+
class User
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :account_id, :disk_used_mb, :gecos, :home, :password, :quota_mb, :shell, :type, :username
|
6
|
+
|
7
|
+
def self.new_from_xml(xml)
|
8
|
+
u = new
|
9
|
+
u.account_id = (xml).at('account_id').innerHTML
|
10
|
+
u.disk_used_mb = (xml).at('disk_used_mb').innerHTML
|
11
|
+
u.gecos = (xml).at('gecos').innerHTML
|
12
|
+
u.home = (xml).at('home').innerHTML
|
13
|
+
u.password = (xml).at('password').innerHTML
|
14
|
+
u.quota_mb = (xml).at('quota_mb').innerHTML
|
15
|
+
u.shell = (xml).at('shell').innerHTML
|
16
|
+
u.type = (xml).at('type').innerHTML
|
17
|
+
u.username = (xml).at('username').innerHTML
|
18
|
+
u
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
+
|
3
|
+
class DreamyControlTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
@@base = Dreamy::Control.new(CREDS["user"],CREDS["key"])
|
6
|
+
|
7
|
+
context "Initialization" do
|
8
|
+
|
9
|
+
should "require email and API key" do
|
10
|
+
assert_raise(ArgumentError) { Dreamy::Control.new }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
context "Domains" do
|
16
|
+
|
17
|
+
should "return array of domain objects" do
|
18
|
+
assert_kind_of Array, @@base.domains
|
19
|
+
assert_kind_of Dreamy::Domain, @@base.domains.first
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Users" do
|
25
|
+
|
26
|
+
should "return array of user objects" do
|
27
|
+
assert_kind_of Array, @@base.users
|
28
|
+
assert_kind_of Dreamy::User, @@base.users.first
|
29
|
+
end
|
30
|
+
|
31
|
+
should "not include user passwords by default" do
|
32
|
+
assert_equal "********", @@base.users.first.password
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "DNS" do
|
37
|
+
|
38
|
+
should "return array of DNS records" do
|
39
|
+
assert_kind_of Array, @@base.dns
|
40
|
+
assert_kind_of Dreamy::Dns, @@base.dns.first
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
data/test/dns_test.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
+
|
3
|
+
class DreamyDnsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Creation" do
|
6
|
+
setup do
|
7
|
+
@xml = <<EOF
|
8
|
+
<data>
|
9
|
+
<account_id>8675309</account_id>
|
10
|
+
<comment></comment>
|
11
|
+
<editable?>0</editable?>
|
12
|
+
<record>anessalee.net</record>
|
13
|
+
<type>A</type>
|
14
|
+
<value>202.22.191.4</value>
|
15
|
+
<zone>anessalee.net</zone>
|
16
|
+
</data>
|
17
|
+
EOF
|
18
|
+
end
|
19
|
+
|
20
|
+
should "create a new DNS entry from xml" do
|
21
|
+
d = Dreamy::Dns.new_from_xml(Hpricot.XML(@xml))
|
22
|
+
assert_equal "8675309", d.account_id
|
23
|
+
assert_equal "", d.comment
|
24
|
+
# assert_equal "0", d.editable
|
25
|
+
assert_equal "anessalee.net", d.record
|
26
|
+
assert_equal "A", d.type
|
27
|
+
assert_equal "202.22.191.4", d.value
|
28
|
+
assert_equal "anessalee.net", d.zone
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/test/domain_test.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
+
|
3
|
+
class DreamyDomainTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Creation" do
|
6
|
+
setup do
|
7
|
+
@xml = <<EOF
|
8
|
+
<data>
|
9
|
+
<account_id>8675309</account_id>
|
10
|
+
<domain>anessalee.net</domain>
|
11
|
+
<fastcgi>0</fastcgi>
|
12
|
+
<home>juniormint.Dreamy.com</home>
|
13
|
+
<hosting_type>full</hosting_type>
|
14
|
+
<outside_url></outside_url>
|
15
|
+
<passenger>0</passenger>
|
16
|
+
<path>anessalee.net</path>
|
17
|
+
<php>pcgi5</php>
|
18
|
+
<php_fcgid>0</php_fcgid>
|
19
|
+
<security>0</security>
|
20
|
+
<type>http</type>
|
21
|
+
<unique_ip></unique_ip>
|
22
|
+
<user>sant0sk1</user>
|
23
|
+
<www_or_not>both_work</www_or_not>
|
24
|
+
<xcache>0</xcache>
|
25
|
+
</data>
|
26
|
+
EOF
|
27
|
+
@d = Dreamy::Domain.new_from_xml(Hpricot.XML(@xml))
|
28
|
+
end
|
29
|
+
|
30
|
+
should "assign valid domain from xml" do
|
31
|
+
assert_equal "8675309", @d.account_id
|
32
|
+
assert_equal "anessalee.net", @d.domain
|
33
|
+
assert_equal "0", @d.fastcgi
|
34
|
+
assert_equal "juniormint.Dreamy.com", @d.home
|
35
|
+
assert_equal "full", @d.hosting_type
|
36
|
+
assert_equal "", @d.outside_url
|
37
|
+
assert_equal "0", @d.passenger
|
38
|
+
assert_equal "anessalee.net", @d.path
|
39
|
+
assert_equal "pcgi5", @d.php
|
40
|
+
assert_equal "0", @d.php_fcgid
|
41
|
+
assert_equal "0", @d.security
|
42
|
+
assert_equal "http", @d.type
|
43
|
+
assert_equal "", @d.unique_ip
|
44
|
+
assert_equal "sant0sk1", @d.user
|
45
|
+
assert_equal "both_work", @d.www_or_not
|
46
|
+
assert_equal "0", @d.xcache
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return shortened server name if requested" do
|
50
|
+
assert_equal "juniormint", @d.short_home
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/test/test_helper.rb
ADDED
data/test/user_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
+
|
3
|
+
class DreamyUserTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Creation" do
|
6
|
+
setup do
|
7
|
+
@xml = <<EOF
|
8
|
+
<data>
|
9
|
+
<account_id>8675309</account_id>
|
10
|
+
<disk_used_mb>0</disk_used_mb>
|
11
|
+
<gecos>Joe Schmoe</gecos>
|
12
|
+
<home>spork.Dreamy.com</home>
|
13
|
+
<password>YahRight!</password>
|
14
|
+
<quota_mb>50</quota_mb>
|
15
|
+
<shell>/bin/bash</shell>
|
16
|
+
<type>mail</type>
|
17
|
+
<username>joe@schmoe.com</username>
|
18
|
+
</data>
|
19
|
+
EOF
|
20
|
+
end
|
21
|
+
|
22
|
+
should "create a new user from xml" do
|
23
|
+
u = Dreamy::User.new_from_xml(Hpricot.XML(@xml))
|
24
|
+
assert_equal "8675309", u.account_id
|
25
|
+
assert_equal "0", u.disk_used_mb
|
26
|
+
assert_equal "Joe Schmoe", u.gecos
|
27
|
+
assert_equal "spork.Dreamy.com", u.home
|
28
|
+
assert_equal "YahRight!", u.password
|
29
|
+
assert_equal "50", u.quota_mb
|
30
|
+
assert_equal "/bin/bash", u.shell
|
31
|
+
assert_equal "mail", u.type
|
32
|
+
assert_equal "joe@schmoe.com", u.username
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sant0sk1-dreamy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jerod Santo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-18 00:00:00 -07:00
|
13
|
+
default_executable: dh
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: visionmedia-terminal-table
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.5
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: jerod.santo@gmail.com
|
27
|
+
executables:
|
28
|
+
- dh
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.md
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- VERSION.yml
|
37
|
+
- bin/dh
|
38
|
+
- lib/dreamy.rb
|
39
|
+
- lib/dreamy/command.rb
|
40
|
+
- lib/dreamy/commands/base.rb
|
41
|
+
- lib/dreamy/commands/dns.rb
|
42
|
+
- lib/dreamy/commands/domains.rb
|
43
|
+
- lib/dreamy/commands/help.rb
|
44
|
+
- lib/dreamy/commands/users.rb
|
45
|
+
- lib/dreamy/control.rb
|
46
|
+
- lib/dreamy/dns.rb
|
47
|
+
- lib/dreamy/domain.rb
|
48
|
+
- lib/dreamy/easy_class_maker.rb
|
49
|
+
- lib/dreamy/user.rb
|
50
|
+
- test/control_test.rb
|
51
|
+
- test/dns_test.rb
|
52
|
+
- test/domain_test.rb
|
53
|
+
- test/test_helper.rb
|
54
|
+
- test/user_test.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/sant0sk1/dreamy
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options:
|
59
|
+
- --charset=UTF-8
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.2.0
|
78
|
+
signing_key:
|
79
|
+
specification_version: 2
|
80
|
+
summary: A Ruby library and command line tool for accessing DreamHost's API
|
81
|
+
test_files:
|
82
|
+
- test/control_test.rb
|
83
|
+
- test/dns_test.rb
|
84
|
+
- test/domain_test.rb
|
85
|
+
- test/test_helper.rb
|
86
|
+
- test/user_test.rb
|