shanesveller-webbynode-api 0.1.0 → 0.1.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -67,90 +67,4 @@ class WebbyNode
67
67
  @data = auth_get("/api/xml/webbies")["hash"]["webbies"]
68
68
  end
69
69
  end
70
-
71
- # Represents the DNS zones present on the API account
72
- #
73
- # @author Shane Sveller
74
- # @since 0.0.2
75
- # @version 0.1.0
76
- class DNS < WebbyNode::APIObject
77
- # Holds the ID used internally at WebbyNode that represents a given zone.
78
- attr_accessor :id
79
-
80
- # Fetches either a single zone or an Array of all zones based on the presence
81
- # of the id parameter.
82
- #
83
- # @option options [String] :email E-mail address used for API access
84
- # @option options [String] :token API token used for API access
85
- # @option options [Integer] :id ID that represents an individual zone
86
- # @raise [ArgumentError] Raises ArgumentError if the :id option is missing
87
- # from the optins parameter.
88
- def initialize(options = {})
89
- raise ArgumentError, ":id is a required argument" unless options[:id]
90
- super(options)
91
- @id = options[:id]
92
- @data = auth_get("/api/xml/dns/#{@id}")["hash"]["zone"]
93
- end
94
-
95
- # @since 0.0.3
96
- # @return [Array<Hash>] Array of a zones' records, each individually is a Hash.
97
- def records
98
- raise "This method should only be called on DNS instances with an id" unless @id
99
- auth_get("/api/xml/dns/#{@id}/records")["hash"]["records"]
100
- end
101
-
102
- # @since 0.0.6
103
- # @option options [String] :email E-mail address used for API access
104
- # @option options [String] :token API token used for API access
105
- # @option options [optional, String] :status Optional argument to set the
106
- # status of the zone. Valid values include 'Active' or 'Inactive' only.
107
- # @return [Hash] Hash of the new zone's information
108
- # @raise [ArgumentError] Raises ArgumentError if :token, :email, :domain,
109
- # or :ttl are missing from the options parameter.
110
- def self.new_zone(options = {})
111
- raise ArgumentError, "API access information via :email and :token are required arguments" unless options[:email] && options[:token]
112
- raise ArgumentError, ":domain and :ttl are required arguments" unless options[:domain] && options[:ttl]
113
- if options[:status]
114
- raise ArgumentError, ":status must be 'Active' or 'Inactive'" unless %w(Active Inactive).include? options[:status]
115
- end
116
- zone_data = auth_post("/api/xml/dns/new", :query =>
117
- {
118
- :email => options[:email],
119
- :token => options[:token],
120
- "zone[domain]" => options[:domain],
121
- "zone[ttl]" => options[:ttl],
122
- "zone[status]" => options[:status]
123
- })
124
- return zone_data["hash"]
125
- end
126
-
127
- # @since 0.0.6
128
- # @option options [String] :email E-mail address used for API access
129
- # @option options [String] :token API token used for API access
130
- # @option options [Integer] :id WebbyNode's internally-used ID that idenftifies the zone
131
- # @return [Boolean] Returns true upon succesful deletion of the zone.
132
- # @raise [ArgumentError] Raises ArgumentError if :token, :email, or :id are
133
- # missing from the options parameter.
134
- def self.delete_zone(options = {})
135
- raise ArgumentError, "API access information via :email and :token are required arguments" unless options[:email] && options[:token]
136
- raise ArgumentError, ":id is a required argument" unless options[:id]
137
- return auth_post("/api/xml/dns/#{options[:id]}/delete", :query => options)["hash"]["success"]
138
- end
139
- end
140
-
141
- # Represents an Array of all DNS zones present on the API account
142
- #
143
- # @author Shane Sveller
144
- # @since 0.1.0
145
- # @version 0.1.0
146
- class DNSList < WebbyNode::APIObject
147
- # Fetches an Array of all zones into @data.
148
- #
149
- # @option options [String] :email E-mail address used for API access
150
- # @option options [String] :token API token used for API access
151
- def initialize(options = {})
152
- super(options)
153
- @data = auth_get("/api/xml/dns")["hash"]["zones"]
154
- end
155
- end
156
70
  end
