kingsquare/wercker-sdk

Kingsquare PHP client for interacting with Wercker API

1.1.1 2019-06-20 14:13 UTC

This package is auto-updated.

Last update: 2024-04-21 00:22:54 UTC


README

Latest Stable Version License Total Downloads

This is an unofficial PHP SDK for the Wercker service

Much of the underlying library code was derived from the Auth0/Sdk

Installation

composer require kingsquare/wercker-sdk

Usage

After using the composer autoloader

<?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);

Quick testing

Create a .env file with the WERCKER_API_TOKEN value:

WERCKER_API_TOKEN=123
WERCKER_USER=myUser

copy the php script above into a test.php and run it with the .env variables loaded

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