PHP code example of i3-hackathon / bmw-php-sdk

1. Go to this page and download the library: Download i3-hackathon/bmw-php-sdk 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/ */

    

i3-hackathon / bmw-php-sdk example snippets


     

use Mojio\Api\Client;

secretKey = "{SecretKey}";

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

// ...

// ...
<<<<<<< HEAD
// Authenticate specific user
$client->login(array(
    'userOrEmail' => '[email protected]',
    'password' => 'mypassword',
));
	
=======
// Set the redirect URI to point to this exact same script.
$redirectUri = (isset($_SERVER['HTTPS']) ? 'https' : 'http')
                   . '://' . $_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']);
}

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

// ...
// Fetch first page of 15 users
$results = $client->getTrips(array(
    '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(array(
    "id" => $mojioId
));
	
// Do something with the mojio data
// ...

// ...
$appId = "0a5123a0-7e70-12d1-a5k6-28db18c10200";
	
// Fetch app from API
$app = $client->getApp(array(
    'id' => $appId
));
	
// Make a change
$app->Name = "New Application Name";
	
// Save the changes
$client->saveEntity(array(
    '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(array(
        "type" => MojioEntity::getType(),
        "id" => $mojioId,
        "action" => EventEntity::getType()
    ));
	
    // Or, alternatively
    $mojio = $client->getMojio(array( 'id' => $mojioId ));
    $events = $client->getList(array(
        '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( array(
        'type' => UserEntity::getType(),
        'id' => $userId,
        'key' => $key
        'value' => $value
    ));

    // ...
    // Retrieve user's eye colour
    $client.getStored( array(
        '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
              "http://my-domain-example.com/receiver.php" // Location to send events
    );

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


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