@@ -0,0 +1,130 @@
1
+ class WebbyNode
2
+ class DNS
3
+ # Represents the DNS zones present on the API account
4
+ #
5
+ # @author Shane Sveller
6
+ # @since 0.0.2
7
+ # @version 0.1.0
8
+ class Zone < WebbyNode::APIObject
9
+ # Holds the ID used internally at WebbyNode that represents a given zone.
10
+ attr_accessor :id
11
+
12
+ # Fetches either a single zone or an Array of all zones based on the presence
13
+ # of the id parameter.
14
+ #
15
+ # @option options [String] :email E-mail address used for API access
16
+ # @option options [String] :token API token used for API access
17
+ # @option options [Integer] :id ID that represents an individual zone
18
+ # @raise [ArgumentError] Raises ArgumentError if the :id option is missing
19
+ # from the optins parameter.
20
+ # @example Get a zone with ID 100
21
+ # @zone = WebbyNode::DNS::Zone.new(:email => email, :token => token, :id => 100)
22
+ def initialize(options = {})
23
+ raise ArgumentError, ":id is a required argument" unless options[:id]
24
+ super(options)
25
+ @id = options[:id]
26
+ @data = auth_get("/api/xml/dns/#{@id}")["hash"]["zone"]
27
+ end
28
+
29
+ # Activates a DNS zone in WebbyNode's DNS servers
30
+ #
31
+ # @since 0.1.2
32
+ # @return [String] Returns "Active" if successful
33
+ # @example Activate a zone with ID 100
34
+ # @zone = WebbyNode::DNS::Zone.new(:email => email, :token => token, :id => 100)
35
+ # @zone.status
36
+ # # => "Inactive"
37
+ # @zone.activate
38
+ # # => "Active"
39
+ def activate
40
+ status = auth_post("/api/xml/dns/#{@id}", {:query => {"zone[status]" => "Active", :email => @email, :token => @token}})["hash"]["status"]
41
+ raise "Unable to activate zone" unless status == "Active"
42
+ return status
43
+ end
44
+
45
+ # Activates a DNS zone in WebbyNode's DNS servers
46
+ #
47
+ # @since 0.1.2
48
+ # @return [String] Returns "Inactive" if successful
49
+ # @example Deactivate a zone with ID 100
50
+ # @zone = WebbyNode::DNS::Zone.new(:email => email, :token => token, :id => 100)
51
+ # @zone.status
52
+ # # => "Active"
53
+ # @zone.deactivate
54
+ # # => "Inactive"
55
+ def deactivate
56
+ status = auth_post("/api/xml/dns/#{@id}", {:query => {"zone[status]" => "Inactive", :email => @email, :token => @token}})["hash"]["status"]
57
+ raise "Unable to deactivate zone" unless status == "Inactive"
58
+ return status
59
+ end
60
+
61
+ # @since 0.0.6
62
+ # @option options [String] :email E-mail address used for API access
63
+ # @option options [String] :token API token used for API access
64
+ # @option options [optional, String] :status Optional argument to set the
65
+ # status of the zone. Valid values include 'Active' or 'Inactive' only.
66
+ # @return [Hash] Hash of the new zone's information
67
+ # @raise [ArgumentError] Raises ArgumentError if :token, :email, :domain,
68
+ # or :ttl are missing from the options parameter.
69
+ def self.create_zone(options = {})
70
+ raise ArgumentError, "API access information via :email and :token are required arguments" unless options[:email] && options[:token]
71
+ raise ArgumentError, ":domain and :ttl are required arguments" unless options[:domain] && options[:ttl]
72
+ if options[:status]
73
+ raise ArgumentError, ":status must be 'Active' or 'Inactive'" unless %w(Active Inactive).include? options[:status]
74
+ end
75
+ zone_data = auth_post("/api/xml/dns/new", :query =>
76
+ {
77
+ :email => options[:email],
78
+ :token => options[:token],
79
+ "zone[domain]" => options[:domain],
80
+ "zone[ttl]" => options[:ttl],
81
+ "zone[status]" => options[:status]
82
+ })
83
+ return zone_data["hash"]
84
+ end
85
+
86
+ # @since 0.0.6
87
+ # @option options [String] :email E-mail address used for API access
88
+ # @option options [String] :token API token used for API access
89
+ # @option options [Integer] :id WebbyNode's internally-used ID that idenftifies the zone
90
+ # @return [Boolean] Returns true upon succesful deletion of the zone.
91
+ # @raise [ArgumentError] Raises ArgumentError if :token, :email, or :id are
92
+ # missing from the options parameter.
93
+ def self.delete_zone(options = {})
94
+ raise ArgumentError, "API access information via :email and :token are required arguments" unless options[:email] && options[:token]
95
+ raise ArgumentError, ":id is a required argument" unless options[:id]
96
+ return auth_post("/api/xml/dns/#{options[:id]}/delete", :query => options)["hash"]["success"]
97
+ end
98
+ end
99
+
100
+ # Represents an Array of all DNS zones present on the API account
101
+ #
102
+ # @author Shane Sveller
103
+ # @since 0.1.0
104
+ # @version 0.1.0
105
+ class ZoneList < WebbyNode::APIObject
106
+ # Fetches an Array of all zones into @data.
107
+ #
108
+ # @option options [String] :email E-mail address used for API access
109
+ # @option options [String] :token API token used for API access
110
+ def initialize(options = {})
111
+ super(options)
112
+ @data = auth_get("/api/xml/dns")["hash"]["zones"]
113
+ end
114
+ end
115
+
116
+ # Represents an Array of all DNS records for a given zone
117
+ #
118
+ # @author Shane Sveller
119
+ # @since 0.1.1
120
+ # @version 0.1.0
121
+ class RecordList < WebbyNode::APIObject
122
+ def initialize(options = {})
123
+ raise ArgumentError, ":id is a required argument" unless options[:id]
124
+ super(options)
125
+ @id = options[:id]
126
+ @data = auth_get("/api/xml/dns/#{@id}/records")["hash"]["records"]
127
+ end
128
+ end
129
+ end
130
+ end
data/lib/webbynode-api.rb CHANGED
@@ -82,4 +82,4 @@ class WebbyNode
82
82
  end
