PHP code example of georgo / mojio

1. Go to this page and download the library: Download georgo/mojio library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

georgo / mojio example snippets


     

use Mojio\Api\Client;

secretKey = "{SecretKey}";

$client = Client::factory([
        'base_url' => Client::LIVE,
        'app_id' => $appId,
        'secret_key' => $secretKey
]);

// ...

// ...

// Set the redirect URI to point to this exact same script.
$redirectUri = 'https://' . $_SERVER['HTTP_HOST'] 
                   . strtok($_SERVER['REQUEST_URI'], '?');
                   
if(!isset($_GET['code'])) {
    // Initiate an OAuth request
    header('Location: '.$client->getAuthorizationUrl($redirectUri));
    exit;
} else {
    // Handle the OAuth response
    $client->authorize($redirectUri, $_GET['code']);
}

// ...
// Logout user.
$client->logout();

// ...
// Fetch first page of 15 users
$results = $client->getTrips([
    'pageSize' => 15,
    'page' => 1
]);

foreach( $results as $trip )
{
    // Do something with each trip
    // ...
}

// ...
$mojioId = "0a5123a0-7e70-12d1-a5k6-28db18c10200";
	
// Fetch mojio from API
$mojio = $client->getMojio([
    "id" => $mojioId
]);
	
// Do something with the mojio data
// ...

// ...
$appId = "0a5123a0-7e70-12d1-a5k6-28db18c10200";
	
// Fetch app from API
$app = $client->getApp([
    'id' => $appId
]);
	
// Make a change
$app->Name = "New Application Name";
	
// Save the changes
$client->saveEntity([
    'entity' => $app
]);

use Mojio\Api\Model\MojioEntity;
use Mojio\Api\Model\EventEntity;

    // ...
    $mojioId = "0a5123a0-7e70-12d1-a5k6-28db18c10200";
	
    // Fetch mojio's events
    $events = $client->getList([
        "type" => MojioEntity::getType(),
        "id" => $mojioId,
        "action" => EventEntity::getType()
    ]);
	
    // Or, alternatively
    $mojio = $client->getMojio(['id' => $mojioId]);
    $events = $client->getList([
        'entity' => $mojio,
        'action' => EventEntity::getType()
    ]);

    // ...

use Mojio\Api\Model\UserEntity;

    // ...
    $userId = "0a5453a0-7e70-16d1-a2w6-28dl98c10200";  // Some user's ID
    $key = "EyeColour";	// Key to store
    $value = "Brown"; 	// Value to store

    // Save user's eye colour
    $client.setStored([
        'type' => UserEntity::getType(),
        'id' => $userId,
        'key' => $key
        'value' => $value
    ]);

    // ...
    // Retrieve user's eye colour
    $client.getStored([
        'type' => UserEntity::getType(),
        'id' => $userId,
        'key' => $key
    ]);

    $mojioId = "0a5123a0-7e70-12d1-a5k6-28db18c10200";

    $sub = SubscriptionEntity::factory(
              'IgnitionOn', // Event Type to receive
              'Mojio',      // Subscription Type
              $mojioId,     // Entity ID
              "https://my-domain-example.com/receiver.php" // Location to send events
    );

    $client->newEntity(['entity' =>$sub]);


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $raw = file_get_contents('php://input');
  $event = json_decode( $raw );
  
  // ... Do something with the event!
}
Batchfile
    curl -sS https://getcomposer.org/installer | php
    php composer.phar install