定制 presshub-io/php-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

presshub-io/php-sdk

Composer 安装命令:

composer require presshub-io/php-sdk

包简介

Presshub PHP SDK. Content distribution API for publishers.

README 文档

README

Presshub\Template is a PHP library that helps construct templates in the Presshub Template format

Presshub\Client is a PHP library that allows you to distribute content to third-party content platforms via Presshub API. You can also retrieve and delete articles you’ve already published, and get basic information about your published articles, information about supported services and more.

Presshub API Reference

Installation

composer require presshub-io/php-sdk

or

git clone git@github.com:presshub-io/php-sdk.git
cd php-sdk
curl -sS https://getcomposer.org/installer | php
./composer.phar install

Presshub Template

This example shows how to build Presshub template and map template fields.

// Create Presshub template.
$template = Presshub\Template::create()
  ->setTitle('Your Article Title')
  ->setSubTitle('Your Article Subtitle')
  ->setCanonicalURL( 'http://example.com/your-article-url.html' )
  ->setThumbnail( 'https://example.com/article-thumbnail.jpg' )
  ->setKeywords(['Keyword1', 'Keyword2', 'Keyword3'])
  ->setTemplate( 'basic' )
  ->addComponent(
    Presshub\Template\Component::create()
      ->setMap('category')
      ->setValue('Test Category')
      ->setProps()
  )
  ->addComponent(
    Presshub\Template\Component::create()
      ->setMap('byline')
      ->setValue('By Author Name')
      ->setProps()
  )
  ->addComponent(
    Presshub\Template\Component::create()
      ->setMap('featured_image')
      ->setValue('URL')
      ->setProps([
        'Caption'      => 'Image caption',
        'Photographer' => 'Photo by Name',
      ])
  )
  ->addComponent(
    Presshub\Template\Component::create()
      ->setMap('body')
      ->setValue('<p>HTML content</p>')
      ->setProps()
  );

Presshub Client

$api_key_id = "YOUR_PRESSHUB_API_KEY";

// maximum amount of time in seconds to which the execution of individual
// cURL extension function calls will be limited. Note that the value 
// for this setting should include the value for $connect_timeout.
$timeout = 400;

// Maximum amount of time in seconds that is allowed to make the connection 
// to the server. It can be set to 0 to disable this limit, 
// but this is inadvisable in a production environment.
$connect_timeout = 0;

// Defaults to https://api.presshub.io/v1 However in some cases we create
// separate servers for premium clients.
$endpoint = "https://api.presshub.io/v1";

// Initialize Presshub Client object.
$client = new Presshub\Client($api_key, $timeout, $connect_timeout, $endpoint);
Preview Article
// Generate previewable files, more services can be added.
// Please follow example: 'FacebookIA' => []
$result = $client->setTemplate($template)
  ->setServices([
      'AppleNews' => [],
      'Twitter'   => [
        // When empty article title will be used.
        "message" => "This is how you could override the title"
      ]
  ])
  ->preview()
  ->execute();

var_dump($result);
Publish Article
// Publish article to AppleNews and Twitter.
// More can be added. See Get Services callback.
// $template - is a Presshub Template object. See above for an example.
$result = $client->setTemplate($template)
  ->setServices([
      'AppleNews' => [],
      'Twitter'   => [
        // When empty article title will be used.
        "message" => "This is how you could override the title",
        // Specify images - up to 5 supported.
        "media"   => [
          "https://images.unsplash.com/photo-1451153378752-16ef2b36ad05?dpr=1&auto=format&fit=crop&w=1500&h=1004&q=80&cs=tinysrgb&crop=",
          "https://images.unsplash.com/photo-1480129043491-6d5a4785b65c?dpr=1&auto=format&fit=crop&w=1500&h=1280&q=80&cs=tinysrgb&crop="
        ],
      ]
  ])
  ->publish()
  ->execute();

var_dump($result);
Update Article
// Update article in AppleNews and Twitter
// Please note not all services support update operation via API.
$result = $client->setTemplate($template)
  ->setServices([
      'AppleNews' => [],
      'Twitter'   => [
        // When empty article title will be used.
        "message" => "This is how you could override the title"
      ]
  ])
  // Presshub publication ID.
  ->update('POST_ID')
  ->execute();

var_dump($result);
Delete Article
// Delete article from AppleNews and Twitter
// Please note not all services support delete operation via API.
$result = $client->setServices([
      'AppleNews' => [],
      'Twitter'   => []
  ])
  ->delete('POST_ID')
  ->execute();

var_dump($result);

See examples directory for more code examples.

presshub-io/php-sdk 适用场景与选型建议

presshub-io/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 10 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「php」 「json」 「media」 「http」 「rest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 presshub-io/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 presshub-io/php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 presshub-io/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-31