83
83
  end
84
84
 
85
- require File.join(File.dirname(__FILE__), 'webbynode-api', 'data')
85
+ Dir["#{File.dirname(__FILE__)}/webbynode-api/*.rb"].each {|file| require file}
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class WebbyNodeAPIObjectTest < Test::Unit::TestCase
4
+ context "with bad API token or email" do
5
+ setup do
6
+ @email ="example@email.com"
7
+ @token = "123456"
8
+ data_path = File.join(File.dirname(__FILE__), "data")
9
+ FakeWeb.clean_registry
10
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/client\?\w+/i, :body => File.read("#{data_path}/bad-auth.xml"))
11
+ FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/.+$/, :body => "")
12
+ end
13
+ should "raise ArgumentError if no API data given" do
14
+ # for auth_get
15
+ assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::Client.new(:email => nil, :token => nil) }
16
+ assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::Client.new(:email => @email, :token => nil) }
17
+ assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::Client.new(:email => nil, :token => @token) }
18
+ # for auth_post
19
+ assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::APIObject.new(:email => nil, :token => nil).auth_post("",{}) }
20
+ assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::APIObject.new(:email => @email, :token => nil).auth_post("",{}) }
21
+ assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::APIObject.new(:email => nil, :token => @token).auth_post("",{}) }
22
+ end
23
+ should "raise ArgumentError if bad API data given" do
24
+ assert_raise(ArgumentError, "Probable bad API information given"){ WebbyNode::Client.new(@email, @token) }
25
+ # TODO: Need XML fixture file for this
26
+ # assert_raise(ArgumentError, "Probable bad API information given"){ WebbyNode::APIObject.new(@email, @token).auth_post("",{}) }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class WebbyNodeClientTest < Test::Unit::TestCase
4
+ context "fetching client data from API" do
5
+ setup do
6
+ email = "example@email.com"
7
+ token = "123456"
8
+ data_path = File.join(File.dirname(__FILE__), "data")
9
+ FakeWeb.clean_registry
10
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/client\?.+/i, :body => File.read("#{data_path}/client.xml"))
11
+ @api = WebbyNode::Client.new(:email => email, :token => token)
12
+ end
13
+
14
+ should "use method missing to get values for present keys" do
15
+ @api.methods.include?("firstname").should == false
16
+ @api.firstname.should == "Shane"
17
+ end
18
+
19
+ should "return nil for missing keys" do
20
+ @api.blank.should be(nil)
21
+ end
22
+
23
+ should "fetch physical address information" do
24
+ @api.address1.should == "1234 Nonexistent Lane"
25
+ @api.city.should == "Nameless City"
26
+ @api.postcode.should == "65432"
27
+ @api.state.should == "My State"
28
+ @api.country.should == "US"
29
+ end
30
+
31
+ should "fetch user name, email and status" do
32
+ @api.firstname.should == "Shane"
33
+ @api.lastname.should == "Sveller"
34
+ @api.email.should == "example@email.com"
35
+ @api.status.should == "Active"
36
+ @api.datecreated.should == Date.new(2009,06,30)
37
+ end
38
+
39
+ should "fetch company name, phone number and credits" do
40
+ @api.credit.should == 1.5
41
+ @api.companyname.should == "Phantom Inc."
42
+ @api.phonenumber.should == "555-867-5309"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <hash>
3
+ <status>Active</status>
4
+ <ttl type="integer">86400</ttl>
5
+ <domain>example.com.</domain>
6
+ <id type="integer">171</id>
7
+ </hash>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <hash>
3
+ <status>Inactive</status>
4
+ <ttl type="integer">86400</ttl>
5
+ <domain>example.com.</domain>
6
+ <id type="integer">171</id>
7
+ </hash>
data/test/dns_test.rb ADDED
@@ -0,0 +1,143 @@
1
+ require 'test_helper'
2
+
3
+ class WebbyNodeDNSTest < Test::Unit::TestCase
4
+ context "fetching all DNS data from API" do
5
+ setup do
6
+ email = "example@email.com"
7
+ token = "123456"
8
+ data_path = File.join(File.dirname(__FILE__), "data")
9
+ FakeWeb.clean_registry
10
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
11
+ @zones = WebbyNode::DNS::ZoneList.new(:email => email, :token => token)
12
+ end
13
+ should "return an array of zones with domain, status, id, and TTL" do
14
+ @zones.data.is_a?(Array).should be(true)
15
+ @zones.data.size.should == 3
16
+ zone = @zones.data.first
17
+ zone["id"].should == 1
18
+ zone["status"].should == "Active"
19
+ zone["domain"].should == "example.com."
20
+ zone["ttl"].should == 86400
21
+ zone = @zones.data.last
22
+ zone["id"].should == 132
23
+ zone["status"].should == "Inactive"
24
+ zone["domain"].should == "inactive.com."
25
+ zone["ttl"].should == 86400
26
+ end
27
+ end
28
+ context "fetching DNS data from API with id" do
29
+ setup do
30
+ email = "example@email.com"
31
+ token = "123456"
32
+ id = 1
33
+ data_path = File.join(File.dirname(__FILE__), "data")
34
+ FakeWeb.clean_registry
35
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
36
+ @dns = WebbyNode::DNS::Zone.new(:email => email, :token => token, :id => id)
37
+ end
38
+ should "return domain name, status, id and TTL" do
39
+ @dns.domain.should == "example.com."
40
+ @dns.id.should == 1
41
+ @dns.ttl.should == 86400
42
+ @dns.status.should == "Active"
43
+ end
44
+ end
45
+ context "creating a new DNS zone" do
46
+ setup do
47
+ @email = "example@email.com"
48
+ @token = "123456"
49
+ @domain = "example.com."
50
+ @ttl = 86400
51
+ data_path = File.join(File.dirname(__FILE__), "data")
52
+ FakeWeb.clean_registry
53
+ FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/new\?.+/i, :body => File.read("#{data_path}/new-zone.xml"))
54
+ end
55
+ should "raise ArgumentError if API information isn't present" do
56
+ assert_raise(ArgumentError,"API access information via :email and :token are required arguments"){ WebbyNode::DNS::Zone.create_zone(:token => @token, :domain => @domain, :ttl => @ttl) }
57
+ assert_raise(ArgumentError,"API access information via :email and :token are required arguments"){ WebbyNode::DNS::Zone.create_zone(:email => @email, :domain => @domain, :ttl => @ttl) }
58
+ end
59
+ should "raise ArgumentError if :domain or :ttl aren't included in method call" do
60
+ assert_raise(ArgumentError, ":domain and :ttl are required arguments"){ WebbyNode::DNS::Zone.create_zone(:email => @email, :token => @token, :ttl => @ttl) }
61
+ assert_raise(ArgumentError, ":domain and :ttl are required arguments"){ WebbyNode::DNS::Zone.create_zone(:email => @email, :token => @token, :domain => @domain) }
62
+ end
63
+ should "raise ArgumentError if :status is not a valid option" do
64
+ assert_raise(ArgumentError, ":domain and :ttl are required arguments"){ WebbyNode::DNS::Zone.create_zone(:email => @email, :token => @token, :ttl => @ttl, :status => "Not active") }
65
+ assert_nothing_raised(ArgumentError){ WebbyNode::DNS::Zone.create_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => "Active") }
66
+ assert_nothing_raised(ArgumentError){ WebbyNode::DNS::Zone.create_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => "Inactive") }
67
+ assert_nothing_raised(ArgumentError){ WebbyNode::DNS::Zone.create_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => nil) }
68
+ end
69
+ should "return a Hash containing the new zone's information" do
70
+ @new_zone = WebbyNode::DNS::Zone.create_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => "Inactive")
71
+ @new_zone["id"].should == 171
72
+ @new_zone["domain"].should == "example.com."
73
+ @new_zone["ttl"].should == 86400
74
+ end
75
+ end
76
+ context "deleting a DNS zone" do
77
+ setup do
78
+ @email = "example@email.com"
79
+ @token = "123456"
80
+ @id = 171
81
+ data_path = File.join(File.dirname(__FILE__), "data")
82
+ FakeWeb.clean_registry
83
+ FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\/delete\?.+/i, :body => File.read("#{data_path}/delete-zone.xml"))
84
+ end
85
+ should "return a boolean true for succesful deletion" do
86
+ WebbyNode::DNS::Zone.delete_zone(:email => @email, :token => @token, :id => @id)
87
+ end
88
+ end
89
+ context "activating and deactivating a zone" do
90
+ setup do
91
+ @email = "example@email.com"
92
+ @token = "123456"
93
+ @id = 171
94
+ end
95
+ should "raise RuntimeError if the action is unsuccesful" do
96
+ data_path = File.join(File.dirname(__FILE__), "data")
97
+ FakeWeb.clean_registry
98
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
99
+ FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/deactivate-zone.xml"))
100
+ assert_raise(RuntimeError, "Unable to activate zone"){ WebbyNode::DNS::Zone.new(:email => @email, :token => @token, :id => @id).activate }
101
+ FakeWeb.clean_registry
102
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
103
+ FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/activate-zone.xml"))
104
+ assert_raise(RuntimeError, "Unable to deactivate zone"){ WebbyNode::DNS::Zone.new(:email => @email, :token => @token, :id => @id).deactivate }
105
+ end
106
+ should "return the new status when activating or deactivating" do
107
+ data_path = File.join(File.dirname(__FILE__), "data")
108
+ FakeWeb.clean_registry
109
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
110
+ FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/activate-zone.xml"))
111
+ WebbyNode::DNS::Zone.new(:email => @email, :token => @token, :id => @id).activate.should == "Active"
112
+ FakeWeb.clean_registry
113
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
114
+ FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/deactivate-zone.xml"))
115
+ WebbyNode::DNS::Zone.new(:email => @email, :token => @token, :id => @id).deactivate.should == "Inactive"
116
+ end
117
+ end
118
+ context "listing a DNS zone's records" do
119
+ setup do
120
+ @email = "example@email.com"
121
+ @token = "123456"
122
+ @id = 1
123
+ data_path = File.join(File.dirname(__FILE__), "data")
124
+ FakeWeb.clean_registry
125
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\/records\?.+/i, :body => File.read("#{data_path}/dns-records.xml"))
126
+ end
127
+ should "raise ArgumentError if :id argument is absent" do
128
+ assert_raise(ArgumentError, ":id is a required argument"){ WebbyNode::DNS::RecordList.new(:email => @email, :token => @token, :id => nil)}
129
+ assert_nothing_raised { WebbyNode::DNS::RecordList.new(:email => @email, :token => @token, :id => @id)}
130
+ end
131
+ should "set @data to an Array of records" do
132
+ @records = WebbyNode::DNS::RecordList.new(:email => @email, :token => @token, :id => @id)
133
+ @records.data.is_a?(Array).should be(true)
134
+ record = @records.data.first
135
+ record["id"].should == 51
136
+ record["ttl"].should == 86400
137
+ record["data"].should == "200.100.200.100"
138
+ record["name"].should be(nil)
139
+ record["aux"].should == 0
140
+ record["type"].should == "A"
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ class WebbyNodeWebbyTest < Test::Unit::TestCase
4
+ context "fetching webby data from API" do
5
+ setup do
6
+ email = "example@email.com"
7
+ token = "123456"
8
+ hostname = "webby1"
9
+ data_path = File.join(File.dirname(__FILE__), "data")
10
+ FakeWeb.clean_registry
11
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/start\?.+/i, :body => File.read("#{data_path}/webby-start.xml"))
12
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/shutdown\?.+/i, :body => File.read("#{data_path}/webby-shutdown.xml"))
13
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/reboot\?.+/i, :body => File.read("#{data_path}/webby-reboot.xml"))
14
+ @webby = WebbyNode::Webby.new(:email => email, :token => token, :hostname => hostname)
15
+ end
16
+ should "return a job ID when starting, shutting down, or rebooting" do
17
+ @webby.start.should == 2562
18
+ @webby.shutdown.should == 2561
19
+ @webby.reboot.should == 2564
20
+ end
21
+ should "return a valid status" do
22
+ data_path = File.join(File.dirname(__FILE__), "data")
23
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status.xml"))
24
+ @webby.status.should == "on"
25
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-shutdown.xml"))
26
+ @webby.status.should == "Shutting down"
27
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-off.xml"))
28
+ @webby.status.should == "off"
29
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-reboot.xml"))
30
+ @webby.status.should == "Rebooting"
31
+ end
32
+ end
33
+ context "fetching webbies data from API" do
34
+ setup do
35
+ email = "example@email.com"
36
+ token = "123456"
37
+ data_path = File.join(File.dirname(__FILE__), "data")
38
+ FakeWeb.clean_registry
39
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webbies\?.+/i, :body => File.read("#{data_path}/webbies.xml"))
40
+ @webbies = WebbyNode::WebbyList.new(:email => email, :token => token)
41
+ end
42
+ should "return a array of webbies" do
43
+ @webbies.data.is_a?(Array).should be(true)
44
+ webby = @webbies.data.first
45
+ webby["status"].should == "on"
46
+ webby["ip"].should == "222.111.222.111"
47
+ webby["node"].should == "location-a01"
48
+ webby["plan"].should == "Webby_384"
49
+ webby["name"].should == "webby1"
50
+ webby["notes"].should be(nil)
51
+ end
52
+ end
53
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{webbynode-api}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Shane Sveller"]
@@ -23,8 +23,13 @@ Gem::Specification.new do |s|
23
23
  "VERSION",
