public function uploadAsset(\SplFileInfo $file, Library $library = null): MoovlyObject
    {
        $supportedExtensions = array_merge(
            self::SUPPORTED_AUDIO_EXTENSION,
            self::SUPPORTED_IMAGE_EXTENSIONS,
            self::SUPPORTED_VIDEO_EXTENSIONS
        );

        $assetExtensions = array_merge(
            self::SUPPORTED_AUDIO_EXTENSION,
            self::SUPPORTED_IMAGE_EXTENSIONS
        );

        if (!in_array($file->getExtension(), $supportedExtensions)) {
            throw new BadAssetException($file);
        }

        if (in_array($file->getExtension(), $assetExtensions)) {
            try {
                $object = $this->client->uploadAsset($file, is_null($library) ? null : $library->getId());
            } catch (ClientException $ce) {
                $response = $ce->getResponse();

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

            return ObjectFactory::createFromAPIResponse($object);
        }

        try {
            $object = $this->client->uploadAsset($file, is_null($library) ? null : $library->getId());
        } catch (ClientException $ce) {
            $response = $ce->getResponse();

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

        return ObjectFactory::createFromAPIResponse($object);
    }
public function uploadAsset(\SplFileInfo $file, Library $library = null): MoovlyObject
    {
        $supportedExtensions = array_merge(
            self::SUPPORTED_AUDIO_EXTENSION,
            self::SUPPORTED_IMAGE_EXTENSIONS,
            self::SUPPORTED_VIDEO_EXTENSIONS
        );

        $assetExtensions = array_merge(
            self::SUPPORTED_AUDIO_EXTENSION,
            self::SUPPORTED_IMAGE_EXTENSIONS
        );

        if (!in_array($file->getExtension(), $supportedExtensions)) {
            throw new BadAssetException($file);
        }

        if (in_array($file->getExtension(), $assetExtensions)) {
            try {
                $object = $this->client->uploadAsset($file, is_null($library) ? null : $library->getId());
            } catch (ClientException $ce) {
                $response = $ce->getResponse();

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

            return ObjectFactory::createFromAPIResponse($object);
        }

        try {
            $object = $this->client->uploadAsset($file, is_null($library) ? null : $library->getId());
        } catch (ClientException $ce) {
            $response = $ce->getResponse();

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

        return ObjectFactory::createFromAPIResponse($object);
    }
public function uploadAsset ( \ SplFileInfo $ file , Library $ library = null ) : MoovlyObject { $ supportedExtensions = array_merge ( self :: SUPPORTED_AUDIO_EXTENSION , self :: SUPPORTED_IMAGE_EXTENSIONS , self :: SUPPORTED_VIDEO_EXTENSIONS ) ; $ assetExtensions = array_merge ( self :: SUPPORTED_AUDIO_EXTENSION , self :: SUPPORTED_IMAGE_EXTENSIONS ) ; if ( ! in_array ( $ file -> getExtension ( ) , $ supportedExtensions ) ) { throw new BadAssetException ( $ file ) ; } if ( in_array ( $ file -> getExtension ( ) , $ assetExtensions ) ) { try { $ object = $ this -> client -> uploadAsset ( $ file , is_null ( $ library ) ? null : $ library -> getId ( ) ) ; } catch ( ClientException $ ce ) { $ response = $ ce -> getResponse ( ) ; throw ExceptionFactory :: create ( $ response , $ ce ) ; } return ObjectFactory :: createFromAPIResponse ( $ object ) ; } try { $ object = $ this -> client -> uploadAsset ( $ file , is_null ( $ library ) ? null : $ library -> getId ( ) ) ; } catch ( ClientException $ ce ) { $ response = $ ce -> getResponse ( ) ; throw ExceptionFactory :: create ( $ response , $ ce ) ; } return ObjectFactory :: createFromAPIResponse ( $ object ) ; }
Uploads an asset to the Moovly API.

@param \SplFileInfo $file
@param Library      $library

@return MoovlyObject

@throws MoovlyException
Uploads an asset to the Moovly API .