shanesveller-webbynode-api 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +46 -1
- data/VERSION +1 -1
- data/lib/webbynode-api.rb +8 -4
- data/lib/webbynode-api/data.rb +51 -0
- data/test/data/{api-xml-client.xml → client.xml} +0 -0
- data/test/data/dns-1.xml +9 -0
- data/test/data/dns-records.xml +22 -0
- data/test/data/dns.xml +23 -0
- data/test/data/webby-reboot.xml +4 -0
- data/test/data/webby-shutdown.xml +4 -0
- data/test/data/webby-start.xml +4 -0
- data/test/data/webby-status-off.xml +4 -0
- data/test/data/webby-status-reboot.xml +4 -0
- data/test/data/webby-status-shutdown.xml +4 -0
- data/test/data/webby-status.xml +4 -0
- data/test/webbynode-api_test.rb +76 -1
- data/webbynode-api.gemspec +59 -0
- metadata +14 -2
data/README.rdoc
CHANGED
@@ -1,6 +1,51 @@
|
|
1
1
|
= webbynode-api
|
2
2
|
|
3
|
-
|
3
|
+
This gem wraps the API available for the VPS hosting company
|
4
|
+
{WebbyNode}[http://www.webbynode.com]. Details and a preliminary
|
5
|
+
design document for the API itself are available
|
6
|
+
{here}[http://howto.webbynode.com/topic.php?id=25]. Functionality
|
7
|
+
is currently based on the API guide version 1.
|
8
|
+
|
9
|
+
== Currently Supported API functionality
|
10
|
+
* Client information such as account status, contact/address info, credit
|
11
|
+
* Webby information (status) and simple actions (start, shutdown, reboot)
|
12
|
+
* DNS zone information such as domain name, TTL, and status
|
13
|
+
|
14
|
+
== In Development
|
15
|
+
* DNS record information such as type, data, name, id, and TTL
|
16
|
+
|
17
|
+
== Planned Features
|
18
|
+
* DNS zone/record creation, editing and deletion
|
19
|
+
* Whatever else WebbyNode gives us in the API :)
|
20
|
+
|
21
|
+
== Example Usage
|
22
|
+
=== Account
|
23
|
+
require 'webbynode-api'
|
24
|
+
email = "example@email.com"
|
25
|
+
api_key = "1234567890abcdef"
|
26
|
+
@client = WebbyNode::Client.new(email, api_key)
|
27
|
+
puts @client.firstname
|
28
|
+
|
29
|
+
=== Webby
|
30
|
+
require 'webbynode-api'
|
31
|
+
email = "example@email.com"
|
32
|
+
api_key = "1234567890abcdef"
|
33
|
+
hostname = "webby1"
|
34
|
+
@webby = WebbyNode::Webby.new(email, api_key, hostname)
|
35
|
+
@webby.status
|
36
|
+
@webby.shutdown
|
37
|
+
@webby.status
|
38
|
+
|
39
|
+
=== DNS
|
40
|
+
require 'webbynode-api'
|
41
|
+
email = "example@email.com"
|
42
|
+
api_key = "1234567890abcdef"
|
43
|
+
zone_id = 123
|
44
|
+
@dns = WebbyNode::DNS.new(email, api_key)
|
45
|
+
pp @dns.zones
|
46
|
+
@dns = WebbyNode::DNS.new(email, api_key, zone_id)
|
47
|
+
pp @dns.domain
|
48
|
+
pp @dns.records
|
4
49
|
|
5
50
|
== Copyright
|
6
51
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/webbynode-api.rb
CHANGED
@@ -3,28 +3,32 @@ gem 'httparty'
|
|
3
3
|
require 'httparty'
|
4
4
|
|
5
5
|
class WebbyNode
|
6
|
-
class
|
6
|
+
class APIObject
|
7
7
|
include HTTParty
|
8
8
|
base_uri "https://manager.webbynode.com"
|
9
9
|
format :xml
|
10
10
|
|
11
11
|
attr_accessor :email, :api_key, :data
|
12
12
|
|
13
|
+
# Creates a new API object secured by e-mail address and API token
|
13
14
|
def initialize(email, api_key)
|
14
15
|
@email = email
|
15
16
|
@api_key = api_key
|
16
|
-
@data = self.auth_get('/api/xml/client')["hash"]["client"]
|
17
17
|
end
|
18
18
|
|
19
|
+
# Uses HTTParty to submit a secure API request via email address and token
|
19
20
|
def auth_get(url, options = {})
|
20
21
|
options[:query] ||= {}
|
21
22
|
options[:query].merge!(:email => @email, :token => @api_key)
|
22
23
|
self.class.get(url, options)
|
23
24
|
end
|
24
25
|
|
26
|
+
# Catches simple requests for specific API data returned via a hash
|
25
27
|
def method_missing(method)
|
26
|
-
key = @data[method.to_s]
|
28
|
+
key = @data[method.to_s] if @data
|
27
29
|
key
|
28
30
|
end
|
29
31
|
end
|
30
|
-
end
|
32
|
+
end
|
33
|
+
|
34
|
+
require File.join(File.dirname(__FILE__), 'webbynode-api', 'data')
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class WebbyNode
|
2
|
+
# Represents the account-holder's information
|
3
|
+
class Client < WebbyNode::APIObject
|
4
|
+
def initialize(email, api_key)
|
5
|
+
super(email, api_key)
|
6
|
+
@data = auth_get("/api/xml/client")["hash"]["client"]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Represents an individual webby with status, reboot/shutdown/start functionality
|
11
|
+
# via +method_missing+
|
12
|
+
class Webby < WebbyNode::APIObject
|
13
|
+
attr_accessor :hostname
|
14
|
+
|
15
|
+
def initialize(email, api_key, hostname)
|
16
|
+
super(email, api_key)
|
17
|
+
@hostname = hostname
|
18
|
+
end
|
19
|
+
|
20
|
+
def method_missing(method)
|
21
|
+
if method.to_s == "status"
|
22
|
+
return auth_get("/api/xml/webby/#{@hostname}/status")["hash"]["status"]
|
23
|
+
elsif %w(start shutdown reboot).include? method.to_s
|
24
|
+
return auth_get("/api/xml/webby/#{@hostname}/#{method.to_s}")["hash"]["job_id"]
|
25
|
+
else
|
26
|
+
raise "No such action possible on a Webby."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class DNS < WebbyNode::APIObject
|
32
|
+
attr_accessor :id
|
33
|
+
|
34
|
+
# Optionally takes an ID as the third argument to fetch just that zone. Without,
|
35
|
+
# you get an array of all zones.
|
36
|
+
def initialize(email, api_key, id = nil)
|
37
|
+
super(email, api_key)
|
38
|
+
if id
|
39
|
+
@id = id
|
40
|
+
@data = auth_get("/api/xml/dns/#{@id}")["hash"]["zone"]
|
41
|
+
else
|
42
|
+
@data = auth_get("/api/xml/dns")["hash"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def records
|
47
|
+
raise "This method should only be called on DNS instances with an id." unless @id
|
48
|
+
auth_get("/api/xml/dns/#{@id}/records")["hash"]["records"]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
File without changes
|
data/test/data/dns-1.xml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
<!-- Courtesy of the WebbyNode API guide, version 1, page 10 -->
|
2
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
3
|
+
<hash>
|
4
|
+
<records type="array">
|
5
|
+
<record>
|
6
|
+
<type>A</type>
|
7
|
+
<aux type="integer">0</aux>
|
8
|
+
<name/>
|
9
|
+
<data>200.100.200.100</data>
|
10
|
+
<id type="integer">51</id>
|
11
|
+
<ttl type="integer">86400</ttl>
|
12
|
+
</record>
|
13
|
+
<record>
|
14
|
+
<type>A</type>
|
15
|
+
<aux type="integer">0</aux>
|
16
|
+
<name>*</name>
|
17
|
+
<data>200.100.200.100</data>
|
18
|
+
<id type="integer">26</id>
|
19
|
+
<ttl type="integer">86400</ttl>
|
20
|
+
</record>
|
21
|
+
</records>
|
22
|
+
</hash>
|
data/test/data/dns.xml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<hash>
|
3
|
+
<zones type="array">
|
4
|
+
<zone>
|
5
|
+
<status>Active</status>
|
6
|
+
<ttl type="integer">86400</ttl>
|
7
|
+
<domain>example.com.</domain>
|
8
|
+
<id type="integer">1</id>
|
9
|
+
</zone>
|
10
|
+
<zone>
|
11
|
+
<status>Active</status>
|
12
|
+
<ttl type="integer">7200</ttl>
|
13
|
+
<domain>fluid.com.</domain>
|
14
|
+
<id type="integer">111</id>
|
15
|
+
</zone>
|
16
|
+
<zone>
|
17
|
+
<status>Inactive</status>
|
18
|
+
<ttl type="integer">86400</ttl>
|
19
|
+
<domain>inactive.com.</domain>
|
20
|
+
<id type="integer">132</id>
|
21
|
+
</zone>
|
22
|
+
</zones>
|
23
|
+
</hash>
|
data/test/webbynode-api_test.rb
CHANGED
@@ -6,7 +6,7 @@ class WebbynodeApiTest < Test::Unit::TestCase
|
|
6
6
|
email = "example@email.com"
|
7
7
|
api_key = "123456"
|
8
8
|
data_path = File.join(File.dirname(__FILE__), "data")
|
9
|
-
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/client\?.+/i, :body => File.read("#{data_path}/
|
9
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/client\?.+/i, :body => File.read("#{data_path}/client.xml"))
|
10
10
|
@api = WebbyNode::Client.new(email, api_key)
|
11
11
|
end
|
12
12
|
|
@@ -41,4 +41,79 @@ class WebbynodeApiTest < Test::Unit::TestCase
|
|
41
41
|
@api.phonenumber.should == "555-867-5309"
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
context "fetching webbies data from API" do
|
46
|
+
setup do
|
47
|
+
email = "example@email.com"
|
48
|
+
api_key = "123456"
|
49
|
+
hostname = "webby1"
|
50
|
+
data_path = File.join(File.dirname(__FILE__), "data")
|
51
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/start\?.+/i, :body => File.read("#{data_path}/webby-start.xml"))
|
52
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/shutdown\?.+/i, :body => File.read("#{data_path}/webby-shutdown.xml"))
|
53
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/reboot\?.+/i, :body => File.read("#{data_path}/webby-reboot.xml"))
|
54
|
+
@webby = WebbyNode::Webby.new(email, api_key, hostname)
|
55
|
+
end
|
56
|
+
should "return a job ID when starting, shutting down, or rebooting" do
|
57
|
+
@webby.start.should == 2562
|
58
|
+
@webby.shutdown.should == 2561
|
59
|
+
@webby.reboot.should == 2564
|
60
|
+
end
|
61
|
+
should "return a valid status" do
|
62
|
+
data_path = File.join(File.dirname(__FILE__), "data")
|
63
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status.xml"))
|
64
|
+
@webby.status.should == "on"
|
65
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-shutdown.xml"))
|
66
|
+
@webby.status.should == "Shutting down"
|
67
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-off.xml"))
|
68
|
+
@webby.status.should == "off"
|
69
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-reboot.xml"))
|
70
|
+
@webby.status.should == "Rebooting"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "fetching DNS data from API without id" do
|
75
|
+
setup do
|
76
|
+
email = "example@email.com"
|
77
|
+
api_key = "123456"
|
78
|
+
data_path = File.join(File.dirname(__FILE__), "data")
|
79
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
|
80
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
|
81
|
+
@dns = WebbyNode::DNS.new(email, api_key)
|
82
|
+
end
|
83
|
+
should "return an array of zones with domain, status, id, and TTL" do
|
84
|
+
@dns.zones.is_a?(Array).should be(true)
|
85
|
+
@dns.zones.size.should == 3
|
86
|
+
zone = @dns.zones.first
|
87
|
+
zone["id"].should == 1
|
88
|
+
zone["status"].should == "Active"
|
89
|
+
zone["domain"].should == "example.com."
|
90
|
+
zone["ttl"].should == 86400
|
91
|
+
zone = @dns.zones.last
|
92
|
+
zone["id"].should == 132
|
93
|
+
zone["status"].should == "Inactive"
|
94
|
+
zone["domain"].should == "inactive.com."
|
95
|
+
zone["ttl"].should == 86400
|
96
|
+
end
|
97
|
+
end
|
98
|
+
context "fetching DNS data from API with id" do
|
99
|
+
setup do
|
100
|
+
email = "example@email.com"
|
101
|
+
api_key = "123456"
|
102
|
+
id = 1
|
103
|
+
data_path = File.join(File.dirname(__FILE__), "data")
|
104
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
|
105
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
|
106
|
+
FakeWeb.register_uri(:get, /https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\/records\?.+/i, :body => File.read("#{data_path}/dns-records.xml"))
|
107
|
+
@dns = WebbyNode::DNS.new(email, api_key, id)
|
108
|
+
end
|
109
|
+
should "return domain name, status, id and TTL" do
|
110
|
+
@dns.domain.should == "example.com."
|
111
|
+
@dns.id.should == 1
|
112
|
+
@dns.ttl.should == 86400
|
113
|
+
@dns.status.should == "Active"
|
114
|
+
end
|
115
|
+
should "return an array of records with id, type, name, data, auxiliary data, and TTL" do
|
116
|
+
@dns.records.is_a?(Array).should be(true)
|
117
|
+
end
|
118
|
+
end
|
44
119
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{webbynode-api}
|
5
|
+
s.version = "0.0.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Shane Sveller"]
|
9
|
+
s.date = %q{2009-07-10}
|
10
|
+
s.email = %q{shanesveller@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/webbynode-api.rb",
|
23
|
+
"lib/webbynode-api/data.rb",
|
24
|
+
"test/data/client.xml",
|
25
|
+
"test/data/dns-1.xml",
|
26
|
+
"test/data/dns-records.xml",
|
27
|
+
"test/data/dns.xml",
|
28
|
+
"test/data/webby-reboot.xml",
|
29
|
+
"test/data/webby-shutdown.xml",
|
30
|
+
"test/data/webby-start.xml",
|
31
|
+
"test/data/webby-status-off.xml",
|
32
|
+
"test/data/webby-status-reboot.xml",
|
33
|
+
"test/data/webby-status-shutdown.xml",
|
34
|
+
"test/data/webby-status.xml",
|
35
|
+
"test/test_helper.rb",
|
36
|
+
"test/webbynode-api_test.rb",
|
37
|
+
"webbynode-api.gemspec"
|
38
|
+
]
|
39
|
+
s.has_rdoc = true
|
40
|
+
s.homepage = %q{http://github.com/shanesveller/webbynode-api}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.1}
|
44
|
+
s.summary = %q{wraps the WebbyNode API into nice Ruby objects}
|
45
|
+
s.test_files = [
|
46
|
+
"test/test_helper.rb",
|
47
|
+
"test/webbynode-api_test.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 2
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
+
else
|
56
|
+
end
|
57
|
+
else
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shanesveller-webbynode-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Sveller
|
@@ -30,9 +30,21 @@ files:
|
|
30
30
|
- Rakefile
|
31
31
|
- VERSION
|
32
32
|
- lib/webbynode-api.rb
|
33
|
-
-
|
33
|
+
- lib/webbynode-api/data.rb
|
34
|
+
- test/data/client.xml
|
35
|
+
- test/data/dns-1.xml
|
36
|
+
- test/data/dns-records.xml
|
37
|
+
- test/data/dns.xml
|
38
|
+
- test/data/webby-reboot.xml
|
39
|
+
- test/data/webby-shutdown.xml
|
40
|
+
- test/data/webby-start.xml
|
41
|
+
- test/data/webby-status-off.xml
|
42
|
+
- test/data/webby-status-reboot.xml
|
43
|
+
- test/data/webby-status-shutdown.xml
|
44
|
+
- test/data/webby-status.xml
|
34
45
|
- test/test_helper.rb
|
35
46
|
- test/webbynode-api_test.rb
|
47
|
+
- webbynode-api.gemspec
|
36
48
|
has_rdoc: true
|
37
49
|
homepage: http://github.com/shanesveller/webbynode-api
|
38
50
|
post_install_message:
|