szeidler/pageplanner-php-sdk

Pageplanner PHP SDK

1.0.0 2019-05-16 10:58 UTC

This package is auto-updated.

Last update: 2024-09-17 00:28:07 UTC


README

Build Status

Pageplanner PHP SDK 利用 guzzle-services 实现与 Pageplanner API 的简单集成。

要求

  • PHP 7.0 或更高版本
  • Composer
  • Guzzle

安装

将 Pageplanner PHP SDK 添加为 composer 依赖项。

composer require szeidler/pageplanner-php-sdk:^1.0

用法

根据资产的资源 URL 返回资产表示形式。

use szeidler\Pageplanner\PageplannerClient;

$client = new PageplannerClient([
    'baseUrl' => 'https://preportal.pageplanner.no/api-demo/api/',
    'access_token_url' => 'https://login.microsoftonline.com/pageplannersolutions.com/oauth2/token',
    'client_id'        => 'xxxxxx-xxxxxxxxxxxx',
    'client_secret'    => '123456',
]);

// Get all issues.
$issues = $client->getIssues();
foreach ($issues->getIterator() as $issue) {
  print $issue['name'];
}

// Get a issue by id.
$issue = $client->getIssue(['id' => 2]);
print $issue->offsetGet('name');

// Get all publications.
$publications = $client->getPublications();
foreach ($publications->getIterator() as $publication) {
  print $publication['name'];
}

// Get a single publication by id.
$publications = $client->getPublications(['id' => 2]);
print $publication->offsetGet('name');
print $publication->offsetGet('publicationCode');

// Get all stories for an issue.
$stories = $client->getStories(['issueId' => 5]);
foreach ($stories->getIterator() as $story) {
  print $story['name'];
}

// Get a single story by id.
$story = $client->getStory(['id' => 123]);
print $story->offsetGet('name');
print $story->offsetGet('author');

// Create a story for an issue.
$data = [
    'id' => 'abcd',
    'title' =>
      [
        'value' => 'My new title',
        'isHtml' => FALSE,
      ],
    'abstract' =>
      [
        'value' => 'Put your abstract here',
        'isHtml' => FALSE,
      ],
    'body' =>
      [
        'value' => '<strong>Your body could include HTML</strong>',
        'isHtml' => TRUE,
      ],
    'tags' => ['News', 'Culture'],
];
$story = $client->createStory($data);
print $story->offsetGet['name'];

测试

此 SDK 将 PHPUnit 作为 composer 的 require-dev 包含。将 phpunit.xml.dist 复制到 phpunit.xml 并填写您的 API 测试凭据。

./vendor/bin/phpunit -c phpunit.xml

致谢

Stephan Zeidler 为 Ramsalt Lab AS

许可协议

MIT 许可协议 (MIT)