24
24
  "lib/webbynode-api.rb",
25
25
  "lib/webbynode-api/data.rb",
26
+ "lib/webbynode-api/dns.rb",
27
+ "test/apiobject_test.rb",
28
+ "test/client_test.rb",
29
+ "test/data/activate-zone.xml",
26
30
  "test/data/bad-auth.xml",
27
31
  "test/data/client.xml",
32
+ "test/data/deactivate-zone.xml",
28
33
  "test/data/delete-zone.xml",
29
34
  "test/data/dns-1.xml",
30
35
  "test/data/dns-records.xml",
@@ -38,8 +43,9 @@ Gem::Specification.new do |s|
38
43
  "test/data/webby-status-reboot.xml",
39
44
  "test/data/webby-status-shutdown.xml",
40
45
  "test/data/webby-status.xml",
46
+ "test/dns_test.rb",
41
47
  "test/test_helper.rb",
42
- "test/webbynode-api_test.rb",
48
+ "test/webby_test.rb",
43
49
  "webbynode-api.gemspec"
44
50
  ]
45
51
  s.has_rdoc = true
@@ -49,8 +55,11 @@ Gem::Specification.new do |s|
49
55
  s.rubygems_version = %q{1.3.1}
50
56
  s.summary = %q{wraps the WebbyNode API into nice Ruby objects}
