Skip to content

spiralover/nerve-client-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nerve PHP Client

Webhook Payload Router PHP Client

Getting started

composer require spiralover/nerve-client

Usage

Neuron Management

<?php

use SpiralOver\Nerve\Client\Neuron;

require __DIR__ . '/vendor/autoload.php';

$client  = Neuron::client(pat: '<personal-access-token>');

// List
$neurons = $client->list();

// Create
$created = $client->create(
    name: 'My Neuron 1',
    uniqueName: 'my.neuron.1',
    visibility: 'public',
    url: 'localhost:7788',
    webhook: 'localhost:7788/webhook',
    desc: 'Hello World',
);

// Update
$updated = $client->update(
    id: $created->neuron_id,
    name: 'My Neuron 1',
    uniqueName: 'my.neuron.1',
    visibility: 'public',
    url: 'localhost:7788',
    webhook: 'localhost:7788/webhook',
    desc: 'Hello World',
);

// Fetch Info
$viewed = $neuron->read($created->neuron_id);

// Delete
$message = $neuron->delete($created->neuron_id);

Emitting Impulses

Sending impulse(event) to webhooks

<?php

use SpiralOver\Nerve\Client\Neuron;

require __DIR__ . '/vendor/autoload.php';

$client  = Neuron::client(pat: '<personal-access-token>');    
$uniqueReference = sprintf('my-unique-app-prefix-%s', uniqid(more_entropy: true));
$response = $client->emitImpulse(
    neuronId: 'ba666184-1e8d-43c0-b59a-ac7240897875',
    name: 'user.created',
    data: [
        'first_name' => 'Jane',
        'last_name' => 'Doe',
        'email' => 'jane.doe@example.com'
    ],
    endpoint: 'http://localhost:9999',
    uniqueReference: $uniqueReference,
    callback: 'http://localhost:7777',
    callbackOnSuccess: false,
    callbackOnFailure: true,
    withImpulseMetadata: true
);

Receiving Impulses

Receiving impulse(event) from webhook

<?php

use SpiralOver\Nerve\Client\Webhook;

require __DIR__ . '/vendor/autoload.php';

$webhook  = Webhook::capture(secret: '<personal-access-token>');
if (!$webhook->isVerified) {    // impulse verification failed
    http_response_code(401);
}

$message = $webhook->message;

Client Options

<?php

use SpiralOver\Nerve\Client\Neuron;

require __DIR__ . '/vendor/autoload.php';

$client  = Neuron::client(
    pat: '<personal-access-token>',
    server: Neuron::SERVER_SPIRALOVER,
    apiVersion: Neuron::API_VERSION_1_0
);

Enjoy 😎

About

Webhook Payload Router PHP Client

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages