sant0sk1-dreamy 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -10
- data/VERSION.yml +2 -2
- data/lib/dreamy/base.rb +15 -0
- data/lib/dreamy/commands/announce.rb +30 -2
- data/lib/dreamy/commands/help.rb +9 -10
- data/test/base_test.rb +22 -6
- metadata +1 -1
data/README.md
CHANGED
@@ -17,22 +17,50 @@ Library Usage
|
|
17
17
|
|
18
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
19
|
|
20
|
-
To get started with the library:
|
20
|
+
To get started with the library, just require the gem:
|
21
21
|
|
22
22
|
require 'rubygems'
|
23
23
|
require 'dreamy'
|
24
24
|
|
25
|
+
Create a new object using your username and API key.
|
26
|
+
|
25
27
|
account = Dreamy::Base.new(username,api_key)
|
26
28
|
|
27
|
-
|
29
|
+
Fetch an array of Dreamy::Domain objects:
|
30
|
+
|
28
31
|
account.domains
|
29
32
|
|
33
|
+
Now that you have an array you can have your way with the data:
|
34
|
+
|
35
|
+
account.domains.each do |d|
|
36
|
+
puts d.home
|
37
|
+
puts d.user
|
38
|
+
puts d.www_or_not
|
39
|
+
end
|
40
|
+
|
41
|
+
Same goes with Users, DNS records and announcement list subscribers
|
42
|
+
|
30
43
|
# fetch an array of Dreamy::User objects
|
31
44
|
account.users
|
32
45
|
|
33
46
|
# fetch an array of Dreamy::Dns objects
|
34
47
|
account.dns
|
35
48
|
|
49
|
+
# fetch an array of Dreamy::Subscribers to an announcement list
|
50
|
+
account.announce_list(listname,domain)
|
51
|
+
|
52
|
+
You can interact with announcement lists by adding and removing subscribers
|
53
|
+
|
54
|
+
# add a new subscriber to an announcement list
|
55
|
+
account.announce_add(listname,domain,email)
|
56
|
+
|
57
|
+
# remove a subscriber from an announcement list
|
58
|
+
account.announce_remove(listname,domain,email)
|
59
|
+
|
60
|
+
More and more functions will be added as time allows. If there's something missing that you want in, please:
|
61
|
+
|
62
|
+
fork -> commit -> pull request
|
63
|
+
|
36
64
|
Command Line Usage
|
37
65
|
==================
|
38
66
|
|
@@ -58,16 +86,20 @@ Run this from the command line to print the usage:
|
|
58
86
|
dh help
|
59
87
|
|
60
88
|
=== Commands
|
89
|
+
help # show this usage
|
90
|
+
|
91
|
+
domains # list domains
|
92
|
+
domains:status # check availability of all domains (pingability)
|
61
93
|
|
62
|
-
|
94
|
+
dns # list your DNS records
|
95
|
+
dns <name> # list DNS records for <ame>
|
63
96
|
|
64
|
-
|
65
|
-
|
97
|
+
announce:list <list> # lists all subscribers to <name> list (eg - 'my_list@example.com')
|
98
|
+
announce:add <list> <email> # add a subscriber with <email> to <list>
|
99
|
+
announce:remove <list> <email> # remove subscriber with <email> from <list>
|
66
100
|
|
67
|
-
|
68
|
-
dns <name> # list DNS records for <ame>
|
101
|
+
users # list user accounts
|
69
102
|
|
70
|
-
users # list user accounts
|
71
103
|
|
72
104
|
That's it for now. New commands should be springing up as Dreamy and the DreamHost API mature!
|
73
105
|
|
@@ -75,8 +107,7 @@ TODO
|
|
75
107
|
====
|
76
108
|
|
77
109
|
* more tests
|
78
|
-
*
|
79
|
-
* mailing lists
|
110
|
+
* add real rdocs
|
80
111
|
|
81
112
|
[1]:http://github.com/sant0sk1/dreamy
|
82
113
|
[2]:http://wiki.Dreamy.com/API
|
data/VERSION.yml
CHANGED
data/lib/dreamy/base.rb
CHANGED
@@ -39,6 +39,21 @@ module Dreamy
|
|
39
39
|
raise ApiError if (doc/:result).innerHTML == "error"
|
40
40
|
(doc/:data).inject([]) { |subs, sub| subs << Subscriber.new_from_xml(sub); subs }
|
41
41
|
end
|
42
|
+
|
43
|
+
# adds new subscriber to announce list
|
44
|
+
def announce_add(listname,domain,email,name="")
|
45
|
+
doc = request("announcement_list-add_subscriber",
|
46
|
+
{"listname" => listname, "domain" => domain, "email" => email, "name" => name})
|
47
|
+
return true if (doc/:result).innerHTML == "success"
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
def announce_remove(listname,domain,email)
|
52
|
+
doc = request("announcement_list-remove_subscriber",
|
53
|
+
{"listname" => listname, "domain" => domain, "email" => email} )
|
54
|
+
return true if (doc/:result).innerHTML == "success"
|
55
|
+
false
|
56
|
+
end
|
42
57
|
|
43
58
|
private
|
44
59
|
|
@@ -2,7 +2,7 @@ module Dreamy::Command
|
|
2
2
|
class Announce < Base
|
3
3
|
|
4
4
|
def list
|
5
|
-
if args.length
|
5
|
+
if args.length >= 1
|
6
6
|
listname, domain = extract_values(args.shift)
|
7
7
|
subscribers = @account.announce_list(listname,domain)
|
8
8
|
if subscribers.empty?
|
@@ -16,7 +16,35 @@ module Dreamy::Command
|
|
16
16
|
display "#{subscribers.size} total subscribers"
|
17
17
|
end
|
18
18
|
else
|
19
|
-
display "
|
19
|
+
display "Usage: dh announce:list my_list@example.com"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def add
|
24
|
+
if args.length >= 2
|
25
|
+
listname, domain = extract_values(args.shift)
|
26
|
+
email = args.shift
|
27
|
+
if @account.announce_add(listname,domain,email)
|
28
|
+
display "Successfully added #{email} to #{listname} list"
|
29
|
+
else
|
30
|
+
display "Failed to add #{email} to #{listname} list"
|
31
|
+
end
|
32
|
+
else
|
33
|
+
display "Usage: dh announce:add my_list@example.com new_guy@gmail.com"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove
|
38
|
+
if args.length >= 2
|
39
|
+
listname, domain = extract_values(args.shift)
|
40
|
+
email = args.shift
|
41
|
+
if @account.announce_remove(listname,domain,email)
|
42
|
+
display "Successfully removed #{email} from #{listname} list"
|
43
|
+
else
|
44
|
+
display "Failed to remove #{email} from #{listname} list"
|
45
|
+
end
|
46
|
+
else
|
47
|
+
display "Usage: dh announce:remove my_list@example.com new_guy@gmail.com"
|
20
48
|
end
|
21
49
|
end
|
22
50
|
|
data/lib/dreamy/commands/help.rb
CHANGED
@@ -8,20 +8,19 @@ module Dreamy::Command
|
|
8
8
|
usage = <<EOTXT
|
9
9
|
|
10
10
|
=== Commands
|
11
|
+
help # show this usage
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
domains # list domains
|
15
|
-
domains:status # check availability of all domains
|
13
|
+
domains # list domains
|
14
|
+
domains:status # check availability of all domains (pingability)
|
16
15
|
|
17
|
-
dns
|
18
|
-
dns <name>
|
16
|
+
dns # list your DNS records
|
17
|
+
dns <name> # list DNS records for <ame>
|
19
18
|
|
20
|
-
announce:list <
|
21
|
-
announce:add <
|
22
|
-
announce:remove <
|
19
|
+
announce:list <list> # lists all subscribers to <name> list (eg - 'my_list@example.com')
|
20
|
+
announce:add <list> <email> # add a subscriber with <email> to <list>
|
21
|
+
announce:remove <list> <email> # remove subscriber with <email> from <list>
|
23
22
|
|
24
|
-
users
|
23
|
+
users # list user accounts
|
25
24
|
|
26
25
|
EOTXT
|
27
26
|
end
|
data/test/base_test.rb
CHANGED
@@ -56,14 +56,30 @@ class DreamyBaseTest < Test::Unit::TestCase
|
|
56
56
|
|
57
57
|
end
|
58
58
|
|
59
|
-
context "
|
59
|
+
context "adding a subscriber" do
|
60
|
+
|
61
|
+
should "require values for listname, domain, and email" do
|
62
|
+
assert_raise(ArgumentError) { @@base.announce_add() }
|
63
|
+
end
|
64
|
+
|
65
|
+
should "return true on success" do
|
66
|
+
assert @@base.announce_add(CREDS["listname"],CREDS["domain"],"new_guy@test.com")
|
67
|
+
end
|
68
|
+
|
60
69
|
end
|
61
70
|
|
62
|
-
context "
|
71
|
+
context "removing a subscriber" do
|
72
|
+
|
73
|
+
should "require values for listname, domain, and email" do
|
74
|
+
assert_raise(ArgumentError) { @@base.announce_remove() }
|
75
|
+
end
|
76
|
+
|
77
|
+
should "return true on success" do
|
78
|
+
assert @@base.announce_remove(CREDS["listname"],CREDS["domain"],"new_guy@test.com")
|
79
|
+
end
|
80
|
+
|
63
81
|
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
|
82
|
+
|
83
|
+
end # announcement lists
|
68
84
|
|
69
85
|
end
|