shanesveller-webbynode-api 0.2.4 → 0.2.5

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.
@@ -11,6 +11,7 @@ is currently based on the API guide version 2.
11
11
  * Webby information (status) and simple actions (start, shutdown, reboot)
12
12
  * List all webbies
13
13
  * DNS zone information such as domain name, TTL, and status
14
+ * Look up DNS zone by domain name
14
15
  * List of all individual records in a given DNS zone
15
16
  * Creation/deletion of DNS zones
16
17
  * Activation/deactivation of DNS zones
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -142,6 +142,25 @@ class WebbyNode
142
142
  raise ArgumentError, ":id is a required argument" unless options[:id]
143
143
  return auth_post("/api/xml/dns/#{options[:id]}/delete", :query => options)["hash"]["success"]
144
144
  end
145
+
146
+ # @since 0.2.5
147
+ # @option options [String] :email E-mail address used for API access
148
+ # @option options [String] :token API token used for API access
149
+ # @option options [String] :domain Domain name to search for
150
+ # @return [Hash, nil] Returns a hash of data about the zone if it exists
151
+ # or nil
152
+ # @raise [ArgumentError] Raises ArgumentError if :token, :email or :domain
153
+ # are missing from the options parameter
154
+ # @example Look up a zone for the domain "example.com." (Note the final period.)
155
+ # WebbyNode::DNS::Zone.find_by_domain(:email => @email, :token => @token,
156
+ # :domain => "example.com.")
157
+ def self.find_by_domain(options = {})
158
+ raise ArgumentError, ":domain is a required argument" unless options[:domain]
159
+ domain = options[:domain]
160
+ all_zones = ZoneList.new(:email => options[:email], :token => options[:token])
161
+ all_zones.data.reject! {|zone| zone["domain"] != domain}
162
+ return all_zones.data.first || nil
163
+ end
145
164
  end
146
165
 
147
166
  # Represents an Array of all DNS zones present on the API account
@@ -250,4 +250,34 @@ class WebbyNodeDNSTest < Test::Unit::TestCase
250
250
  WebbyNode::DNS::Record.delete(:email => @email, :token => @token, :id => @id)
251
251
  end
252
252
  end
253
+ context "when finding a zone by name" do
254
+ setup do
255
+ @email = "example@email.com"
256
+ @token = "123456"
257
+ @domain = "example.com."
258
+ data_path = File.join(File.dirname(__FILE__), "data", "dns")
259
+ FakeWeb.clean_registry
260
+ FakeWeb.register_uri(:get, /^https:\/\/manager\.webbynode\.com\/api\/xml\/dns\?.+/i, :body => File.read("#{data_path}/dns.xml"))
261
+ end
262
+ should "raise ArgumentError if :domain argument is absent" do
263
+ assert_raise(ArgumentError, ":domain is a required argument"){ WebbyNode::DNS::Zone.find_by_domain(:email => @email, :token => @token, :domain => nil)}
264
+ assert_nothing_raised{ WebbyNode::DNS::Zone.find_by_domain(:email => @email, :token => @token, :domain => @domain)}
265
+ end
266
+ should "return nil unless domain exists in a zone on account" do
267
+ for bad_zone in %w(example2.com baddomain.com nonexistant.com)
268
+ zone = WebbyNode::DNS::Zone.find_by_domain(:email => @email, :token => @token, :domain => bad_zone)
269
+ zone.should be(nil)
270
+ end
271
+ end
272
+ should "return a hash for the domain if a zone exists" do
273
+ zone = WebbyNode::DNS::Zone.find_by_domain(:email => @email, :token => @token, :domain => @domain)
274
+ zone.should_not be(nil)
275
+ zone.is_a?(Hash).should be(true)
276
+ zone["domain"].should == @domain
277
+ zone["id"].should == 1
278
+ zone = WebbyNode::DNS::Zone.find_by_domain(:email => @email, :token => @token, :domain => "inactive.com.")
279
+ zone["domain"].should == "inactive.com."
280
+ zone["id"].should == 132
281
+ end
282
+ end
253
283
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{webbynode-api}
5
- s.version = "0.2.4"
5
+ s.version = "0.2.5"
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"]
9
- s.date = %q{2009-07-17}
9
+ s.date = %q{2009-07-22}
10
10
  s.default_executable = %q{webby}
11
11
  s.email = %q{shanesveller@gmail.com}
12
12
  s.executables = ["webby"]
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.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Sveller
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-17 00:00:00 -07:00
12
+ date: 2009-07-22 00:00:00 -07:00
13
13
  default_executable: webby
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency