<?php use HelpScoutDocs\DocsApiClient; use HelpScoutDocs\Models\ArticleAsset; use HelpScoutDocs\Models\SettingsAsset; require_once __DIR__ . '/../vendor/autoload.php'; $docsClient = new DocsApiClient(); $docsClient->setKey('API_KEY'); // Create article asset $articleAsset = new ArticleAsset(); $articleAsset->setArticleId('ARTICLE_ID'); $articleAsset->setAssetType(ArticleAsset::ARTICLE_ASSET_IMAGE); $articleAsset->setFile('REAL_PATH_TO_FILE'); $result = $docsClient->createArticleAsset($articleAsset); // Create settings asset $settingsAsset = new SettingsAsset(); $settingsAsset->setSiteId('SITE_ID'); $settingsAsset->setAssetType(SettingsAsset::SETTINGS_ASSET_LOGO); $settingsAsset->setFile('REAL_PATH_TO_FILE'); $result = $docsClient->createSettingsAsset($settingsAsset);
/** * @param SettingsAsset $settingsAsset * @return SettingsAsset * @throws ApiException */ public function createSettingsAsset(SettingsAsset $settingsAsset) { if (!file_exists($settingsAsset->getFile())) { throw new ApiException(sprintf("Unable to locate file: %s", $settingsAsset->getFile())); } if (empty($settingsAsset->getAssetType())) { throw new ApiException("assetType is empty or not provided"); } if (empty($settingsAsset->getSiteId())) { throw new ApiException("siteId is empty or not provided"); } $multipart = [['name' => 'key', 'contents' => $this->apiKey], ['name' => 'assetType', 'contents' => $settingsAsset->getAssetType()], ['name' => 'siteId', 'contents' => $settingsAsset->getSiteId()], ['name' => 'file', 'contents' => fopen($settingsAsset->getFile(), 'r')]]; $uploadedAsset = $this->doPostMultipart('assets/settings', $multipart); $settingsAsset->setFileLink($uploadedAsset->filelink); return $settingsAsset; }
/** * @test * @expectedException \HelpScoutDocs\ApiException */ public function should_throw_an_exception_about_missing_site_id() { $settingsAsset = new SettingsAsset(); $settingsAsset->setFile(__DIR__ . '/../../fixtures/assets/octocat.png'); $settingsAsset->setAssetType(SettingsAsset::SETTINGS_ASSET_LOGO); $responseMock = $this->createResponseMock(201, null); $apiClient = $this->createTestApiClient($responseMock); $apiClient->createSettingsAsset($settingsAsset); }