src/Ovh/Sms/SmsClient.php
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);
    }
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);
    }
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 ) ; }
Create a new job

@param string $domain
@param array $opt
@return string (json encoded object)
@throws \Ovh\Common\Exception\BadMethodCallException
@throws Exception\SmsException
Create a new job