Exemplo n.º 1
0
 /**
  * @param MockHandler $mockHandler
  * @return DocsApiClient
  */
 public function createTestApiClient(MockHandler $mockHandler)
 {
     $httpClientMock = new Client(['handler' => $mockHandler]);
     $apiClient = new DocsApiClient();
     $apiClient->setKey('X');
     $apiClient->setHttpClient($httpClientMock);
     return $apiClient;
 }
<?php

use HelpScoutDocs\DocsApiClient;
use HelpScoutDocs\Models\UploadArticle;
require_once __DIR__ . '/../vendor/autoload.php';
$docsClient = new DocsApiClient();
$docsClient->setKey('API_KEY');
$upload = new UploadArticle();
$upload->setCollectionId('COLLECTION_ID');
$upload->setName(uniqid('Uploaded Article '));
$upload->setFile('REAL_PATH_TO_FILE');
$article = $docsClient->uploadArticle($upload, true);
Exemplo n.º 3
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use HelpScoutDocs\DocsApiClient;
// Initialize client
$docsApiClient = new DocsApiClient();
$docsApiClient->setKey('your-api-key');
// Get all collections
$collections = $docsApiClient->getCollections();
// Get all categories by collection ID
$helpCategories = $docsApiClient->getCategories('COLLECTION_ID');
// Get all articles by category ID
$helpCategoryArticles = $docsApiClient->getArticles('CATEGORY_ID');
// Get all sites
$sites = $docsApiClient->getSites();
// Get specific site by ID
$site = $docsApiClient->getSite('your-site-id-here');
// Run default articles search
$articles = $docsApiClient->searchArticles();
 /**
  * @test
  * @expectedException \HelpScoutDocs\ApiException
  * @expectedExceptionMessage Invalid API Key
  */
 public function should_throw_an_exception_if_no_api_key_provided()
 {
     $this->apiClient->getSites();
 }
Exemplo n.º 5
0
<?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);
<?php

include_once "../src/HelpScoutDocs/DocsApiClient.php";
use HelpScoutDocs\DocsApiClient;
$docsApiClient = DocsApiClient::getInstance();
$docsApiClient->setKey('my-api-key');
$collections = $docsApiClient->getCollections();
$helpCollectionName = "Existing Collection Name";
$helpCollection = reset(array_filter($collections->getItems(), function ($item) use($helpCollectionName) {
    return $item->getName() == $helpCollectionName;
}));
$helpCategories = $docsApiClient->getCategories($helpCollection->getId());
$helpCategoryName = 'Existing Category Name';
$helpCategory = reset(array_filter($helpCategories->getItems(), function ($item) use($helpCategoryName) {
    return $item->getName() == $helpCategoryName;
}));
$helpCategoryArticles = $docsApiClient->getArticles($helpCategory->getId());
$sites = $docsApiClient->getSites();
$site = $docsApiClient->getSite('your-site-id');
$articles = $docsApiClient->searchArticles();