Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/OpenCloud/Common/Exceptions/DomainNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright 2012-2014 Rackspace US, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace OpenCloud\Common\Exceptions;

class DomainNotFoundException extends \Exception
{
}
19 changes: 19 additions & 0 deletions lib/OpenCloud/DNS/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use OpenCloud\Common\Http\Message\Formatter;
use OpenCloud\Common\Service\CatalogService;
use OpenCloud\Common\Exceptions\DomainNotFoundException;
use OpenCloud\DNS\Collection\DnsIterator;
use OpenCloud\DNS\Resource\AsyncResponse;
use OpenCloud\DNS\Resource\Domain;
Expand Down Expand Up @@ -55,6 +56,24 @@ public function domain($info = null)
return $this->resource('Domain', $info);
}

/**
* Returns a domain, given a domain name
*
* @param string $domainName Domain name
* @return Domain the domain object
*/
public function domainByName($domainName)
{
$domainList = $this->domainList(array("name" => $domainName));

if (count($domainList) != 1) {
throw new DomainNotFoundException();
}

return $this->resource('Domain', $domainList[0]);
}


/**
* Returns a collection of domains
*
Expand Down
18 changes: 18 additions & 0 deletions tests/OpenCloud/Tests/DNS/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ public function testDomain()
$this->assertInstanceOf('OpenCloud\DNS\Resource\Domain', $this->service->domain());
}

public function testDomainByName()
{
$this->addMockSubscriber($this->makeResponse('{"domains":[{"name":"region2.example.net","id":2725352,"updated":"2011-06-23T20:21:06.000+0000","created":"2011-06-23T19:24:27.000+0000"}],"totalEntries":114}', 200));
$domain = $this->service->domainByName("region2.example.net");

$this->assertInstanceOf('OpenCloud\DNS\Resource\Domain', $domain);
$this->assertEquals("region2.example.net", $domain->getName());
}

/**
* @expectedException OpenCloud\Common\Exceptions\DomainNotFoundException
*/
public function testDomainByNameWhenDomainNotFound()
{
$this->addMockSubscriber($this->makeResponse('{"domains":[],"totalEntries":114}', 200));
$domain = $this->service->domainByName("region2.example.net");
}

/**
* @mockFile Domain_List
*/
Expand Down