51
57
  s.test_files = [
52
- "test/test_helper.rb",
53
- "test/webbynode-api_test.rb"
58
+ "test/apiobject_test.rb",
59
+ "test/client_test.rb",
60
+ "test/dns_test.rb",
61
+ "test/test_helper.rb",
62
+ "test/webby_test.rb"
54
63
  ]
55
64
 
56
65
  if s.respond_to? :specification_version then
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.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Sveller
@@ -33,8 +33,13 @@ files:
33
33
  - VERSION
34
34
  - lib/webbynode-api.rb
35
35
  - lib/webbynode-api/data.rb
36
+ - lib/webbynode-api/dns.rb
37
+ - test/apiobject_test.rb
38
+ - test/client_test.rb
39
+ - test/data/activate-zone.xml
36
40
  - test/data/bad-auth.xml
37
41
  - test/data/client.xml
42
+ - test/data/deactivate-zone.xml
38
43
  - test/data/delete-zone.xml
39
44
  - test/data/dns-1.xml
40
45
  - test/data/dns-records.xml
@@ -48,8 +53,9 @@ files:
48
53
  - test/data/webby-status-reboot.xml
49
54
  - test/data/webby-status-shutdown.xml
50
55
  - test/data/webby-status.xml
56
+ - test/dns_test.rb
51
57
  - test/test_helper.rb
52
- - test/webbynode-api_test.rb
58
+ - test/webby_test.rb
53
59
  - webbynode-api.gemspec
54
60
  has_rdoc: true
55
61
  homepage: http://github.com/shanesveller/webbynode-api
@@ -78,5 +84,8 @@ signing_key:
78
84
  specification_version: 2
79
85
  summary: wraps the WebbyNode API into nice Ruby objects
80
86
  test_files:
87
+ - test/apiobject_test.rb
88
+ - test/client_test.rb
89
+ - test/dns_test.rb
81
90
  - test/test_helper.rb
82
- - test/webbynode-api_test.rb
91
+ - test/webby_test.rb
@@ -1,219 +0,0 @@
1
- require 'test_helper'
2
-
3
- class WebbynodeApiTest < Test::Unit::TestCase
4
- context "with bad API token or email" do
5
- setup do
6
- @email ="example@email.com"
7
- @token = "123456"
8
- data_path = File.join(File.dirname(__FILE__), "data")
9
- FakeWeb.clean_registry
10
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/client\?\w+/i, :body => File.read("#{data_path}/bad-auth.xml"))
11
- FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/.+$/, :body => "")
12
- end
13
- should "raise ArgumentError if no API data given" do
14
- # for auth_get
15
- assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::Client.new(:email => nil, :token => nil) }
16
- assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::Client.new(:email => @email, :token => nil) }
17
- assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::Client.new(:email => nil, :token => @token) }
18
- # for auth_post
19
- assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::APIObject.new(:email => nil, :token => nil).auth_post("",{}) }
20
- assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::APIObject.new(:email => @email, :token => nil).auth_post("",{}) }
21
- assert_raise(ArgumentError, "API information is missing or incomplete"){ WebbyNode::APIObject.new(:email => nil, :token => @token).auth_post("",{}) }
22
- end
23
- should "raise ArgumentError if bad API data given" do
24
- assert_raise(ArgumentError, "Probable bad API information given"){ WebbyNode::Client.new(@email, @token) }
25
- # TODO: Need XML fixture file for this
26
- # assert_raise(ArgumentError, "Probable bad API information given"){ WebbyNode::APIObject.new(@email, @token).auth_post("",{}) }
27
- end
28
- end
29
- context "fetching client data from API" do
30
- setup do
31
- email = "example@email.com"
32
- token = "123456"
33
- data_path = File.join(File.dirname(__FILE__), "data")
34
- FakeWeb.clean_registry
35
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/client\?.+/i, :body => File.read("#{data_path}/client.xml"))
36
- @api = WebbyNode::Client.new(:email => email, :token => token)
37
- end
38
-
39
- should "use method missing to get values for present keys" do
40
- @api.methods.include?("firstname").should == false
41
- @api.firstname.should == "Shane"
42
- end
43
-
44
- should "return nil for missing keys" do
45
- @api.blank.should be(nil)
46
- end
47
-
48
- should "fetch physical address information" do
49
- @api.address1.should == "1234 Nonexistent Lane"
50
- @api.city.should == "Nameless City"
51
- @api.postcode.should == "65432"
52
- @api.state.should == "My State"
53
- @api.country.should == "US"
54
- end
55
-
56
- should "fetch user name, email and status" do
57
- @api.firstname.should == "Shane"
58
- @api.lastname.should == "Sveller"
59
- @api.email.should == "example@email.com"
60
- @api.status.should == "Active"
61
- @api.datecreated.should == Date.new(2009,06,30)
62
- end
63
-
64
- should "fetch company name, phone number and credits" do
65
- @api.credit.should == 1.5
66
- @api.companyname.should == "Phantom Inc."
67
- @api.phonenumber.should == "555-867-5309"
68
- end
69
- end
70
-
71
- context "fetching webby data from API" do
72
- setup do
73
- email = "example@email.com"
74
- token = "123456"
75
- hostname = "webby1"
76
- data_path = File.join(File.dirname(__FILE__), "data")
77
- FakeWeb.clean_registry
78
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/start\?.+/i, :body => File.read("#{data_path}/webby-start.xml"))
79
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/shutdown\?.+/i, :body => File.read("#{data_path}/webby-shutdown.xml"))
80
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/reboot\?.+/i, :body => File.read("#{data_path}/webby-reboot.xml"))
81
- @webby = WebbyNode::Webby.new(:email => email, :token => token, :hostname => hostname)
82
- end
83
- should "return a job ID when starting, shutting down, or rebooting" do
84
- @webby.start.should == 2562
85
- @webby.shutdown.should == 2561
86
- @webby.reboot.should == 2564
87
- end
88
- should "return a valid status" do
89
- data_path = File.join(File.dirname(__FILE__), "data")
90
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status.xml"))
91
- @webby.status.should == "on"
92
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-shutdown.xml"))
93
- @webby.status.should == "Shutting down"
94
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-off.xml"))
95
- @webby.status.should == "off"
96
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webby\/\w+\/status\?.+/i, :body => File.read("#{data_path}/webby-status-reboot.xml"))
97
- @webby.status.should == "Rebooting"
98
- end
99
- end
100
- context "fetching webbies data from API" do
101
- setup do
102
- email = "example@email.com"
103
- token = "123456"
104
- data_path = File.join(File.dirname(__FILE__), "data")
105
- FakeWeb.clean_registry
106
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/webbies\?.+/i, :body => File.read("#{data_path}/webbies.xml"))
107
- @webbies = WebbyNode::WebbyList.new(:email => email, :token => token)
108
- end
109
- should "return a array of webbies" do
110
- @webbies.data.is_a?(Array).should be(true)
111
- webby = @webbies.data.first
112
- webby["status"].should == "on"
113
- webby["ip"].should == "222.111.222.111"
114
- webby["node"].should == "location-a01"
115
- webby["plan"].should == "Webby_384"
116
- webby["name"].should == "webby1"
117
- webby["notes"].should be(nil)
118
- end
119
- end
120
-
121
- context "fetching all DNS data from API" do
122
- setup do
123
- email = "example@email.com"
124
- token = "123456"
125
- data_path = File.join(File.dirname(__FILE__), "data")
126
- FakeWeb.clean_registry
127
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
128
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
129
- @zones = WebbyNode::DNSList.new(:email => email, :token => token)
130
- end
131
- should "return an array of zones with domain, status, id, and TTL" do
132
- @zones.data.is_a?(Array).should be(true)
133
- @zones.data.size.should == 3
134
- zone = @zones.data.first
135
- zone["id"].should == 1
136
- zone["status"].should == "Active"
137
- zone["domain"].should == "example.com."
138
- zone["ttl"].should == 86400
139
- zone = @zones.data.last
140
- zone["id"].should == 132
141
- zone["status"].should == "Inactive"
142
- zone["domain"].should == "inactive.com."
143
- zone["ttl"].should == 86400
144
- end
145
- end
146
- context "fetching DNS data from API with id" do
147
- setup do
148
- email = "example@email.com"
149
- token = "123456"
150
- id = 1
151
- data_path = File.join(File.dirname(__FILE__), "data")
152
- FakeWeb.clean_registry
153
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
154
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\?.+/i, :body => File.read("#{data_path}/dns-1.xml"))
155
- FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\/records\?.+/i, :body => File.read("#{data_path}/dns-records.xml"))
156
- @dns = WebbyNode::DNS.new(:email => email, :token => token, :id => id)
157
- end
158
- should "return domain name, status, id and TTL" do
159
- @dns.domain.should == "example.com."
160
- @dns.id.should == 1
161
- @dns.ttl.should == 86400
162
- @dns.status.should == "Active"
163
- end
164
- should "return an array of records with id, type, name, data, auxiliary data, and TTL" do
165
- @dns.records.is_a?(Array).should be(true)
166
- record = @dns.records.first
167
- record["id"].should == 51
168
- record["ttl"].should == 86400
169
- record["data"].should == "200.100.200.100"
170
- record["name"].should be(nil)
171
- record["aux"].should == 0
172
- record["type"].should == "A"
173
- end
174
- end
175
- context "creating a new DNS zone" do
176
- setup do
177
- @email = "example@email.com"
178
- @token = "123456"
179
- @domain = "example.com."
180
- @ttl = 86400
181
- data_path = File.join(File.dirname(__FILE__), "data")
182
- FakeWeb.clean_registry
183
- FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/new\?.+/i, :body => File.read("#{data_path}/new-zone.xml"))
184
- end
185
- should "raise ArgumentError if API information isn't present" do
186
- assert_raise(ArgumentError,"API access information via :email and :token are required arguments"){ WebbyNode::DNS.new_zone(:token => @token, :domain => @domain, :ttl => @ttl) }
187
- assert_raise(ArgumentError,"API access information via :email and :token are required arguments"){ WebbyNode::DNS.new_zone(:email => @email, :domain => @domain, :ttl => @ttl) }
188
- end
189
- should "raise ArgumentError if :domain or :ttl aren't included in method call" do
190
- assert_raise(ArgumentError, ":domain and :ttl are required arguments"){ WebbyNode::DNS.new_zone(:email => @email, :token => @token, :ttl => @ttl) }
191
- assert_raise(ArgumentError, ":domain and :ttl are required arguments"){ WebbyNode::DNS.new_zone(:email => @email, :token => @token, :domain => @domain) }
192
- end
193
- should "raise ArgumentError if :status is not a valid option" do
194
- assert_raise(ArgumentError, ":domain and :ttl are required arguments"){ WebbyNode::DNS.new_zone(:email => @email, :token => @token, :ttl => @ttl, :status => "Not active") }
195
- assert_nothing_raised(ArgumentError){ WebbyNode::DNS.new_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => "Active") }
196
- assert_nothing_raised(ArgumentError){ WebbyNode::DNS.new_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => "Inactive") }
197
- assert_nothing_raised(ArgumentError){ WebbyNode::DNS.new_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => nil) }
198
- end
199
- should "return a Hash containing the new zone's information" do
200
- @new_zone = WebbyNode::DNS.new_zone(:email => @email, :token => @token, :domain => @domain, :ttl => @ttl, :status => "Inactive")
201
- @new_zone["id"].should == 171
202
- @new_zone["domain"].should == "example.com."
203
- @new_zone["ttl"].should == 86400
204
- end
205
- end
206
- context "deleting a DNS zone" do
207
- setup do
208
- @email = "example@email.com"
209
- @token = "123456"
210
- @id = 171
211
- data_path = File.join(File.dirname(__FILE__), "data")
212
- FakeWeb.clean_registry
213
- FakeWeb.register_uri(:post, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\/\d+\/delete\?.+/i, :body => File.read("#{data_path}/delete-zone.xml"))
214
- end
215
- should "return a boolean true for succesful deletion" do
216
- WebbyNode::DNS.delete_zone(:email => @email, :token => @token, :id => @id)
217
- end
218
- end
219
- end