Skip to content

Commit

Permalink
set private server settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jerodsanto committed May 2, 2009
1 parent e6395d0 commit cb1dae4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/dreamy/base.rb
Expand Up @@ -84,6 +84,12 @@ def ps_settings(name)
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
PrivateServer.settings_from_xml(doc)
end

def ps_set(name,setting,value)
doc = request("dreamhost_ps-set_settings", {"ps" => name, setting => value})
raise ApiError, (doc/:data).innerHTML if (doc/:result).innerHTML == "error"
true
end

private

Expand All @@ -107,6 +113,7 @@ def response(cmd,values={})
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

begin
# puts path
response = http.get(path)
rescue => error
raise CantConnect, error.message
Expand Down
23 changes: 23 additions & 0 deletions lib/dreamy/commands/ps.rb
Expand Up @@ -16,5 +16,28 @@ def list
end
alias :index :list

def settings
if args.length == 1
settings = @account.ps_settings(args[0])
settings_table = table do |t|
t.headings = 'Setting', 'Value'
settings.each { |k,v| t << [k,v] }
end
display settings_table
else
display "Usage: dh ps:settings [ps name]"
end
end

def set
if args.length == 3
name, setting, value = args[0], args[1], args[2]
@account.ps_set(name,setting,value)
display "Successfully set #{setting} to #{value} for #{name}"
else
display "Usage: dh ps:set [ps name] [setting] [value]"
end
end

end
end
19 changes: 19 additions & 0 deletions test/base_test.rb
Expand Up @@ -137,13 +137,32 @@ class DreamyBaseTest < Test::Unit::TestCase
end # announcement lists

context "Private Servers" do
setup { @ps = CREDS["ps"] }

should "return an array of PrivateServer objects" do
ps = @@base.ps
assert_kind_of Array, ps
assert_kind_of Dreamy::PrivateServer, ps.first unless ps.empty?
end

context "settings" do

should "return a hash of settings" do
settings = @@base.ps_settings(@ps)
assert_kind_of Hash, settings
end

should "require values for ps, setting, and value when setting value" do
assert_raise(ArgumentError) { @@base.ps_set() }
end

should "set specified setting" do
@@base.ps_set(@ps,'comment','testps')
settings = @@base.ps_settings(@ps)
assert_equal 'testps', settings['comment']
end

end

end

Expand Down
3 changes: 2 additions & 1 deletion test/credentials.yml.example
Expand Up @@ -3,4 +3,5 @@ user: "your username or email"
key: "your api key"
# announce list tests
listname: "list"
domain: "example.com"
domain: "example.com"
ps: "ps12345"

0 comments on commit cb1dae4

Please sign in to comment.