Skip to content

Commit

Permalink
Add more information to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Grendel7 committed Dec 26, 2016
1 parent 96508fe commit 178cf45
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
# jsconnect-php
Vanilla Forums jsConnect for PHP, rebuilt for Composer
# Vanilla Forums jsConnect for Composer

Rebuild of the official [jsConnect PHP library](https://github.com/vanilla/jsConnectPHP) for Vanilla Forums. PSR compliant and easily installable through Composer.

## Installation
Add the composer dependency:
```bash
composer require hansadema/jsconnect
```

## Usage
The example below shows a standard use case for a logged in user.

```php
<?php

require_once '../vendor/autoload.php';

// Setup a Jsconnect instance
$jsConnect = new \HansAdema\JsConnect\JsConnect('YOUR CLIENT ID', 'YOUR CLIENT SECRET');

// Build a user object
$user = new \HansAdema\JsConnect\User([
'id' => 1234,
'name' => 'Example User',
'email' => '[email protected]',
'photoUrl' => 'http://example.com/user.jpg',
'roles' => ['member', 'administrator'],
]);

// Try to build the response
$response = $jsConnect->buildResponse($user, $_GET);

// Return the JSONP result
echo $_GET['callback'].'('.json_encode($response).')';
```

If the user is not logged in, the user object can be left empty. If there is an error, you can return an error with the response data:
```php
$response = [
'error' => 'invalid_client',
'message' => 'Your Custom Error Message',
];
```

0 comments on commit 178cf45

Please sign in to comment.