<?php
/**
 * Copyright 2013 Stéphane Depierrepont (aka Toorop)
 *
 * Authors :
 *  - Stéphane Depierrepont (aka Toorop)
 *  - Florian Jensen (aka flosoft) : https://github.com/flosoft
 *  - Gillardeau Thibaut (aka Thibautg16)
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * or in the "license" file accompanying this file. This file 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.
 */

/*
 * cloned from VPS - Slartibardfast - 2014-06-30
*/

namespace Ovh\Ip;

use Guzzle\Http\Message\Response;

use Ovh\Common\AbstractClient;
use Ovh\Common\Exception\BadMethodCallException;

use Ovh\Ip\Exception\IpException;

class IPClient extends AbstractClient
{

    /**
     * Get IPBlockProperties
     *
     * @param string $ipBlock
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getIPBlockProperties($ipblock)
    {
        try {
            $r = $this->get('ip/' . urlencode($ipblock))->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * set IPBlockProperties
     *
     * @param string $description
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException

only seems to return null on success

     */
    public function setIPBlockProperties($ipblock,$description)
    {
		$payload = array(
			'description' => $description
		 );

        try {
            $r = $this->put('ip/' . urlencode($ipblock), array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($payload))->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get IPBlockArp
     *
     * @param string $ipBlock
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getIPBlockArp($ipblock)
    {
        try {
            $r = $this->get('ip/' . urlencode($ipblock) . '/arp')->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get IPBlockedInfo - returns information about the specific IP in the IPBlock
     *
     * @param string $ipBlock
	 * @param string $ip
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getIPBlockedInfo($ipblock, $ip)
    {
        try {
            $r = $this->get('ip/' . urlencode($ipblock) . '/arp/' . $ip)->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get Reverse - returns Reverse IP of selected Block
     *
     * @param string $ipBlock
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getReverse($ipblock)
    {
        try {
            $r = $this->get('ip/' . urlencode($ipblock) . '/reverse/')->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get ReverseProperties - returns information about the specific IP Reverse
     *
     * @param string $ipBlock
	 * @param string $ip
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getReverseProperties($ipblock, $ip)
    {
        try {
            $r = $this->get('ip/' . urlencode($ipblock) . '/reverse/' . $ip)->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Set ReverseProperties - returns information about the specific IP Reverse
     *
     * @param string $ipBlock
	 * @param string $ip
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function setReverseProperties($ipblock,$ip,$reverse)
    {
		if (!$ipblock)
			throw new BadMethodCallException('Parameter $ipblock is missing.');
		if (!$ip)
			throw new BadMethodCallException('Parameter $ip is missing.');
	//	if (!$reverse)
	//		throw new BadMethodCallException('Parameter $reverse is missing.');
	//	if (inet_pton($ip) !== false)
	//		throw new BadMethodCallException('Parameter $ip is invalid.');
	//	if (substr($reverse, -1) != ".")
	//		throw new BadMethodCallException('Parameter $reverse must end in ".".');
		$payload = array(
			'ipReverse' => $ip,
			'reverse' => $reverse
		 );
        try {
            $r = $this->post('ip/' . urlencode($ipblock) . '/reverse', array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($payload))->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

	/*
	* deleteReverseProperties
	*
	* @param string ipblock
	* @param string ip
	*
	* @returns mixed
	*/
	public function deleteReverseProperties($ipblock,$ip)
    {
		if (!$ipblock)
			throw new BadMethodCallException('Parameter $ipblock is missing.');
		if (!$ip)
			throw new BadMethodCallException('Parameter $ip is missing.');
        try {
            $r = $this->delete('ip/' . urlencode($ipblock) . '/reverse/' . $ip)->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get Spam  - returns list of IPs on spam control in block
     *
     * @param string $ipBlock
	 * @param string $spamstate { "blockedForSpam", "unblocked", "unblocking"}
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getSpam($ipblock, $spamstate)
    {
		if (!$ipblock)
			throw new BadMethodCallException('Parameter $ipblock is missing.');
		if (!$spamstate)
			throw new BadMethodCallException('Parameter $spamstate is missing.');
		switch ($spamstate) {
			case "blockedForSpam":
			case "unblocked":
			case "unblocking":
				break;
			default:
				throw new BadMethodCallException('Parameter $spamstate is invalid.');
		}
        try {
            $r = $this->get('ip/' . urlencode($ipblock) . '/spam/?state=' . $spamstate)->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

	/**
     * Get SpamProperties  - returns Properties of IP on Spam
     *
     * @param string $ipBlock
	 * @param string $ipv4
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getSpamProperties($ipblock, $spamstate)
    {
		if (!$ipblock)
			throw new BadMethodCallException('Parameter $ipblock is missing.');
		if (!$ipv4)
			throw new BadMethodCallException('Parameter $ipv4 is missing.');
        try {
            $r = $this->get('ip/' . urlencode($ipblock) . '/spam/' . $ipv4)->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

	/**
     * Get SpamStats  - returns Statistics of IP on Spam
     *
     * @param string $ipBlock
	 * @param string $ipv4
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function getSpamStats($ipblock, $spamstate, $fromdate, $todate)
    {
		if (!$ipblock)
			throw new BadMethodCallException('Parameter $ipblock is missing.');
		if (!$ipv4)
			throw new BadMethodCallException('Parameter $ipv4 is missing.');
		if (!$fromdate)
			throw new BadMethodCallException('Parameter $fromdate is missing.');
		if (!$todate)
			throw new BadMethodCallException('Parameter $todate is missing.');
        try {
            $r = $this->get('ip/' . urlencode($ipblock) . '/spam/' . $ipv4 .'/stats?from='.urlencode($fromdate).'&to='.urlencode($todate))->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Set UnblockSpam - Trigger unblocking of IP on Spam block
     *
     * @param string $ipBlock
	 * @param string $ipv4
     * @return string Json
     * @throws Exception\IpException
     * @throws Exception\IpNotFoundException
     */
	public function setUnblockSpam($ipblock,$ipv4)
    {
		if (!$ipblock)
			throw new BadMethodCallException('Parameter $ipblock is missing.');
		if (!$ipv4)
			throw new BadMethodCallException('Parameter $ipv4 is missing.');

        try {
            $r = $this->post('ip/' . urlencode($ipblock) . '/spam/' . $ipv4 .'/unblock' )->send();
        } catch (\Exception $e) {
            throw new IpException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

/*
		/ip/{ip}/firewall/*				not implemented
		/ip/{ip}/game/*					not implemented
g		/ip/{ip}/license/cpanel 		TODO
g		/ip/{ip}/license/directadmin	TODO
g		/ip/{ip}/license/plesk			TODO
g		/ip/{ip}/license/virtuozzo		TODO
g		/ip/{ip}/license/windows		TODO
	** no worklight? **
g/p		/ip/{ip}/migrationToken			TODO
g/p/d	/ip/{ip}/mitigation/*			TODO
g/p		/ip/{ip}/mitigationProfiles		TODO
post	/ip/{ip}/move					TODO
post	/ip/{ip}/park					TODO
g/p		/ip/{ip}/reverse/*				TODO
g/p		/ip/{ip}/task/p					TODO
p		/ip/{ip}/terminate				TODO

*/
}


<?php

namespace Ovh\Telephony;

use Ovh\Common\Exception\BadConstructorCallException;
use Ovh\Common\Exception\NotImplementedYetByOvhException;
use Ovh\Telephony\TelephonyClient;
use Ovh\Telephony\TelephonyAccountService;

class Telephony
{
	private $billingAccount = null;
	private static $telephonyClient = null;

    /**
     * @param $billingAccount
     *
     * @throws \Ovh\Common\Exception\BadConstructorCallException;
     */
    public function __construct($billingAccount)
    {
        if (!$billingAccount)
            throw new BadConstructorCallException('$billingAccount parameter is missing.');
        $this->setbillingAccount($billingAccount);
    }

    /**
     * Return Telephony client
     *
     * @return SmsClient
     */
    private static function getClient()
    {
        if (!self::$telephonyClient instanceof TelephonyClient){
            self::$telephonyClient = new TelephonyClient();
        };
        return self::$telephonyClient;
    }

    /**
     * Set billingAccount
     *
     * @param string $billingAccount
     */
    public function setBillingAccount($billingAccount)
    {
        $this->billingAccount = $billingAccount;
    }

    /**
     * Get billingAccount
     *
     * @return null | string billingAccount
     */
    public function getBillingAccount()
    {
        return $this->billingAccount;
    }

    /**
     * Get Telephony object properties
     *
     * @return object
     */
    public function getProperties()
    {
        return json_decode(self::getClient()->getProperties($this->billingAccount));
    }

    /**
     * @param array $props (avalaibles keys are callBack and templates)
     * @return boolean
     */
    public function setProperties($props)
    {
        return self::getClient()->setProperties($this->billingAccount, $props);
    }

    /**
     * Get services associated with this billing account.
     * @return array billing accoun services
     */
    public function getBillingAccountServices()
    {
    	$serviceList = json_decode(self::getClient()->getBillingAccountServices($this->billingAccount));

    	$services = array();

    	foreach ($serviceList as $service)
    	{
    		$services[] = new TelephonyAccountService($service, $this);
    	}
    	return $services;
    }

    /**
     * Get infos about the service
     * @return string service info
     */
    public function getServiceInfos()
    {
        return json_decode(self::getClient()->getServiceInfos($this->billingAccount));
    }
}

 ?>


<?php
/**
 * Copyright 2013 Stéphane Depierrepont (aka Toorop)
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * or in the "license" file accompanying this file. This file 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.
 */

/**
 * @todo setDescription
 */

namespace Ovh\Xdsl;

use Ovh\Common\Exception\BadConstructorCallException;
use Ovh\Common\Exception\NotImplementedYetException;

use Ovh\Xdsl\XdslClient;

/**
 *
 */
class Xdsl
{
    /**
     * @var string
     */
    private $id;

    /**
     * @var  \Ovh\Xdsl\XdslClient;
     */
    private static $client;

    /**
     * @var
     */
    private $properties;

    /**
     *
     * @param string $id
     *
     * @throws \Ovh\Common\Exception\BadConstructorCallException;
     */
    public function __construct($id)
    {
        if (!$id)
            throw new BadConstructorCallException("$id parameter is missing.");
        $this->id = (string)$id;
    }

    /**
     * @return XdslClient
     */
    private static function getClient()
    {
        if (!self::$client instanceof XdslClient) {
            self::$client = new XdslClient();
        }
        return self::$client;
    }

    /**
     * Get Raw properties
     *
     * @return object
     */
    public function getProperties()
    {
        $this->properties = json_decode(self::getClient()->getProperties($this->id));
        return $this->properties;
    }

    /**
     * Is IPV6 Enabled
     *
     * @param bool $forceReload
     * @return bool
     */
    public function isIpv6Enabled($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->ipv6Enabled;
    }

    /**
     * Get Status
     *
     * @param bool $forceReload
     * @return string
     */
    public function getStatus($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->status;
    }

    /**
     * Return nb pairs used
     *
     * @param bool $forceReload
     * @return integer
     */
    public function getPairsNumber($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->pairsNumber;
    }

    /**
     * Get description (writtable -> setDescription)
     *
     * @param bool $forceReload
     * @return string
     */
    public function getDescription($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->description;
    }

    /**
     * Get access Type (eg adsl, sdsl,..)
     *
     * @param bool $forceReload
     * @return string
     */
    public function getAccessType($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->accessType;
    }

    /**
     *  Get capabilities
     *
     * @param bool $forceReload
     * @return object
     */
    public function getCapabilities($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->capabilities;
    }

    /**
     * Can we change DSLAM Profile  ?
     *
     * @param bool $forceReload
     * @return boolean
     */
    public function canChangeDslamProfile($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->capabilities->canChangeDslamProfile;
    }

    /**
     * Can we change DSLAM port ?
     *
     * @param bool $forceReload
     * @return boolean
     */
    public function canResetDslamPort($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->capabilities->canResetDslamPort;
    }

    /**
     * Can we change Lns ?
     *
     * @param bool $forceReload
     * @return boolean
     */
    public function canChangeLns($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->capabilities->canChangeLns;
    }

    /**
     * Get address
     *
     * @param bool $forceReload
     * @return object
     */
    public function getAddress($forceReload = false)
    {
        if (!$this->properties || $forceReload)
            $this->getProperties();
        return $this->properties->address;
    }

    /**
     * Set description
     *
     * @param $desc
     */
    public function setDescription($desc)
    {
        self::getClient()->setDescription($this->id, (string)$desc);
    }

    /**
     * Get Pending Action
     *
     * @return object
     */
    public function getPendingAction()
    {
        return json_decode(self::getClient()->getPendingAction($this->id));
    }

    /**
     * Get all tasks
     *
     * @return array
     */
    public function getTasks()
    {
        return json_decode(self::getClient()->getTasks($this->id));
    }

    /**
     * Get task info
     *
     * @param $taskId
     * @return mixed
     */
    public function getTask($taskId)
    {
        return json_decode(self::getClient()->getTask($this->id, $taskId));
    }

    /**
     * Get IP
     *
     * @return array of ips
     */
    public function getIps()
    {
        return json_decode(self::getClient()->getIps($this->id));
    }

    /**
     * Get IP properties
     *
     * @param string $ip
     * @return mixed
     */
    public function getIpProperties($ip)
    {
        return json_decode(self::getClient()->getIpProperties($this->id, $ip));
    }

    /**
     * Get IP monitoring state (enable | disable)
     *
     * @param string $ip
     * @return string enable | disable
     */
    public function ipGetMonitoringState($ip)
    {
        return self::getClient()->ipGetMonitoringState($this->id, $ip);
    }

    /**
     * Get IP version (ipv4 or ipv6)
     *
     * @param  string $ip
     * @return string ipv4 | ipv6
     */
    public function ipGetVersion($ip)
    {
        return self::getClient()->ipGetVersion($this->id, $ip);
    }

    /**
     * Get IP range
     *
     * @param string $ip
     * @return int
     */
    public function ipGetRange($ip)
    {
        return self::getClient()->ipGetRange($this->id, $ip);
    }

    /**
     * Get DNS List for IP
     *
     * @param string $ip
     * @return array of IP
     */
    public function ipGetDnsList($ip)
    {
        return self::getClient()->ipGetDnsList($this->id, $ip);
    }

    /**
     * Get IP reverse
     *
     * @param string $ip
     * @return string
     */
    public function ipGetReverse($ip)
    {
        return self::getClient()->ipGetReverse($this->id, $ip);
    }

    /**
     * Get monitoring notifications for IP
     *
     * @param string $ip
     * @return array
     */
    public function ipGetMonitoringNotifications($ip)
    {
        return json_decode(self::getClient()->ipGetMonitoringNotifications($this->id, $ip));
    }

    /**
     * Set a monitoring notification on IP
     *
     * @param string $ip
     * @param string $frequency
     * @param string $email
     * @param array $sms
     * @return object
     */
    public function ipSetMonitoringNotifications($ip, $frequency = 'once', $email = '', $sms = array())
    {
        return json_decode(self::getClient()->ipSetMonitoringNotifications($this->id, $ip, $frequency, $email, $sms));
    }

    /**
     * Get monitoring notification properties for IP
     *
     * @param  string $ip
     * @param integer $notificationId
     * @return object
     */
    public function ipGetMonitoringNotification($ip, $notificationId)
    {
        return json_decode(self::getClient()->ipGetMonitoringNotification($this->id, $ip, $notificationId));
    }

    /**
     * Update monitoring notification for IP $ip
     *
     * @param string $ip
     * @param integer $notificationId
     * @param string $frequency
     * @param string $email
     * @param string $phone
     * @param bool $enable
     */
    public function ipUpdateMonitoringNotification($ip, $notificationId, $frequency, $email, $phone, $enable)
    {
        self::getClient()->ipUpdateMonitoringNotification($this->id, $ip, $notificationId, $frequency, $email, $phone, $enable);
    }

    /**
     * Delete notification for IP $ip
     *
     * @param string $ip
     * @param string $notificationId
     */
    public function ipDeleteMonitoringNotification($ip, $notificationId)
    {
        self::getClient()->ipDeleteMonitoringNotification($this->id, $ip, $notificationId);
    }

    /**
     * Get lines
     *
     * @return array of string
     */
    public function getLines()
    {
        return json_decode(self::getClient()->getLines($this->id));
    }

    /**
     * Get line properties
     *
     * @todo : dispacth properties (eg getLineDeconsolidation, ...)
     *
     * @param string $line
     * @return object
     */
    public function getLineProperties($line)
    {
        return json_decode(self::getClient()->getLineProperties($this->id, $line));
    }

    /**
     * Reset Dslam port
     * @todo object task
     *
     * @param string $line
     * @return object Task
     */

    public function lineResetDslamPort($line)
    {
        return json_decode(self::getClient()->lineResetDslamPort($this->id, $line));
    }

    /**
     * @todo "Operator sfr not supported"
     * @throws \Ovh\Common\Exception\NotImplementedYetException
     */
    public function lineChangeDslamProfile()
    {
        throw new NotImplementedYetException;
    }

    /**
     * Get available Dslam profile for line $line
     *
     * @param $line
     * @return array of object DslamLineProfile
     */
    public function lineGetAvailableDslamProfiles($line)
    {
        return json_decode(self::getClient()->lineGetAvailableDslamProfiles($this->id, $line));
    }

    /**
     * returm modem properties
     *
     * @return object modem
     */
    public function getModemProperties()
    {
        return json_decode(self::getClient()->getModemProperties($this->id));
    }

    /**
     * Enable IPv6 routing
     *
     * @return object task
     */
    public function enableIpv6()
    {
        return json_decode(self::getClient()->enableIpv6($this->id));
    }

    /**
     * Disable IPv6 routing
     *
     * @return object task
     */
    public function disableIpv6()
    {
        return json_decode(self::getClient()->disableIpv6($this->id));
    }

    /**
     * Resquest ppp credentials (will be sent by mail)
     */
    public function getPppLoginByMail()
    {
        self::getClient()->getPppLoginByMail($this->id);
    }

    /**
     * @todo waiting for sandbox...
     *
     * @throws \Ovh\Common\Exception\NotImplementedYetException
     */
    public function requestTotalDeconsolidation()
    {
        throw new NotImplementedYetException;
    }

    /**
     * Get available Lns
     *
     * @return array of Lns Object (@todo lns object)
     */
    public function getAvailableLns()
    {
        return json_decode(self::getClient()->getAvailableLns($this->id));
    }

    /**
     * Change Lns
     *
     * @param  string $lnsName
     * @return object task
     */
    public function changeLns($lnsName)
    {
        return json_decode(self::getClient()->changeLns($this->id, $lnsName));
    }

}


<?php

namespace Ovh\Telephony;

use Ovh\Common\AbstractClient;
use Ovh\Common\Exception\BadMethodCallException;
use Ovh\Common\Exception\NotImplementedYetByOvhException;
use Ovh\Telephony\Exception\TelephonyAccountServiceException;

class TelephonyAccountServiceClient extends AbstractClient
{
	/**
     * Get Telephony account service properties
     *
     * @param string $service
     * @param Telephony $billingAccount
     * @return string Json
     * @throws Exception\TelephonyAccountServiceException
     * @throws BadMethodCallException
     */
    public function getProperties($service, $billingAccount)
    {
        if (!$service)
            throw new BadMethodCallException('Parameter $service is missing.');
        if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        try {
            $r = $this->get('telephony/' . $billingAccount->getBillingAccount() . '/service/' . $service)->send();
        } catch (\Exception $e) {
            throw new TelephonyAccountServiceException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Set Properties of Telephony account
     *
     * @param string $service
     * @param Telephony $billingAccount
     * @param array $properties (available keys are callBack & templates)
     * @return \Guzzle\Http\Message\Response
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function setProperties($service, $billingAccount, $properties)
    {
        if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        if (!$properties)
            throw new BadMethodCallException('Parameter $properties is missing.');
        if (!is_array($properties))
            throw new BadMethodCallException('Parameter $properties must be a array.');
        $t = array();
        if (array_key_exists('description', $properties))
            $t['description'] = $properties['description'];
        $properties = $t;
        unset($t);
        if (count($properties) == 0)
            throw new BadMethodCallException('Parameter $properties does not contain valid key. valid key is "description"');
        try {
            $r = $this->put('telephony/' . $billingAccount->getBillingAccount() . '/service/' . $service, array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($properties))->send();
        } catch (\Exception $e) {
            throw new TelephonyAccountServiceException($e->getMessage(), $e->getCode(), $e);
        }
        return true;
    }

	/**
     * Get Telephony account service voice consumptions.
     *
     * @param string $service
     * @param Telephony $billingAccount
     * @return string Json
     * @throws Exception\TelephonyAccountServiceException
     * @throws BadMethodCallException
     */
    public function getVoiceConsumptions($service, $billingAccount, $params = null)
    {
    	$paramsString = "";
    	if (!$service)
            throw new BadMethodCallException('Parameter $service is missing.');
        if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        if ($params != null && is_array($params) && count($params) > 0)
        {
        	$paramsString = "?";
        	if (array_key_exists('creationDatetime.from', $params))
        	{
        		$string = $params['creationDatetime.from'];
        		if ($params['creationDatetime.from'] instanceof \Datetime)
        			$string = $params['creationDatetime.from']->format("Y-m-d\TH:i:sP");
            	$paramsString .= "creationDatetime.from=".urlencode($string);
        	}
        	if (array_key_exists('creationDatetime.to', $params))
        	{
                $paramsString .= "&";
        		$string = $params['creationDatetime.to'];
        		if ($params['creationDatetime.to'] instanceof \Datetime)
        			$string = $params['creationDatetime.to']->format("Y-m-d\TH:i:sP");
            	$paramsString .= "creationDatetime.to=".urlencode($string);
        	}
        	if (array_key_exists('destinationType', $params) && in_array($params['destinationType'], array('landline', 'mobile', 'special')))
            {
                $paramsString .= "&";
            	$paramsString .= "destinationType=".$params['destinationType'];
            }
        	if (array_key_exists('planType', $params) && in_array($params['planType'], array('outplan', 'priceplan')))
            {
                $paramsString .= "&";
            	$paramsString .= "planType=".$params['planType'];
            }
        	if (array_key_exists('wayType', $params) && in_array($params['wayType'], array('incoming', 'outgoing', 'transfer')))
            {
                $paramsString .= "&";
            	$paramsString .= "wayType=".$params['wayType'];
            }
        }
        try {
            $r = $this->get('telephony/' . $billingAccount->getBillingAccount() . '/service/' . $service . '/voiceConsumption' . $paramsString)->send();
        } catch (\Exception $e) {
            throw new TelephonyAccountServiceException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

	/**
     * Get Telephony account service fax consumptions.
     *
     * @param string $service
     * @param Telephony $billingAccount
     * @return string Json
     * @throws Exception\TelephonyAccountServiceException
     * @throws BadMethodCallException
     */
    public function getFaxConsumptions($service, $billingAccount, $params = null)
    {
    	$paramsString = "";
    	if (!$service)
            throw new BadMethodCallException('Parameter $service is missing.');
        if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        if ($params != null && is_array($params) && count($params) > 0)
        {
        	$paramsString = "?";
            if (array_key_exists('creationDatetime.from', $params))
            {
                $string = $params['creationDatetime.from'];
                if ($params['creationDatetime.from'] instanceof \Datetime)
                    $string = $params['creationDatetime.from']->format("Y-m-d\TH:i:sP");
                $paramsString .= "creationDatetime.from=".urlencode($string);
            }
            if (array_key_exists('creationDatetime.to', $params))
            {
                $paramsString .= "&";
                $string = $params['creationDatetime.to'];
                if ($params['creationDatetime.to'] instanceof \Datetime)
                    $string = $params['creationDatetime.to']->format("Y-m-d\TH:i:sP");
                $paramsString .= "creationDatetime.to=".urlencode($string);
            }
            if (array_key_exists('destinationType', $params) && in_array($params['destinationType'], array('landline', 'mobile', 'special')))
            {
                $paramsString .= "&";
                $paramsString .= "destinationType=".$params['destinationType'];
            }
            if (array_key_exists('planType', $params) && in_array($params['planType'], array('outplan', 'priceplan')))
            {
                $paramsString .= "&";
                $paramsString .= "planType=".$params['planType'];
            }
            if (array_key_exists('wayType', $params) && in_array($params['wayType'], array('incoming', 'outgoing', 'transfer')))
            {
                $paramsString .= "&";
                $paramsString .= "wayType=".$params['wayType'];
            }
        }
        try {
            $r = $this->get('telephony/' . $billingAccount->getBillingAccount() . '/service/' . $service . '/faxConsumption' . $paramsString)->send();
        } catch (\Exception $e) {
            throw new TelephonyAccountServiceException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }
}


<?php

namespace Ovh\Telephony;

use Ovh\Common\AbstractClient;
use Ovh\Common\Exception\BadMethodCallException;
use Ovh\Common\Exception\NotImplementedYetByOvhException;
use Ovh\Telephony\Exception\TelephonyException;

class TelephonyClient extends AbstractClient
{
	/**
     * Get Telphony properties
     *
     * @param string $billingAccount
     * @return string Json
     * @throws Exception\TelephonyException
     * @throws BadMethodCallException
     */
    public function getProperties($billingAccount)
    {
        if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        try {
            $r = $this->get('telephony/' . $billingAccount)->send();
        } catch (\Exception $e) {
            throw new TelephonyException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Set Properties of Telephony account
     *
     * @param string $domain
     * @param array $properties (available keys are callBack & templates)
     * @return \Guzzle\Http\Message\Response
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function setProperties($billingAccount, $properties)
    {
        if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        if (!$properties)
            throw new BadMethodCallException('Parameter $properties is missing.');
        if (!is_array($properties))
            throw new BadMethodCallException('Parameter $properties must be a array.');
        $t = array();
        if (array_key_exists('description', $properties))
            $t['description'] = $properties['description'];
        $properties = $t;
        unset($t);
        if (count($properties) == 0)
            throw new BadMethodCallException('Parameter $properties does not contain valid key. valid key is "description"');
        try {
            $r = $this->put('telephony/' . $billingAccount, array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($properties))->send();
        } catch (\Exception $e) {
            throw new TelephonyException($e->getMessage(), $e->getCode(), $e);
        }
        return true;
    }

    /**
     * Services associated with this billing account
     * @param  $billingAccount
     * @return string Json
     */
    public function getBillingAccountServices($billingAccount)
    {
		if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        try {
            $r = $this->get('telephony/' . $billingAccount . '/service')->send();
        } catch (\Exception $e) {
            throw new TelephonyException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    public function getServiceInfos($billingAccount)
    {
        if (!$billingAccount)
            throw new BadMethodCallException('Parameter $billingAccount is missing.');
        try {
            $r = $this->get('telephony/' . $billingAccount . '/serviceInfos')->send();
        } catch (\Exception $e) {
            throw new TelephonyException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }
}

 ?>


<?php
/**
 * Copyright 2013 Stéphane Depierrepont (aka Toorop)
 *
 * Authors :
 *  - Stéphane Depierrepont (aka Toorop)
 *  - Florian Jensen (aka flosoft) : https://github.com/flosoft
 *  - Gillardeau Thibaut (aka Thibautg16)
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * or in the "license" file accompanying this file. This file 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.
 */

// cloned from VPS // Slartibardfast / 2014-06-30

namespace Ovh\Ip;

use Ovh\Common\Exception\NotImplementedYetException;
use Ovh\Common\Exception\NotImplementedYetByOvhException;
use Ovh\Common\Ovh;
use Ovh\Ip\IpClient;
use Ovh\Common\Task;

/*
 *
 * Class  for the /ip/.. heirarchy
*/
class Ip
{
	private $domain = null;
	private static $IPClient = null;

	/**
	 * @param string $domain
	 */
	public function __construct($domain)
	{
		$this->setIP($domain);
	}

	/**
	 * Return IP client
	 *
	 * @return null|IPClient
	 */
	private static function getClient()
	{
		if (!self::$IPClient instanceof IPClient){
			self::$IPClient=new IPClient();
		};
		return self::$IPClient;
	}

	/**
	 * Set domain
	 *
	 * @param string $domain
	 */
	public function setIP($domain)
	{
		$this->domain = $domain;
	}

	/**
	 * Get domain
	 *
	 * @return null | string domain
	 */
	public function getIP()
	{
		return $this->domain;
	}

	###
	# Mains methods from OVH Rest API
	##

	/**
	 *  Get ipblock properties
	 *
	 *  @return object
	 *
	*/
	public function getIPBlockProperties(){
        return json_decode(self::getClient()->getIPBlockProperties($this->getIP()));
    }

	/**
	 *  set ipblock properties (only description allowed at this time)
	 *
	 *  @return NULL ??
	 *
	*/
	public function setIPBlockProperties($description) {
		return json_decode(self::getClient()->setIPBlockProperties($this->getIP(),$description));
	}

	/**
	 *  get ips in the current block which are blocked (for spam, etc...)
	 *
	 *  @return list of IPv4
	 *
	*/
	public function getIPBlockArp() {
		return json_decode(self::getClient()->getIPBlockArp($this->getIP()));
	}

	/*
	 * get details about the specific IP that is blocked
	 *
	 * return mixed detail
	*/
	public function getIPBlockedInfo($domain) {
		return json_decode(self::getClient()->getIPBlockArp($this->getIP(),$domain));
	}

	/*
	 * get ReverseIP
	 *
	 * return mixed detail
	*/
	public function getReverse() {
		return json_decode(self::getClient()->getReverse($this->getIP()));
	}

	/*
	 * get details about the ReverseIP
	 *
	 * return mixed detail
	*/
	public function getReverseProperties($ipv4) {
		return json_decode(self::getClient()->getReverseProperties($this->getIP(),$ipv4));
	}

	/*
	 * get set the ReverseIP pointer on an IP
	 *
	 * automatically falls into a delete of IPreverse if passed reverse is empty string
	 * (Avoids unnecessary error at API level)
	 *
	 * return mixed detail
	*/
	public function setReverseProperties($ipv4,$reverse) {
		if ($reverse > "") {
			return json_decode(self::getClient()->setReverseProperties($this->getIP(),$ipv4,$reverse));
		} else {
			return json_decode(self::getClient()->deleteReverseProperties($this->getIP(),$ipv4));
		}
	}

	/*
	 * clear the ReverseIP pointer on an IP
	 *
	 * return mixed detail
	*/
	public function deleteReverseProperties($ipv4) {
		return json_decode(self::getClient()->deleteReverseProperties($this->getIP(),$ipv4));
	}

	/*
	 * get IPs in block on SPAM
	 *
	 * return array IPv4
	*/
	public function getSpam($spamstate="blockedForSpam") {
		return json_decode(self::getClient()->getSpam($this->getIP(),$spamstate));
	}

	/*
	 * get properties of IP on SPAM
	 *
	 * return mixed
	*/
	public function getSpamProperties($ipv4) {
		return json_decode(self::getClient()->getSpamProperties($this->getIP(),$ipv4));
	}

	/*
	 * get stats of IP on SPAM
	 *
	 * return mixed
	*/
	public function getSpamStats($ipv4, $fromdate="2000-01-01 00:00:00", $todate="") {
		if ($todate=="") $todate=date("Y-m-d 23:59:59",time());
		return json_decode(self::getClient()->getSpamStats($this->getIP(),$ipv4, $fromdate, $todate));
	}

	/*
	 * get stats of IP on SPAM
	 *
	 * return mixed
	*/
	public function setUnblockSpam($ipv4) {
		return json_decode(self::getClient()->setUnblockSpam($this->getIP(),$ipv4));
	}

}


<?php

namespace Ovh\Telephony;

use Ovh\Telephony\Telephony;
use Ovh\Telephony\TelephonyAccountServiceClient;
use Ovh\Telephony\VoiceConsumption;
use Ovh\Telephony\FaxConsumption;

class TelephonyAccountService
{
	private $service = null;
	private $billingAccount = null;
	private static $telephonyAccountServiceClient = null;

	/**
	 *
	 * @param String $service
	 * @param Telephony $billingAccount
     *
     * @throws \Ovh\Common\Exception\BadConstructorCallException;
     *
	 */
	function __construct($service, Telephony $billingAccount)
	{
		if (!$service)
            throw new BadConstructorCallException('$service parameter is missing.');
		if (!$billingAccount)
            throw new BadConstructorCallException('$billingAccount parameter is missing.');
		$this->service = $service;
		$this->billingAccount = $billingAccount;
	}

	/**
	 * Get Telephony Account Service
	 * @return string $service
	 */
	public function getService()
	{
		return $this->service;
	}

	/**
	 * Get Telephony Account Service
	 * @return string $service
	 */
	public function getBillingAccount()
	{
		return $this->billingAccount;
	}

	/**
     * Return TelephonyAccountService client
     *
     * @return SmsClient
     */
    private static function getClient()
    {
        if (!self::$telephonyAccountServiceClient instanceof TelephonyAccountServiceClient){
            self::$telephonyAccountServiceClient = new TelephonyAccountServiceClient();
        };
        return self::$telephonyAccountServiceClient;
    }

	/**
     * Get Service object properties
     *
     * @return object
     */
    public function getProperties()
    {
        return json_decode(self::getClient()->getProperties($this->service, $this->billingAccount));
    }

    /**
     * @param array $props (avalaibles keys are callBack and templates)
     * @return boolean
     */
    public function setProperties($props)
    {
        return self::getClient()->setProperties($this->service, $this->billingAccount, $props);
    }

    /**
     * Get Fax delivery records.
     * @return [type] [description]
     */
    public function getFaxConsumptions($params = null)
    {
    	$consumptionList = json_decode(self::getClient()->getFaxConsumptions($this->service, $this->billingAccount, $params));
    	$consumptions = array();

    	foreach ($consumptionList as $consumption)
    	{
    		$consumptions[] = new FaxConsumption($consumption, $this);
    	}
    	return $consumptions;
    }

    /**
     * Get Call delivery records.
     * @return [type] [description]
     */
    public function getVoiceConsumptions($params = null)
    {
    	$consumptionList = json_decode(self::getClient()->getVoiceConsumptions($this->service, $this->billingAccount, $params));
    	$consumptions = array();

    	foreach ($consumptionList as $consumption)
    	{
    		$consumptions[] = new VoiceConsumption($consumption, $this);
    	}
    	return $consumptions;
    }
}


<?php

/**
 * Copyright 2013 Stéphane Depierrepont (aka Toorop)
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * or in the "license" file accompanying this file. This file 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 Ovh\Sms;

use Ovh\Common\AbstractClient;
use Ovh\Common\Exception\BadMethodCallException;
use Ovh\Common\Exception\NotImplementedYetByOvhException;
use Ovh\Sms\Exception\SmsException;

class smsClient extends AbstractClient
{

    /**
     * Get SMS properties
     *
     * @param string $domain
     * @return string Json
     * @throws Exception\SmsException
     * @throws BadMethodCallException
     */
    public function getProperties($domain)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        try {
            $r = $this->get('sms/' . $domain)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Set Properties of SMS account
     *
     * @param string $domain
     * @param array $properties (available keys are callBack & templates)
     * @return \Guzzle\Http\Message\Response
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function setProperties($domain, $properties)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$properties)
            throw new BadMethodCallException('Parameter $properties is missing.');
        if (!is_array($properties))
            throw new BadMethodCallException('Parameter $properties must be a array.');
        // clean : only callback and templates are allowed
        $t = array();
        if (array_key_exists('callBack', $properties))
            $t['callBack'] = $properties['callBack'];
        if (array_key_exists('templates', $properties))
            $t['templates'] = $properties['templates'];
        $properties = $t;
        unset($t);
        if (count($properties) == 0)
            throw new BadMethodCallException('Parameter $properties does not contain valid key. valid keys are "templates" and "callBack"');
        try {
            $r = $this->put('sms/' . $domain, array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($properties))->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return true;
    }

    /**
     * Get Numbers blacklisted associated to the sms account
     *
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getBlacklists($domain)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        try {
            $r = $this->get('sms/' . $domain . '/blacklists')->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Delete a number from blacklist
     *
     * @param string $domain
     * @param string $number
     * @return \Guzzle\Http\Message\Response
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function deleteBlacklist($domain, $number)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$number)
            throw new BadMethodCallException('Parameter $number is missing.');
        try {
            $r = $this->delete('sms/' . $domain . '/blacklists/' . $number)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r;
    }

    /**
     * Get Sms sent associated to the sms account
     * Wrapper on $this->getOutgoings() for backward compatibility
     *
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     * @deprecated
     */
    public function getHistories($domain)
    {
        trigger_error('Deprecated method. Use $this->getHistories() instead.', E_USER_DEPRECATED);
        return $this->getOutgoings($domain);
    }

    /**
     * Get Sms sent associated to the sms account
     *
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getOutgoings($domain)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        try {
            $r = $this->get('sms/' . $domain . '/outgoing')->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Get history object properties
     * Wrapper on $this->getOutgoing() for backward compatibility
     *
     * @param string $domain
     * @param int $id
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     * @deprecated
     */
    public function getHistory($domain, $id)
    {
        trigger_error('Deprecated method. Use $this->getHistory() instead.', E_USER_DEPRECATED);
        return $this->getOutgoing($domain, $id);
    }

    /**
     * Get outgoing object properties
     *
     * @param string $domain
     * @param integer $id
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getOutgoing($domain, $id)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if ($id !== 0 && !$id)
            throw new BadMethodCallException('Parameter $id is missing.');
        $id = intval($id);
        try {
            $r = $this->get('sms/' . $domain . '/outgoing/' . $id)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Delete the sms history given
     * Wrapper on $this->getOutgoing() for backward compatibility
     *
     * @param string $domain
     * @param int $id
     * @return bool true‡
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     * @deprecated
     */
    public function deleteHistory($domain, $id)
    {
        trigger_error('Deprecated method. Use $this->deleteOutgoing() instead.', E_USER_DEPRECATED);
        return $this->deleteOutgoing($domain, $id);
    }

    /**
     * Delete the sms history given
     *
     * @param string $domain
     * @param int $id
     * @return bool true‡
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function deleteOutgoing($domain, $id)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$id)
            throw new BadMethodCallException('Parameter $id is missing.');
        try {
            $this->delete('sms/' . $domain . '/outgoing/' . $id)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return true;
    }

    /**
     * Get Sms sent associated to the sms account
     *
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getIncomings($domain)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        try {
            $r = $this->get('sms/' . $domain . '/incoming')->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Get history object properties
     *
     * @param string $domain
     * @param integer $id
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getIncoming($domain, $id)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if ($id !== 0 && !$id)
            throw new BadMethodCallException('Parameter $id is missing.');
        $id = intval($id);
        try {
            $r = $this->get('sms/' . $domain . '/incoming/' . $id)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Delete the sms history given
     *
     * @param string $domain
     * @param int $id
     * @return bool true‡
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function deleteIncoming($domain, $id)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$id)
            throw new BadMethodCallException('Parameter $id is missing.');
        try {
            $this->delete('sms/' . $domain . '/incoming/' . $id)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return true;
    }

    /**
     * Get users associated to the sms account
     *
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getJobs($domain)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        try {
            $r = $this->get('sms/' . $domain . '/jobs')->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Get job object properties
     *
     * @param string $domain
     * @param string $id
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getJob($domain, $id)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if ($id !== 0 && !$id)
            throw new BadMethodCallException('Parameter $id is missing.');
        $id = intval($id);
        try {
            $r = $this->get('sms/' . $domain . '/jobs/' . $id)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Create a new job
     *
     * @param string $domain
     * @param array $opt
     * @return string (json encoded object)
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function createJob($domain, $opt)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$opt)
            throw new BadMethodCallException('Parameter $opt is missing');
        if (!is_array($opt))
            throw new BadMethodCallException('Parameter $opt must be a array of option. ' . gettype($opt) . ' given.');
        // required opt are :
        //      receivers : array of recievers
        //      message : sms message
        //      sender : a valid sender
        if (!array_key_exists('message', $opt) || !array_key_exists('sender', $opt) || !array_key_exists('receivers', $opt))
            throw new BadMethodCallException('Parameter $opt must have at least  "message" (=> string), "sender" (=> string) and receivers (=> array) keys');

        if (!is_array($opt['receivers']))
            throw new BadMethodCallException('Parameter $opt[receivers] must be a array of option. ' . gettype($opt['receivers']) . ' given.');
        if (count($opt['receivers']) == 0)
            throw new BadMethodCallException('Parameter $opt[receivers] is empty.');

        // clean opt
        $job = array();

        $job['sender'] = $opt['sender'];
        $job['message'] = $opt['message'];
        $job['receivers'] = $opt['receivers'];

        // noStopClause : if true no STOP clause at the end of the SMS. Default to false
        $job['noStopClause'] = (@$opt['noStopClause']) ? $opt['noStopClause'] : false;

        // priority Default: veryLow
        if (@$opt['priority'] &&
            in_array($opt['priority'], array('high', 'medium', 'low', 'veryLow')))
            $job['priority'] = $opt['priority'];
        else $job['priority'] = 'veryLow';

        // validityPeriod : SMS validity in minutes. Default : 2880 (48 Hours)
        $job['validityPeriod'] = (@$opt['validityPeriod']) ? intval($opt['validityPeriod']) : 2880;

        // charset : Charset of sms message. Default : ?
        $job['charset'] = (@$opt['charset']) ? $opt['charset'] : 'UTF-8';

        // coding : the sms coding : '7bit' or '8bit' for unicode. Default is '7bit'
        if (@$opt['coding'] && in_array($opt['coding'], array('7bit', '8bit')))
            $job['coding'] = $opt['coding'];
        else $job['coding'] = '7bit';

        // differedPeriod :  Time in minutes to wait before sending the message. Default : 0
        $job['differedPeriod'] = (@$opt['differedPeriod']) ? intval($opt['differedPeriod']) : 0;

        // tag : optionnal tag (string)
        $job['tag'] = (@$opt['tag']) ? $opt['tag'] : '';

        // class :  the sms class: 'flash', 'phoneDisplay', 'sim', 'toolkit'. Default : 'phoneDisplay'
        if (@$opt['class'] &&
            in_array($opt['class'], array('flash', 'phoneDisplay', 'sim', 'toolkit')))
            $job['class'] = $opt['class'];
        else $job['class'] = 'phoneDisplay';

        unset($opt); // not - really - usefull...

        try {
            $r = $this->post('sms/' . $domain . '/jobs', array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($job))->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * @param string $domain
     * @param int $id : job id
     * @return \Guzzle\Http\Message\Response
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function deleteJob($domain, $id)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if ($id !== 0 && !$id)
            throw new BadMethodCallException('Parameter $id is missing.');
        $id = intval($id);
        try {
            $r = $this->delete('sms/' . $domain . '/job/' . $id)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r;
    }

    /**
     * Describe SMS offers available.
     *
     * @param string $countryDestination country code ISO 3166-2
     * @param string $countryCurrencyPrice country code ISO 3166-2
     * @param integer $quantity
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getSeeOffers($domain, $countryDestination, $countryCurrencyPrice, $quantity)
    {
        $countriesDestination = array('all', 'ai', 'an', 'ar', 'at', 'au', 'aw', 'ba', 'bb', 'be', 'bg', 'bh', 'bm', 'bo', 'br', 'bz', 'ch', 'cl', 'cn', 'co', 'cr', 'cu', 'cy', 'cz', 'de', 'dk', 'dm', 'dz', 'ec', 'ee', 'eg', 'es', 'fi', 'fr', 'gb', 'gd', 'gp', 'gr', 'gy', 'hk', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'in', 'is', 'it', 'jm', 'jo', 'jp', 'kr', 'kw', 'ky', 'lb', 'lc', 'lt', 'lu', 'lv', 'ma', 'me', 'mq', 'ms', 'mt', 'my', 'nc', 'ng', 'nl', 'no', 'nz', 'pa', 'pe', 'pf', 'ph', 'pk', 'pl', 'pt', 'py', 're', 'ro', 'rs', 'ru', 'sa', 'se', 'sg', 'si', 'sk', 'sr', 'tc', 'th', 'tn', 'tr', 'tt', 'tw', 'ua', 'uy', 'vc', 've', 'vg', 'vn', 'za');
        $countryDestination = strtolower($countryDestination);

        $countriesCurrencyPrice = array('all', 'ca', 'cz', 'de', 'en', 'es', 'fi', 'fr', 'gb', 'ie', 'it', 'lt', 'ma', 'nl', 'pl', 'pp', 'pt', 'qc', 'ru', 'sk', 'sn', 'tn', 'we');
        $countryCurrencyPrice = strtolower($countryCurrencyPrice);

        $quantities = array(100, 1000, 10000, 100000, 1000000, 200, 250, 2500, 25000, 500, 5000, 50000);
        $quantity = intval($quantity);

        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');

        if (!in_array($countryDestination, $countriesDestination)) {
            throw new BadMethodCallException('Parameter $countryDestination must be in array (' . implode(', ', $countriesDestination) . '), "' . $countryDestination . '" given.');
        }
        if (!in_array($countryCurrencyPrice, $countriesCurrencyPrice)) {
            throw new BadMethodCallException('Parameter $countryCurrencyPrice must be in array (' . implode(', ', $countriesCurrencyPrice) . '), "' . $countryCurrencyPrice . '" given.');
        }
        if (!in_array($quantity, $quantities)) {
            throw new BadMethodCallException('Parameter $quantity must be in array (' . implode(', ', $quantities) . '), "' . $quantity . '" given.');
        }

        try {

            $r = $this->get('sms/' . $domain . '/seeOffers?countryDestination=' . $countryDestination . '&countryCurrencyPrice=' . $countryCurrencyPrice . '&quantity=' . $quantity)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Purchase SMS credits
     *
     * @param string $domain
     * @param int $quantity
     * @return string (json encoded object)
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function purchase($domain, $quantity)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$quantity)
            throw new BadMethodCallException('Parameter $quantity is missing.');
        $quantity = intval($quantity);
        $allowedQ = array(100, 200, 250, 500, 1000, 5000, 2500, 10000, 50000, 100000);
        if (!in_array($quantity, $allowedQ))
            throw new BadMethodCallException('Parameter $quantity must be in array (' . implode(', ', $allowedQ) . '), "' . $quantity . '" given.');
        try {
            $r = $this->post('sms/' . $domain . '/purchase', array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($quantity))->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get senders allowed associated to the sms account
     *
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getSenders($domain)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        try {
            $r = $this->get('sms/' . $domain . '/senders')->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }

        return $r->getBody(true);
    }

    /**
     * Get sender object properties
     *
     * @param string $domain
     * @param string $sender
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getSender($domain, $sender)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$sender)
            throw new BadMethodCallException('Parameter $sender is missing.');
        $sender = urlencode($sender);
        try {
            $r = $this->get('sms/' . $domain . '/senders/' . $sender)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     *  Create a new sender
     *
     * @param string $domain
     * @param array $sender (keys : sender (requiered) => string, relaunch => string, reason => string)
     * @return void
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @throws Exception\SmsException
     */
    public function createSender($domain, $sender)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$sender)
            throw new BadMethodCallException('Parameter $sender is missing.');
        if (!is_array($sender))
            throw new BadMethodCallException('Parameter $sender must be a array. ' . gettype($sender) . ' given.');
        // required fields (sender)
        if (!array_key_exists('sender', $sender))
            throw new BadMethodCallException('Parameter $sender have key sender (string).');
        // sanitize
        $t = array();
        $t['sender'] = $sender['sender'];
        // relaunch
        ($sender['relaunch']) ? $t['relaunch'] = $sender['relaunch'] : $t['relaunch'] = '';
        // reason
        ($sender['reason']) ? $t['reason'] = $sender['reason'] : $t['reason'] = '';
        unset($sender);
        try {
            $r = $this->post('sms/' . $domain . '/senders', array('Content-Type' => 'application/json;charset=UTF-8'), json_encode($t))->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
    }

    /**
     * @param string $domain
     * @param array $sender
     * @throws \Ovh\Common\Exception\NotImplementedYetByOvhException
     */
    public function updateSender($domain, $sender)
    {
        throw new NotImplementedYetByOvhException();
    }

    /**
     * @param string $domain
     * @param string $sender
     * @throws \Ovh\Common\Exception\NotImplementedYetByOvhException
     */
    public function deleteSender($domain, $sender)
    {
        throw new NotImplementedYetByOvhException();
    }

    /**
     * Get users associated to the sms account
     *
     * @param string $domain
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getUsers($domain)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        try {
            $r = $this->get('sms/' . $domain . '/users')->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get users associated to the sms account
     *
     * @param string $domain
     * @param string $user
     * @return string Json
     * @throws BadMethodCallException
     * @throws Exception\SmsException
     */
    public function getUser($domain, $user)
    {
        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');
        if (!$user)
            throw new BadMethodCallException('Parameter $user is missing.');
        try {
            $r = $this->get('sms/' . $domain . '/users/' . $user)->send();
        } catch (\Exception $e) {
            throw new SmsException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     *
     * @param $domain
     * @param $user
     * @throws \Ovh\Common\Exception\NotImplementedYetByOvhException
     */
    public function addUser($domain, $user)
    {
        throw new NotImplementedYetByOvhException();
    }

    /**
     *
     * @param $domain
     * @param $user
     * @throws \Ovh\Common\Exception\NotImplementedYetByOvhException
     */
    public function updateUser($domain, $user)
    {
        throw new NotImplementedYetByOvhException();
    }

    /**
     *
     * @param $domain
     * @param $user
     * @throws \Ovh\Common\Exception\NotImplementedYetByOvhException
     */
    public function deleteUser($domain, $user)
    {
        throw new NotImplementedYetByOvhException();
    }

}


<?php
/**
 * Copyright 2013 Stéphane Depierrepont (aka Toorop)
 *
 * Authors :
 *  - Stéphane Depierrepont (aka Toorop)
 *  - Florian Jensen (aka flosoft) : https://github.com/flosoft
 *  - Gillardeau Thibaut (aka Thibautg16)
 *  - Scott Brown (aka Slartibardfast)
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * or in the "license" file accompanying this file. This file 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 Ovh\Dedicated\Server;

use Ovh\Common\Exception\NotImplementedYetException;
use Ovh\Common\Exception\NotImplementedYetByOvhException;
use Ovh\Common\Ovh;
use Ovh\Dedicated\Server\ServerClient;
use Ovh\Common\Task;

class Server
{
	private $domain = null;
	private static $serverClient = null;

	/**
	 * @param string $domain
	 */
	public function __construct($domain)
	{
		$this->setDomain($domain);
	}

	/**
	 * Return Dedicated Server client
	 *
	 * @return null|serverClient
	 */
	private static function getClient()
	{
		if (!self::$serverClient instanceof ServerClient){
			self::$serverClient=new ServerClient();
		};
		return self::$serverClient;
	}

	/**
	 * Set domain
	 *
	 * @param string $domain
	 */
	public function setDomain($domain)
	{
		$this->domain = $domain;
	}

	/**
	 * Get domain
	 *
	 * @return null | string domain
	 */
	public function getDomain()
	{
		return $this->domain;
	}

	###
	# Mains methods from OVH Rest API
	##

	/**
	 *  Get Dedicated Server properties
	 *
	 *  @return object
	 *
	 */
	public function  getProperties()
	{
		return json_decode(self::getClient()->getProperties($this->getDomain()));
	}

	/**
	 * @return mixed
	 */
	public function getBoot()
	{
		return json_decode(self::getClient()->getBoot($this->getDomain()));
	}

/** BackupFTP - added in 0.1.2 **/

	/*
	* Get backup FTP assigned to server
	*
	* @return mixed
	*/
	public function getbackupFTP()
	{
		return json_decode(self::getClient()->getBackupFTP($this->getDomain()));
	}

	/*
	* Create Backup FTP on server
	*
	* @return mixed
	*/
	public function createBackupFTP()
	{
		return json_decode(self::getClient()->createBackupFTP($this->getDomain()));
	}

	/*
	* Delete backup FTP
	*
	*/
	public function deleteBackupFTP()
	{
		return json_decode(self::getClient()->deleteBackupFTPAccess($this->getDomain()));
	}

	/*
	* Change backup FTP Password
	*
	*/
	public function changeBackupFTPPassword()
	{
		return json_decode(self::getClient()->changeBackupFTPPassword($this->getDomain()));
	}

	/*
	* Get backup FTP ACL list
	*
	* @returns object (array of ACL)
	*/
	public function getBackupFTPAccess()
	{
		return json_decode(self::getClient()->getBackupFTPAccess($this->getDomain()));
	}

	/*
	* Create backup FTP ACL for IPBlock (creates with default ACL)
	*
	* @returns mixed
	*/
	public function createBackupFTPAccess($ipBlock)
	{
		return json_decode(self::getClient()->createBackupFTPAccess($this->getDomain(), $ipBlock));
	}

	/*
	* Get Authorizable IPblocks on this backup FTP space (IPblocks assoc with the server)
	*
	* @returns object (array of IPblocks)
	*/
	public function getBackupFTPAuthorizableBlocks()
	{
		return json_decode(self::getClient()->getBackupFTPAuthorizableBlocks($this->getDomain()));
	}

	/*
	* Get BackupFTPAccessBlock - Get ACL for specific IPBlock
	*
	* @returns object (ACL information)
	*/
	public function getBackupFTPaccessBlock($ipBlock)
	{
		return json_decode(self::getClient()->getBackupFTPaccessBlock($this->getDomain(),$ipBlock));
	}

	/*
	* delete backup FTP ACL for IPBlock
	*
	* @returns object
	*/
	public function deleteBackupFTPaccessBlock($ipBlock)
	{
		return json_decode(self::getClient()->deleteBackupFTPaccessBlock($this->getDomain(),$ipBlock));
	}

	/*
	* Set backup FTP ACL for IPblock
	*
	* returns object (null??)
	*/
	public function setBackupFTPaccessBlock($ipBlock, $ftp, $nfs, $cifs)
	{
		return json_decode(self::getClient()->setBackupFTPaccessBlock($this->getDomain(),$ipBlock, $ftp, $nfs, $cifs));
	}

	/**
	 * @param $bootId
	 */
	public function getBootProperties($bootId)
	{
		return json_decode(self::getClient()->getBootProperties($this->getDomain(), $bootId));
	}

	/**
	 * @param $bootId
	 */
	public function getBootOptions($bootId)
	{
		return json_decode(self::getClient()->getBootOptions($this->getDomain(), $bootId));
	}

	/**
	 * @param $bootId
	 */
	public function getBootOptionsProperties($bootId, $option)
	{
		return json_decode(self::getClient()->getBootOptionsProperties($this->getDomain(), $bootId, $option));
	}

	/**
     * @param $bootDevice
     * @return bool true
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function setBootdevice($bootDevice){
		// ugly alert - the OVH API assumes any values not passed as part of the "PUT" are null/blank/0.
		// so when we reset the boot device, we need to capture the current state of =monitoring= , =rootdevice= and =state= from
		// getProperties and pass those along too... easiest way is to call getProperties as part of the setBootDevice call, and
		// update hoping that nothing else is updating in the intervening nanoseconds

        self::getClient()->setBootDevice($this->getDomain(), $this->getProperties(), $bootDevice);
        return true;
    }

    /**
     * @param $enable
     * @return bool true
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function setMonitoring($enable){
        self::getClient()->setMonitoring($this->getDomain(),$enable);
        return true;
    }

    /**
     * Set netboot
     *
     * @param $netbootId
     * @return bool true
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function setNetBoot($netbootId){
        self::getClient()->setNetboot($this->getDomain(),$netbootId);
        return true;
    }

    /**
     * Get IPS
     *
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @return array of strings
     */
    public function getIps()
    {
        return json_decode(self::getClient()->getIps($this->getDomain()));
    }

    /**
     * Get MRTG
     * Ajout by @Thibautg16 le 11/11/2013
     *
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     * @return array of strings
     */
    public function getMrtg($period,$type)
    {
        return json_decode(self::getClient()->getMrtg($this->getDomain(),$period,$type));
    }

    /**
     * Reboot server
     *
     * @return bool true
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function reboot()
    {
        self::getClient()->reboot($this->getDomain());
        return true;
    }

    /**
     *  Get secondary DNS
     *
     * @return array
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function getSecondaryDnsDomains()
    {
        return json_decode(self::getClient()->getSecondaryDnsDomains($this->getDomain()));
    }

    /**
     * Add domain to secondary DNS
     *
     * @param string $domain2add
     * @param string ipv4 $ip
     * @return bool true
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function addSecondaryDnsDomains($domain2add, $ip){
        self::getClient()->addSecondaryDnsDomains($this->getDomain(),$domain2add,$ip);
        return true;
    }

    /**
     * Get info about $domain2getInfo
     *
     * @param $domain2getInfo
     * @return array
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function getSecondaryDnsDomainsInfo($domain2getInfo){
        return json_decode(self::getClient()->getSecondaryDnsDomainsInfo($this->getDomain(), $domain2getInfo));
    }

    /**
     * Delete a domain on secondayr DNS server
     *
     * @param $domain2delete
     * @return bool true
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function deleteSecondaryDnsDomains($domain2delete){
        json_decode(self::getClient()->deleteSecondaryDnsDomains($this->getDomain(), $domain2delete));
        return true;
    }

    /**
     * Get info about secondary DNS server of $domain2getInfo
     *
     * @param $domain2getInfo
     * @return array
     * @throws Exception\ServerException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function getSecondaryDnsServerInfo($domain2getInfo){
        return json_decode(self::getClient()->getSecondaryDnsServerInfo($this->getDomain(), $domain2getInfo));
    }

	/**
	 *  Get Dedicated Server Service Infos
	 *
	 *  @return object
	 *
	 */
	public function  getServiceInfos()
	{
		return json_decode(self::getClient()->getServiceInfos($this->getDomain()));
	}

// Network additions in v.1.0.2
	/*
	* Get Network Configuration details
	*
	* @ returns object containing network params
	*/
	public function  getNetworkSpecifications()
	{
		return json_decode(self::getClient()->getNetworkSpecifications($this->getDomain()));
	}

	/*
	* Get Network Burst setting
	*
	* @return mixed
	 */
	public function getBurst()
	{
		return json_decode(self::getClient()->getBurst($this->getDomain()));
	}

	#Task
	/**
	 * Return tasks associated with this Dedicated Server (current and past)
	 *
	 * @return array of int
	 */
	public function getTasks()
	{
		return json_decode(self::getClient()->getTasks($this->getDomain()));
	}

	/**
	 * @param $taskId
	 * @return Task
	 */
	public function getTaskProperties($taskId)
	{
		return json_decode(self::getClient()->getTaskProperties($this->getDomain(), $taskId));
	}

	/*********** Interventions ***********/
        /**
        * Get Interventions
        * Retourne les interventions associés au serveur dédié (en cours et passé)
        * Ajout par @Thibautg16 le 22/11/2013
        *
        * @throws Exception\ServerException
        * @throws \Ovh\Common\Exception\BadMethodCallException
        * @return array of int
        */
        public function getInterventions(){
                return json_decode(self::getClient()->getInterventions($this->getDomain()));
        }

        /**
        * Get InterventionsProperties
        * Retourne les informations d'une intervention suivant son identifiant
        * Ajout by @Thibautg16 le 22/11/2013
        *
        * @throws Exception\ServerException
        * @throws \Ovh\Common\Exception\BadMethodCallException
        * @return array(date,type,id)
        */
        public function getInterventionProperties($interventionId){
                return json_decode(self::getClient()->getInterventionProperties($this->getDomain(), $interventionId));
        }

    /*********** Statistics (RTM) ***********/
		/**
		* Get Statistics (RTM)
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return object
		*/
		public function getStatistics(){
				return json_decode(self::getClient()->getStatistics($this->getDomain()));
			}

		/**
		* Get Statistics Chart Values
		* Ajout by @Thibautg16 le 11/11/2013
		*
		* @param $period
		* @param $type
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return object
		*/
		public function getStatisticsChart($period,$type){
			return json_decode(self::getClient()->getStatisticsChart($this->getDomain(),$period,$type));
		}

		/**
		* Get Statistics Connection
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return array
		*/
		public function getStatisticsConnection(){
			return json_decode(self::getClient()->getStatisticsConnection($this->getDomain()));
		}

		/**
		* Get Statistics Cpu
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsCpu(){
			return json_decode(self::getClient()->getStatisticsCpu($this->getDomain()));
		}

		/**
		* Get Statistics Disk
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsDisk(){
			return json_decode(self::getClient()->getStatisticsDisk($this->getDomain()));
		}

		/**
		* Get Disk Properties
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @param $disk
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsDiskProperties($disk){
			return json_decode(self::getClient()->getStatisticsDiskProperties($this->getDomain(),$disk));
		}

		/**
		* Get SMART Disk Informations
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @param $disk
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsDiskSmart($disk){
			return json_decode(self::getClient()->getStatisticsDiskSmart($this->getDomain(),$disk));
		}

		/**
		* Get Statistics Load
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsLoad(){
			return json_decode(self::getClient()->getStatisticsLoad($this->getDomain()));
		}

		/**
		* Get Statistics Memory
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsMemory(){
				return json_decode(self::getClient()->getStatisticsMemory($this->getDomain()));
		}

		/**
		* Get Motherboard Informations
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsMotherboard(){
			return json_decode(self::getClient()->getStatisticsMotherboard($this->getDomain()));
		}

		/**
		* Get Os Informations
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsOs(){
			return json_decode(self::getClient()->getStatisticsOs($this->getDomain()));
		}

		/**
		* Get Partitions Informations
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsPartition(){
			return json_decode(self::getClient()->getStatisticsPartition($this->getDomain()));
		}

		/**
		* Get Partition Properties
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @param $partition
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsPartitionProperties($partition){
			return json_decode(self::getClient()->getStatisticsPartitionProperties($this->getDomain(),$partition));
		}

		/**
		* Get Disk Properties
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @param $partition
		* @param $period
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsPartitionChart($partition, $period){
			return json_decode(self::getClient()->getStatisticsPartitionChart($this->getDomain(),$partition, $period));
		}

		/**
		* Get PCI Devices Informations
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsPci(){
			return json_decode(self::getClient()->getStatisticsPci($this->getDomain()));
		}

		/**
		* Get Process
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsProcess(){
			return json_decode(self::getClient()->getStatisticsProcess($this->getDomain()));
		}

		/**
		* Get Server Raid Informations
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsRaid(){
			return json_decode(self::getClient()->getStatisticsRaid($this->getDomain()));
		}

		/**
		* Get Raid Properties
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsRaidProperties($unit){
			return json_decode(self::getClient()->getStatisticsRaidProperties($this->getDomain(),$unit));
		}

		/**
		* Get Raid Volumes
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsRaidVolume($unit){
			return json_decode(self::getClient()->getStatisticsRaidVolume($this->getDomain(),$unit));
		}

		/**
		* Get Raid Volume Properties
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Object
		*/
		public function getStatisticsRaidVolumeProperties($unit,$volume){
			return json_decode(self::getClient()->getStatisticsRaidVolumeProperties($this->getDomain(),$unit,$volume));
		}

		/**
		* Get Raid Volume Ports
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsRaidVolumePort($unit,$volume){
			return json_decode(self::getClient()->getStatisticsRaidVolumePort($this->getDomain(),$unit,$volume));
		}

		/**
		* Get Raid Volume Ports Properties
		* Ajout by @Thibautg16 le 01/06/2014
		*
		* @throws Exception\ServerException
		* @throws \Ovh\Common\Exception\BadMethodCallException
		*
		* @return Array
		*/
		public function getStatisticsRaidVolumePortProperties($unit,$volume,$port){
			return json_decode(self::getClient()->getStatisticsRaidVolumePortProperties($this->getDomain(),$unit,$volume,$port));
		}

	/**
    * Get Hardware Specifications
	* Ajout by @Thibautg16 le 01/06/2014
    *
    * @throws Exception\ServerException
    * @throws \Ovh\Common\Exception\BadMethodCallException
	*
    * @return Object
    */
	public function getSpecificationsHardware(){
        return json_decode(self::getClient()->getSpecificationsHardware($this->getDomain()));
    }

// Orderables -- added in v1.0.2
	/*
	* Get list of orderable FTP Backup sizes for the specific server
	*
	* @return Object (Array of valid sizes)
	*/
	public function getOrderableBackupFTP() {
        return json_decode(self::getClient()->getOrderableBackupFTP($this->getDomain()));
    }

	/*
	* Get list of orderable USB keys for the specific server
	*
	* @return Object (array of valid key sizes)
	*/
	public function getOrderableUSB(){
        return json_decode(self::getClient()->getOrderableUSB($this->getDomain()));
    }

	/*
	* Determins if "professionalUse" is available for order on specific server
	*
	* @returns object (contains boolean value)
	*/
	public function getOrderableProfessionalUse(){
        return json_decode(self::getClient()->getOrderableProfessionalUse($this->getDomain()));
    }

// Installation information -- added in v0.1.2
	/*
	* Get list of installation templates compatible with server
	*
	* @returns object (multi-d-array of templates)
	*/
	public function getCompatibleTemplates() {
		return json_decode(self::getClient()->getCompatibleTemplates($this->getDomain()));
	}

	/*
	* Get list of partition schemes available with specific template
	*
	* @returns object (array of partition schemes)
	*/
	public function getCompatibleTemplatePartitionSchemes($domain) {
		return json_decode(self::getClient()->getCompatibleTemplatePartitionSchemes($this->getDomain()));

	}

// IPs list -- overlaps with /ips/ heirarchy, but this is available in the /dedicated/server heirarchy

	/*
	* Get list of Ips assined to server
	*
	* @returns array of IPs assigned (IPv4 and IPv6)
	*/
	public function getServerIPs() {
		return json_decode(self::getClient()->getServerIPs($this->getDomain()));

	}

// virtual MAC API

	/*
	* Get list of vMac addresses assigned to server
	*
	* @returns array of vMacs assigned
	*/
//	/dedicated/server/{serviceName}/virtualMac
	public function getVmacs() {
		return json_decode(self::getClient()->getVmacs($this->getDomain()));
	}

	/*
	* assign vMac to an IP
	*
	* @returns task (array of mixed) :
	*
	*	{
	*		"taskId": 123456,
	*		"function": "virtualMacAdd",
	*		"lastUpdate": "2014-07-04T19:28:52-04:00",
	*		"comment": "Create a virtual mac for ip a.b.c.d",
	*  		"status": "init",
	*  		"startDate": "2014-07-04T19:28:52-04:00",
	*  		"doneDate": null
	*	}
	*
	*/
// POST	/dedicated/server/{serviceName}/virtualMac
	public function createVmac($ip,$type,$vmname) {
		return json_decode(self::getClient()->assignVmac($this->getDomain(),$ip, $type, $vmname));
	}

	/*
	* Get list of vMac addresses assigned to server
	*
	* @returns array of vMacs assigned
	*/
// GET	/dedicated/server/{serviceName}/virtualMac/{virtualmac}
	public function getVmacProperties($vmac) {
		return json_decode(self::getClient()->getVmacProperties($this->getDomain(),$vmac));
	}

	/*
	* Get list of IPs addresses assigned to vMAC
	*
	* @returns array of vMacs assigned
	*/
//	/dedicated/server/{serviceName}/virtualMac/{virtualmac}/virtualAddress
	public function getVmacIPAddresses($vmac) {
		return json_decode(self::getClient()->getVmacIPAddresses($this->getDomain(),$vmac));
	}

	/*
	* add an IP addresses to vMAC
	*
	* @returns array of vMacs assigned
	*/
//	/dedicated/server/{serviceName}/virtualMac/{virtualmac}/virtualAddress
	public function setVmacIPAddresses($vmac, $ip, $vmname) {
		return json_decode(self::getClient()->getVmacIPAddress($this->getDomain(),$vmac, $ip, $vmname));
	}

	/*
	* add an IP addresses to vMAC
	*
	* @returns array of vMacs assigned
	*/
//	/dedicated/server/{serviceName}/virtualMac/{virtualmac}/virtualAddress
	public function deleteVmacIPAddress($vmac, $ip) {
		return json_decode(self::getClient()->deleteVmacIPAddress($this->getDomain(),$vmac, $ip));
	}

	/*
	* function to lookup a vMac based on an IP address - why dont they include this in the API?
	*
	*@param $ipv4 - IPv4 to lookup
	*
	*@returns vmac or null string if not found
	*/
	public function findVmac($ipv4) {
		$vmacs = json_decode(self::getClient()->getVmacs($this->getDomain()));
		foreach($vmacs as $vmac) {
			$test_ip = json_decode(self::getClient()->getVmacIPAddresses($this->getDomain(),$vmac));
			foreach($test_ip as $ip) {
				if ($ip == $ipv4)
					return $vmac;
			}
		}
		return "";
	}

	/*********** VRACK ***********/
	/**
	* Get Serveur Vrack
	* Ajout by @Thibautg16 le 17/05/2015
	*
	* @return String
	*/
	public function getServerVrack(){
		return json_decode(self::getClient()->getServerVrack($this->getDomain()));
	}
}


<?php

namespace Ovh\Telephony;

use Ovh\Common\AbstractClient;
use Ovh\Common\Exception\BadMethodCallException;
use Ovh\Common\Exception\NotImplementedYetByOvhException;
use Ovh\Telephony\Exception\VoiceConsumptionException;

class VoiceConsumptionClient extends AbstractClient
{
	/**
     * Get Telephony account service properties
     *
     * @param string $service
     * @param Telephony $telephoneAccount
     * @return string Json
     * @throws Exception\VoiceConsumptionException
     * @throws BadMethodCallException
     */
    public function getProperties($consumptionId, $telephoneAccount)
    {
        if (!$consumptionId)
            throw new BadMethodCallException('Parameter $consumptionId is missing.');
        if (!$telephoneAccount)
            throw new BadMethodCallException('Parameter $telephoneAccount is missing.');
        try {
            $r = $this->get('telephony/' . $telephoneAccount->getBillingAccount()->getBillingAccount() . '/service/' . $telephoneAccount->getService() . '/voiceConsumption/' . $consumptionId)->send();
        } catch (\Exception $e) {
            throw new VoiceConsumptionException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }
}


<?php
/**
 * Copyright 2013 Stéphane Depierrepont (aka Toorop)
 *
 * Authors :
 *  - Stéphane Depierrepont (aka Toorop)
 *  - Florian Jensen (aka flosoft) : https://github.com/flosoft
 *  - Gillardeau Thibaut (aka Thibautg16)
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 * or in the "license" file accompanying this file. This file 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 Ovh\Vrack;

#use Guzzle\Http\Exception\ClientErrorResponseException;

#use Guzzle\Http\Exception\BadResponseException;
#use Guzzle\Http\Exception\CurlException;
use Guzzle\Http\Message\Response;

use Ovh\Common\AbstractClient;
use Ovh\Common\Exception\BadMethodCallException;

#use Ovh\Common\Exception\NotImplementedYetException;

//use Ovh\Vps\Exception\VpsNotFoundException;
use Ovh\Vrack\Exception\VrackException;

class VrackClient extends AbstractClient
{

    /**
     * Get properties
     *
     * @param string $domain
     * @return string Json
     * @throws Exception\VrackException
     * @throws Exception\VrackNotFoundException
     */
    public function getProperties($domain)
    {
        try {
            $r = $this->get('vrack/' . $domain)->send();
        } catch (\Exception $e) {
            throw new VrackException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

	/*********** DedicatedServer ***********/

    /**
     * Get dedicatedServer
     * Ajout by @Thibautg16 le 24/06/2014
     *
     * @return array of strings
	 *
     * @throws Exception\VrackException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function getdedicatedServer($domain){
        $domain  = (string)$domain;

        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');

        try {
            $r = $this->get('vrack/'.$domain.'/dedicatedServer')->send();
        } catch (\Exception $e) {
            throw new VrackException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

    /**
     * Get MRTG
     * Ajout by @Thibautg16 le 26/06/2014
     *
     * @param string $domain
	 * @param string $serveur
     * @param string $period
     * @param string $type
     *
     * @return \Guzzle\Http\EntityBodyInterface|string
     * @throws Exception\VrackException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function getMrtg($domain, $serveur, $period='daily', $type='traffic:download'){
        $domain  = (string)$domain;
		$serveur = (string)$serveur;
        $period  = (string)$period;
        $type    = (string)$type;

        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');

        try {
            $r = $this->get('vrack/'.$domain.'/dedicatedServer/'.$serveur.'/mrtg?period='.$period.'&type='.$type)->send();
        } catch (\Exception $e) {
            throw new VrackException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

	/*********** DedicatedCloud ***********/
	/**
     * Get dedicatedCloud
     * Ajout by @Thibautg16 le 24/06/2014
     *
     * @return array of strings
	 *
     * @throws Exception\VrackException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function getdedicatedCloud($domain){
        $domain  = (string)$domain;

        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');

        try {
            $r = $this->get('vrack/'.$domain.'/dedicatedCloud')->send();
        } catch (\Exception $e) {
            throw new VrackException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }

	/*********** Ip ***********/
	/**
     * Get ip
     * Ajout by @Thibautg16 le 24/06/2014
     *
     * @return array of strings
	 *
     * @throws Exception\VrackException
     * @throws \Ovh\Common\Exception\BadMethodCallException
     */
    public function getIp($domain){
        $domain  = (string)$domain;

        if (!$domain)
            throw new BadMethodCallException('Parameter $domain is missing.');

        try {
            $r = $this->get('vrack/'.$domain.'/ip')->send();
        } catch (\Exception $e) {
            throw new VrackException($e->getMessage(), $e->getCode(), $e);
        }
        return $r->getBody(true);
    }
}