otar/puffer

PHP 对 Buffer API 的封装库。

1.0.4 2014-10-22 18:08 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:32:02 UTC


README

Latest Stable Release Build Status License

Puffer 是一个用于 PHP 的 Buffer API 封装库。

完整文档即将推出。同时,您可以查看下面的 基本用法基本文档 部分。同时,深入了解源代码,我们都是黑客,对吧? :)

安装

让 Puffer 运行起来的最佳方式是使用 Composer。在您的 composer.json 需求中包含 otar/puffer

{
    "require": {
        "otar/puffer": "1.*"
    }
}

或者您可以从这个存储库中获取代码,但您将需要手动在 vendor/ 目录中安装依赖项,并处理 PSR-4 自动加载。

基本用法

初始化 & 授权

<?php

use Puffer\Puffer;

$puffer = new Puffer([
    'consumer_key' => 'YOUR_CONSUMER_KEY_HERE',
    'consumer_secret' => 'YOUR_CONSUMER_SECRET_HERE',
    'access_token' => 'YOUR_ACCESS_TOKEN_HERE', // If you have one, or authorization will be required
    'storage' => new \Puffer\Storages\Session // Stores tokens in the session (default). Implement Puffer\StorageInterface class to save tokens in the database.
]);

if (!$puffer->isAuthorized()) {
    header('Location: ' . $puffer->getAuthUrl());
    exit;
}

var_dump($puffer->user); // Get user settings

列出您的配置文件

<?php

use Puffer\Profiles;

$profiles = new Profiles;

var_dump($profiles->all()); // All profiles

// Also Profiles object can be accessed as an array,
$first_profile = $profiles[0];

// be counted,
$number_of_profiles = count($profiles);

// or even be iterated.
foreach ($profiles AS $profile) {
    $profile->create('Hello World');
}

列出挂起的更新

<?php

use Puffer\Profiles;

// Grab first profile and it's pending updates in one line.
$pending = (new Profiles)[0]->pending();

创建一个更新

<?php

use Puffer\Profile;

$profile = new Profile('YOUR_PROFILE_ID_HERE');
$result = $profile->create('Hello World');

if ((bool) $result->success) {
    echo 'One more update buffered in your queue.';
} else {
    echo 'Something went wrong.';
}

// Or like this:

$result = (new Profile('YOUR_PROFILE_ID_HERE'))->create('Hello World');

删除挂起的更新

<?php

use Puffer\Profiles;
use Puffer\Update;

// If you have an update id, then:
$update = new Update('UPDATE_ID_HERE');
$update->delete();

// Or grab first profile and delete first pending update in one line:

$result = (new Profiles)[0]->pending()[0]->destroy();

基本文档

库根据上下文分为四个主要类

  • Puffer
    • 用于初始化、授权和对 API 进行调用。
    • 通过访问 userconfiguration 对象属性从 /user/info/configuration 获取相关结果。
    • shares() 接受链接作为参数,并通过 Buffer 平台返回其分享数量。
  • 配置文件
    • 检索您账户下的所有配置文件。
    • 使用 all() 方法以数组形式返回配置文件。
    • 配置文件可以作为数组访问、在循环中迭代或使用 PHP 的 count 函数进行计数。
    • 所有配置文件都返回为具有自身功能的对象。请参阅以下配置文件描述。
  • 配置文件
    • 接受配置文件 ID 作为参数。
    • 可以从对象的属性或作为关联数组访问配置文件数据。
    • sent() 方法返回此配置文件已发送的更新,而 pending() 方法返回当前缓冲/挂起的更新。
    • 您可以直接从 create() 方法创建/缓冲更新。接受文本作为参数。
  • 更新
    • 接受更新 ID 作为参数。
    • 可以从对象的属性或作为关联数组访问更新数据。
    • 支持这些方法:edit()share()interactions()destroy()moveToTop()

强烈建议将您的 Puffer 代码包装在 try/catch 块中,它将在发生错误时抛出 Puffer\Exception

贡献

如果您想为此项目做出贡献,首先您需要设置本地开发环境。

我鼓励您使用 GruntJS。您需要从 NPM 安装以下 NodeJS 模块(我可能在将来切换到 Bower)

  • grunt-phplint
  • grunt-php-cs-fixer
  • grunt-phpunit
  • grunt-contrib-watch
  • grunt-notify

在安装了 GruntJS 插件后,只需运行 grunt 命令。它将开始监视 src/tests/ 目录中的更改,并在您更改 *.php 文件时运行 Grunt 任务。

对于测试,您可能更喜欢使用本地的 PHPUnit 安装,请确保它已更新到最新版本。

首先创建一个问题,分支存储库,进行更改,然后创建“pull request”。

最后说明

联系我的最佳方式是电子邮件或Twitter。请在此处查看我的联系方式:http://otar.me

为了帮助您在愉悦的心情中读完这些内容,这里有一个笑话

Husband: make me a sandwich.
Wife: what? make it yourself!
Husband: sudo make me a sandwich.
Wife: okay...

感谢您一直关注! :)