2017 © Pedro Peláez
 

library graphcommons-php7

PHP7 Wrapper for Graph Commons API/v1

image

graphcommons/graphcommons-php7

PHP7 Wrapper for Graph Commons API/v1

  • Tuesday, June 14, 2016
  • by k-gun
  • Repository
  • 1 Watchers
  • 5 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Graph Commons is a collaborative 'network mapping' platform and a knowledge base of relationships. You can map relationships at scale and unfold the mystery about complex issues that impact you and your community., (*1)

See more about here., (*2)

GraphCommons (for PHP7)

Before beginning;, (*3)

  • Set your autoloader properly or use composer
  • Use PHP >= 7.0.0 (see for other PHP < 7 support here)
  • Handle each action in try/catch blocks
  • On README, dump means var_dump

Notice: See Graph Commons's official documents here before using this library., (*4)

Installation

# composer
~$ composer require graphcommons/graphcommons-php7
// composer.json
{"require": {"graphcommons/graphcommons-php7": "~1.0"}}
// manual, after cloning to /path/to/GraphCommons
$autoload = require('/path/to/GraphCommons/Autoload.php');
$autoload->register();

Configuration

Configuration is optional but you can provide all these options;, (*5)

// dump whole stream while requests
$config['debug'] = false;
// stream blocking
$config['blocking'] = true;
// timeout for read
$config['timeout_read'] = 5;
// timeout for connection
$config['timeout_connection'] = 5;

Usage

use GraphCommons\{
    GraphCommons,
    Graph\Graph,
    Graph\Signal,
    Graph\SignalCollection
};

// init gc object
$gc = new GraphCommons('<YOUR API KEY>', $config=[]): GraphCommons
Check API Status

GET /api/v1/status, (*6)

dump $gc->api->status(): array
Get a Graph

Notice: You can see each graph data as JSON requesting https://graphcommons.com/graphs/<GRAPH ID>.json., (*7)

GET /api/v1/graphs/:id, (*8)

$graph = $gc->api->getGraph('<GRAPH ID>'): Graph

dump $graph->id: string
dump $graph->image->path: string
dump $graph->license->type: string
dump $graph->layout->springLength: int

// iteration over users, nodes, edges, nodeTypes, edgeTypes
foreach ($graph->users as $user) {
    print $user->id ."\n";
}
Add a New Graph

POST /api/v1/graphs, (*9)

$graph = $gc->api->addGraph((function() {
    $graph = new Graph();
    $graph->setName('Person Graph');
    $graph->setDescription('The Person Graph!');
    $graph->setStatus(Graph::STATUS_DRAFT);
    $graph->setSignals(SignalCollection::fromArray([
        [
            'action'        => Signal::NODE_CREATE,
            'parameters'    => [
                'name'      => 'Ahmet',
                'type'      => 'Person']],
        [
            'action'        => Signal::EDGE_CREATE,
            'parameters'    => [
                'from_name' => 'Ahmet',
                'from_type' => 'Person',
                'to_name'   => 'Burak',
                'to_type'   => 'Person',
                'name'      => 'COLLABORATED',
                'weight'    => 2]],
    ]));
    return $graph;
})()): Graph
Add a New Graph Signal

PUT /api/v1/graphs/:id/add, (*10)

$graph = $gc->api->addGraphSignal(
    '<GRAPH ID>', SignalCollection::fromArray([
        [
            'action'        => Signal::EDGE_CREATE,
            'parameters'    => [
                'from_name' => 'Ahmet',
                'from_type' => 'Person',
                'to_name'   => 'Fatih',
                'to_type'   => 'Person',
                'name'      => 'COLLABORATED',
                'weight'    => 2],
        ],
])): Graph
Get Graph Types

GET /api/v1/graphs/:id/types, (*11)

$graphTypes = $gc->api->getGraphTypes('<NODE ID>'): array
Check a Graph Edge

GET /api/v1/graphs/:id/edges, (*12)

 $data = $gc->api->isGraphEdgeExists('<NODE ID>',
   '<FROM ID>', '<TO ID>', $directed=true): bool
Get a Node

GET /api/v1/nodes/:id, (*13)

$graphNode = $gc->api->getNode('<NODE ID>'): GraphNode
Get (search) Nodes

GET /api/v1/nodes/search, (*14)

$graphNodes = $gc->api->getNodes([
    'query' => 'kerem',
    'limit' => 1,
]): GraphNodes

Error Handling

try {
    $gc->api->getGraph('nö!');
} catch (\Throwable $e) {
    // 404
    print $e->getCode() ."\n";
    // API error: code(404) message(Graph not found)
    print $e->getMessage() ."\n";

    // print original response status
    print $gc->client->response->getStatus() ."\n";
    // print original response body
    print $gc->client->response->getBody() ."\n";
}

The Versions

14/06 2016

dev-master

9999999-dev http://github.com/graphcommons/graphcommons-php7

PHP7 Wrapper for Graph Commons API/v1

  Sources   Download

The MIT License (MIT)

The Requires

  • php >=7.0.0

 

rest php7 graphcommons graph commons

14/06 2016

1.0.0

1.0.0.0 http://github.com/graphcommons/graphcommons-php7

PHP7 Wrapper for Graph Commons API/v1

  Sources   Download

The MIT License (MIT)

The Requires

  • php >=7.0.0

 

rest php7 graphcommons graph commons