kingSquare/wercker-sdk

Kingsquare PHP 客户端,用于与 Wercker API 交互

1.1.1 2019-06-20 14:13 UTC

This package is auto-updated.

Last update: 2024-09-21 01:13:59 UTC


README

Latest Stable Version License Total Downloads

这是一个非官方的 PHP SDK,用于Wercker 服务

底层库代码的大部分来自 Auth0/Sdk

安装

composer require kingsquare/wercker-sdk

使用方法

使用 composer 自动加载器之后

<?php

require_once 'vendor/autoload.php';

$token = getenv('WERCKER_API_TOKEN');
if (empty($token)) {
    throw new RuntimeException('No wercker token found. Please set your token as provided by Wercker (see https:devcenter.wercker.com/development/api/authentication/');
}
// username is required for certain API calls, but only with regards to the applications endpoint
$username = getenv('WERCKER_USER');

$wercker = new \Kingsquare\Wercker\Sdk($token, ['http_errors' => false]);

// APPLICATIONS
$filter = (new \Kingsquare\Wercker\Api\Request\Filter\Applications())
    ->limitBy(1);
$applications = $wercker->applications->find($username, $filter);

// DEPLOYS
$deploys = $wercker->applications->getDeploys($username, $applications[0]);

// RUNS
$filter = (new \Kingsquare\Wercker\Api\Request\Filter\Runs)
    ->byApplicationId($applications[0]->getId())
    ->limitBy(1);
$runs = $wercker->runs->find($filter);

// TRIGGERING A NEW RUN
//$triggeredRun = $wercker->runs->trigger(new \Kingsquare\Wercker\Api\Request\Run\Trigger($runs[0]->getPipeline()));

// Aborting A RUN
//$wercker->runs->abort($runId)

// STEPS
$steps = $wercker->runs->getSteps($runs[0]->getId());

// WORKFLOWS
$workflows = $wercker->workflows->find($applications[0]->getId());
// $workflow = $wercker->workflows->get($workflowId);

快速测试

创建一个包含 WERCKER_API_TOKEN 值的 .env 文件

WERCKER_API_TOKEN=123
WERCKER_USER=myUser

将上面的 PHP 脚本复制到 test.php 文件中,并使用 .env 变量运行

eval $(egrep -v '^#' .env | xargs) php test.php