Ejemplo n.º 1
0
 public function getClient()
 {
     $mode = getenv('HttpPlayback');
     if ($mode == false) {
         $mode = 'playback';
     }
     $auth = ['server' => 'server', 'user' => 'user', 'password' => 'password'];
     if (is_file(getcwd() . '/Resources/auth.json')) {
         $auth = json_decode(file_get_contents(getcwd() . '/Resources/auth.json'), true);
     }
     $client = new API();
     $client->buildClient($auth['server'], $auth['user'], $auth['password'], ['httpPlayback' => ['mode' => $mode, 'recordFileName' => self::class . '::' . $this->getName() . '.json']]);
     return $client->getClient()->getClient();
 }
Ejemplo n.º 2
0
 public function testWithCallbackToken()
 {
     //Create our expected item, get our class to build our item, then compare
     $expected = ExchangeWebServices::fromCallbackToken('test.com', 'token', ['version' => ExchangeWebServices::VERSION_2010]);
     $client = API::withCallbackToken('test.com', 'token');
     $actual = $client->getClient();
     $this->assertEquals($expected, $actual);
 }
Ejemplo n.º 3
0
<?php

/**
 * Quick Start
 *
 * This file is an example of how to quickly create a Calendar Item without going through the CalendarAPI, to show
 * that you can create items directly
 */
//Include the API
use jamesiarmes\PEWS\API;
use jamesiarmes\PEWS\API\Enumeration;
//Create and build the client
$api = new API();
$api->buildClient('server', 'username', 'password');
//Get the folder to save the event to
$folderId = $api->getFolderByDistinguishedId('calendar');
//Create our event
$item = array('CalendarItem' => array('Start' => (new \DateTime('8:00 AM'))->format('c'), 'Subject' => 'The Event Subject'));
//Set our options
$options = array('SendMeetingInvitations' => Enumeration\CalendarItemCreateOrDeleteOperationType::SEND_TO_NONE, 'SavedItemFolderId' => array('FolderId' => array('Id' => $folderId->Id)));
//Send the request
$items = $api->createItems($item, $options);
Ejemplo n.º 4
0
<?php

use jamesiarmes\PEWS\API;
$api = new API();
$api->buildClient('server', 'username', 'password');
$calendar = $api->getCalendar();
$start = new DateTime('8:00 AM');
$end = new DateTime('9:00 AM');
$response = $calendar->createCalendarItems(array('Subject' => 'Test', 'Start' => $start->format('c'), 'End' => $end->format('c')));
Ejemplo n.º 5
0
<?php

use jamesiarmes\PEWS\API\Type\ConnectingSIDType;
use jamesiarmes\PEWS\API\Type\ExchangeImpersonation;
//Impersonate an email address
$api = \jamesiarmes\PEWS\API::withUsernameAndPassword('server', 'username', 'password', ['impersonation' => '*****@*****.**']);
//Build your own impersonation
$connectingSID = new ConnectingSIDType();
$connectingSID->setPrincipalName('Some Name');
$connectingSID->setPrimarySmtpAddress('*****@*****.**');
$impersonation = new ExchangeImpersonation();
$impersonation->setConnectingSID($connectingSID);
$api = \jamesiarmes\PEWS\API::withUsernameAndPassword('server', 'username', 'password', ['impersonation' => $impersonation]);
Ejemplo n.º 6
0
<?php

use jamesiarmes\PEWS\API;
use jamesiarmes\PEWS\API\ExchangeWebServicesAuth;
//In order to work with Exchange API, there are a couple of things you need. Your Client ID which is the ID of your
//application when you registered it, your Client Secret which is the password you generated for your application,
//a Redirect URI which is what you set in your registration panel specific for this application and an Authorization
// Code or Token which is retrieved as part of your authorization with the user.
$clientId = null;
$clientSecret = null;
$redirectUri = null;
//At this point you should have already gotten your authorization_code. That's something that needs to be managed by
//your applicaiton, not this library. Once you have your authorization_code, the library can help you turn that in to a
//authorization_token which can be used to talk to Office365.
$authorizationCode = 'The Code you already fetched.';
//Your code is a one-time use code, but your token will last for a little bit of time. It won't last forever, but you
//should only need one token per session. Likewise, since the token lasts a while you'll want to store it somewhere,
//you don't get a new token every time.
$token = $storage->getToken();
if (!$token) {
    $token = ExchangeWebServicesAuth::getTokenFromAuthorizationCode($clientId, $clientSecret, $authorizationCode, $redirectUri);
}
//Once you have your token you can just create your API as easily as before, but with the token instead of with a
//username and a password
$api = API::withCallbackToken('outlook.office365.com', $token);
Ejemplo n.º 7
0
<?php

use jamesiarmes\PEWS\API;
$api = API::withUsernameAndPassword('server', 'username', 'password');
$calendar = $api->getCalendar();
//Delete One Item
$item = $calendar->getCalendarItems()[0];
$calendar->deleteCalendarItem($item->getItemId());
//Delete all items between two date ranges
$calendar->deleteAllCalendarItems(new DateTime('8:00 AM'), new DateTime('5:00 PM'));
Ejemplo n.º 8
0
<?php

require_once "vendor/autoload.php";
use jamesiarmes\PEWS\API\Type;
use jamesiarmes\PEWS\API\Type\CalendarItem;
use jamesiarmes\PEWS\Caster;
use jamesiarmes\PEWS\Test\API\TypeTest;
use jamesiarmes\PEWS\Calendar\CalendarAPI;
$api = \jamesiarmes\PEWS\API::withUsernameAndPassword('server', 'username', 'password', ['primarySmtpEmailAddress' => '*****@*****.**']);
$api->getFolderByDistinguishedId('inbox');
Ejemplo n.º 9
0
 /**
  * Get a list of changes on the calendar items
  *
  * @param null $syncState
  * @param array $options
  * @return mixed
  */
 public function listChanges($syncState = null, $options = array())
 {
     return parent::listItemChanges($this->getFolderId()->Id, $syncState, $options);
 }
Ejemplo n.º 10
0
<?php

/**
 * Building Requests
 *
 * This file is an example on how to build requests manually and execute them directly instead of relying on the
 * simple use section of the library. Essentially, you can create your requests in arrays, pass them through
 * Type::buildFromArray($array) and then post them straight to the API Client.
 */
//Include the API
use jamesiarmes\PEWS\API;
use jamesiarmes\PEWS\API\Enumeration;
use jamesiarmes\PEWS\API\Type;
//Create and build the client
$api = new API();
$api->buildClient('server', 'username', 'password');
//Build the request as an array
$request = array('FolderShape' => array('BaseShape' => array('_' => 'Default')), 'FolderIds' => array('DistinguishedFolderId' => array('Id' => 'calendar')));
//Turn the array in to an object to pass to the API
$request = Type::buildFromArray($request);
//Send the request and get the response
$response = $api->getClient()->GetFolder($request);