public function createJob(Job $job): Job
    {
        $validQualities = ['480p', '720p', '1080p'];

        $options = array_merge([
            'quality'     => '480p',
            'create_moov' => false,
            'auto_render' => true,
        ], $job->getOptions());

        if (!in_array($options['quality'], $validQualities)) {
            throw new BadRequestException(
                sprintf(
                    'The given quality (%s) for a job is invalid, please use a valid one (%s).',
                    $options['quality'],
                    implode(', ', $validQualities)
                )
            );
        }

        if (!is_null($job->getId())) {
            throw new BadRequestException(
                'The given job already has an id. This either means you set this manually, or this is a job already ' .
                    ' registered in Moovly. In the first case, stop assigning a job id, in the latter case, just ' .
                    ' read the job.'
            );
        }

        if (is_null($job->getTemplate())) {
            throw new BadRequestException(
                'You have not supplied a template in the job request. Please run $job->setTemplate() before calling' .
                    ' $service->createJob().'
            );
        }

        $values = array_map(function (Value $value) {
            return [
                'external_id' => $value->getExternalId(),
                'title'       => $value->getTitle(),
                'template_variables' => $value->getTemplateVariables()
            ];
        }, $job->getValues());

        try {
            $result = JobFactory::createFromAPIResponse(
                $this->client->createJob($job->getTemplate()->getId(), $options, $values)
            );

            $result
                ->setTemplate($job->getTemplate())
                ->setOptions($job->getOptions())
                ->setValues($this->mergeJobValues($job->getValues(), $result->getValues()))
            ;
        } catch (ClientException $ce) {
            $response = $ce->getResponse();

            throw ExceptionFactory::create($response, $ce);
        }

        return $result;
    }
public function createJob(Job $job): Job
    {
        $validQualities = ['480p', '720p', '1080p'];

        $options = array_merge([
            'quality'     => '480p',
            'create_moov' => false,
            'auto_render' => true,
        ], $job->getOptions());

        if (!in_array($options['quality'], $validQualities)) {
            throw new BadRequestException(
                sprintf(
                    'The given quality (%s) for a job is invalid, please use a valid one (%s).',
                    $options['quality'],
                    implode(', ', $validQualities)
                )
            );
        }

        if (!is_null($job->getId())) {
            throw new BadRequestException(
                'The given job already has an id. This either means you set this manually, or this is a job already ' .
                    ' registered in Moovly. In the first case, stop assigning a job id, in the latter case, just ' .
                    ' read the job.'
            );
        }

        if (is_null($job->getTemplate())) {
            throw new BadRequestException(
                'You have not supplied a template in the job request. Please run $job->setTemplate() before calling' .
                    ' $service->createJob().'
            );
        }

        $values = array_map(function (Value $value) {
            return [
                'external_id' => $value->getExternalId(),
                'title'       => $value->getTitle(),
                'template_variables' => $value->getTemplateVariables()
            ];
        }, $job->getValues());

        try {
            $result = JobFactory::createFromAPIResponse(
                $this->client->createJob($job->getTemplate()->getId(), $options, $values)
            );

            $result
                ->setTemplate($job->getTemplate())
                ->setOptions($job->getOptions())
                ->setValues($this->mergeJobValues($job->getValues(), $result->getValues()))
            ;
        } catch (ClientException $ce) {
            $response = $ce->getResponse();

            throw ExceptionFactory::create($response, $ce);
        }

        return $result;
    }
public function createJob ( Job $ job ) : Job { $ validQualities = [ '480p' , '720p' , '1080p' ] ; $ options = array_merge ( [ 'quality' => '480p' , 'create_moov' => false , 'auto_render' => true , ] , $ job -> getOptions ( ) ) ; if ( ! in_array ( $ options [ 'quality' ] , $ validQualities ) ) { throw new BadRequestException ( sprintf ( 'The given quality (%s) for a job is invalid, please use a valid one (%s).' , $ options [ 'quality' ] , implode ( ', ' , $ validQualities ) ) ) ; } if ( ! is_null ( $ job -> getId ( ) ) ) { throw new BadRequestException ( 'The given job already has an id. This either means you set this manually, or this is a job already ' . ' registered in Moovly. In the first case, stop assigning a job id, in the latter case, just ' . ' read the job.' ) ; } if ( is_null ( $ job -> getTemplate ( ) ) ) { throw new BadRequestException ( 'You have not supplied a template in the job request. Please run $job->setTemplate() before calling' . ' $service->createJob().' ) ; } $ values = array_map ( function ( Value $ value ) { return [ 'external_id' => $ value -> getExternalId ( ) , 'title' => $ value -> getTitle ( ) , 'template_variables' => $ value -> getTemplateVariables ( ) ] ; } , $ job -> getValues ( ) ) ; try { $ result = JobFactory :: createFromAPIResponse ( $ this -> client -> createJob ( $ job -> getTemplate ( ) -> getId ( ) , $ options , $ values ) ) ; $ result -> setTemplate ( $ job -> getTemplate ( ) ) -> setOptions ( $ job -> getOptions ( ) ) -> setValues ( $ this -> mergeJobValues ( $ job -> getValues ( ) , $ result -> getValues ( ) ) ) ; } catch ( ClientException $ ce ) { $ response = $ ce -> getResponse ( ) ; throw ExceptionFactory :: create ( $ response , $ ce ) ; } return $ result ; }
Registers a new Job request in the Moovly API. This expects a Job model. Use the
JobFactory and the ValueFactory to create this.

@param Job   $job

@return Job

@throws MoovlyException
Registers a new Job request in the Moovly API . This expects a Job model . Use the JobFactory and the ValueFactory to create this .