      1: <?php
      2: /**
      3:  * Copyright 2012-2014 Rackspace US, Inc.
      4:  *
      5:  * Licensed under the Apache License, Version 2.0 (the "License");
      6:  * you may not use this file except in compliance with the License.
      7:  * You may obtain a copy of the License at
      8:  *
      9:  * http://www.apache.org/licenses/LICENSE-2.0
     10:  *
     11:  * Unless required by applicable law or agreed to in writing, software
     12:  * distributed under the License is distributed on an "AS IS" BASIS,
     13:  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14:  * See the License for the specific language governing permissions and
     15:  * limitations under the License.
     16:  */
     17:
     18: namespace OpenCloud\ObjectStore\Resource;
     19:
     20: /**
     21:  * Represents an account that interacts with the CloudFiles API.
     22:  *
     23:  * @link http://docs.rackspace.com/files/api/v1/cf-devguide/content/Accounts-d1e421.html
     24:  */
     25: class Account extends AbstractResource
     26: {
     27:     const METADATA_LABEL = 'Account';
     28:
     29:     /**
     30:      * @var string The temporary URL secret for this account
     31:      */
     32:     private $tempUrlSecret;
     33:
     34:     public function getUrl($path = null, array $query = array())
     35:     {
     36:         return $this->getService()->getUrl();
     37:     }
     38:
     39:     /**
     40:      * Convenience method.
     41:      *
     42:      * @return \OpenCloud\Common\Metadata
     43:      */
     44:     public function getDetails()
     45:     {
     46:         return $this->retrieveMetadata();
     47:     }
     48:
     49:     /**
     50:      * @return null|string|int
     51:      */
     52:     public function getObjectCount()
     53:     {
     54:         return $this->metadata->getProperty('Object-Count');
     55:     }
     56:
     57:     /**
     58:      * @return null|string|int
     59:      */
     60:     public function getContainerCount()
     61:     {
     62:         return $this->metadata->getProperty('Container-Count');
     63:     }
     64:
     65:     /**
     66:      * @return null|string|int
     67:      */
     68:     public function getBytesUsed()
     69:     {
     70:         return $this->metadata->getProperty('Bytes-Used');
     71:     }
     72:
     73:     /**
     74:      * Sets the secret value for the temporary URL.
     75:      *
     76:      * @link http://docs.rackspace.com/files/api/v1/cf-devguide/content/Set_Account_Metadata-d1a4460.html
     77:      *
     78:      * @param null $secret The value to set the secret to. If left blank, a random hash is generated.
     79:      * @return $this
     80:      */
     81:     public function setTempUrlSecret($secret = null)
     82:     {
     83:         if (!$secret) {
     84:             $secret = sha1(rand(1, 99999));
     85:         }
     86:
     87:         $this->tempUrlSecret = $secret;
     88:
     89:         $this->saveMetadata($this->appendToMetadata(array('Temp-Url-Key' => $secret)));
     90:
     91:         return $this;
     92:     }
     93:
     94:     /**
     95:      * @return null|string
     96:      */
     97:     public function getTempUrlSecret()
     98:     {
     99:         if (null === $this->tempUrlSecret) {
    100:             $this->retrieveMetadata();
    101:             $this->tempUrlSecret = $this->metadata->getProperty('Temp-Url-Key');
    102:         }
    103:
    104:         return $this->tempUrlSecret;
    105:     }
    106: }
    107: