Skip to content

Commit

Permalink
Merge pull request #6 from teodortalov/1.1-dev
Browse files Browse the repository at this point in the history
1.1 dev
  • Loading branch information
teodortalov committed May 8, 2015
2 parents 2437786 + 75ba2a9 commit d3b7ecd
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 187 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Citrix API - PHP warpper around GoToWebinar APIs - 2014
Citrix API - PHP warpper around GoToWebinar APIs - 2015
======

Install via Composer
Expand All @@ -12,12 +12,13 @@ Authenticate and Get Going in 15 seconds
All you need in order to authenticate with Citrix's API is consumer key, which you can obtain by registering at [Citrix Developer Center][1]. After registering and adding your application, you will be given *Consumer Key*,
*Consumer Secret*, and *Callback URL*. You need the *Consumer Key* in order for your application to authenticate with Citrix.

In addition to the *Consumer Key*, you need your *username* and *password*, which is the one that you use to login to say [GoToWebinar.com][2].
## Direct Authentication ##
In addition to the *Consumer Key*, for **Direct Authentication** you need your *username* and *password*, which is the one that you use to login to say [GoToWebinar.com][2].

You can authenticate to Citrix, and your GoToWebinar account respectively, like so:


$client = new \Citrix\Citrix('CONSUMER_KEY');
$client = new \Citrix\Authentication\Direct('CONSUMER_KEY');
$client->auth('USERNAME', 'PASSWORD');


Expand All @@ -37,6 +38,14 @@ In order to get all the upcoming webinars, you have to do this:
$webinars = $goToWebinar->getUpcoming();
var_dump($webinars) //this gives you all upcoming webinars

Getting past webinars
--

In order to get all the past webinars, you have to do this:

$goToWebinar = new \Citrix\GoToWebinar($client); //@see $client definition above
$webinars = $goToWebinar->getUpcoming();
var_dump($webinars) //this gives you all upcoming webinars

If you would like to get the registration/join URL for a webinar you can do so like this:
```php
Expand Down
19 changes: 11 additions & 8 deletions examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@

require_once 'vendor/autoload.php';

use Citrix\Citrix;
use Citrix\GoToWebinar;
use Citrix\Entity\Consumer;

//authenticate
$client = new Citrix('CONSUMER_KEY');
//authenticate with direct authentication
$client = new \Citrix\Authentication\Direct('CONSUMER_KEY');
$client->auth('USERNAME', 'PASSWORD');

//get upcoming weibnars
$goToWebinar = new GoToWebinar($client);
$goToWebinar = new \Citrix\GoToWebinar($client);
$webinars = $goToWebinar->getUpcoming();

//get info for a single webinar
/* @var $webinar Citrix\Enttiy\Webinar */
/* @var $webinar \Citrix\Entity\Webinar */
$webinar = reset($webinars);

//get registraion/join url
Expand All @@ -32,7 +29,7 @@

//register a user for a webinar
$data = array('email' => '[email protected]', 'firstName' => 'Teodor', 'lastName' => 'Talov');
$consumer = new Consumer($client);
$consumer = new \Citrix\Entity\Consumer($client);
$consumer->setData($data)->populate();

$registration = $webinar->registerConsumer($consumer);
Expand All @@ -42,3 +39,9 @@
}

var_dump('You just registered!');

//get past weibnars
$goToWebinar = new \Citrix\GoToWebinar($client);
$webinars = $goToWebinar->getPast();


44 changes: 44 additions & 0 deletions src/Citrix/Authentication/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: teodor
* Date: 5/8/15
* Time: 1:23 AM
*/

namespace Citrix\Authentication;

/*
* Wrapper class for all authentication methods.
* It could be used for a single point of entry foo authentication functionality.
*/
class Client {

private $authentication;
public function __construct($authentication = 'Direct'){

$this->setAuthentication($authentication);
}

public function auth(){
return $this->getAuthentication()->auth();
}
/**
* @return mixed
*/
public function getAuthentication()
{
return $this->authentication;
}

/**
* @param string $authentication
*/
public function setAuthentication($authentication)
{
$class = '\\Citrix\\Authentication\\' . $authentication;
$this->authentication = new $class();
return $this;
}

}
198 changes: 198 additions & 0 deletions src/Citrix/Authentication/Direct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<?php
/**
* Created by PhpStorm.
* User: teodor
* Date: 5/8/15
* Time: 1:23 AM
*/

namespace Citrix\Authentication;

use Citrix\ServiceAbstract;
use Citrix\CitrixApiAware;

/**
* Citrix Authentication
*
* Use this class to authenticate into Citrix APIs.
*
* @uses \Citrix\ServiceAbstract
* @uses \Citrix\CitrixApiAware
*/

class Direct extends ServiceAbstract implements CitrixApiAware
{

/**
* Authentication URL
* @var String
*/
private $authorizeUrl = 'https://api.citrixonline.com/oauth/access_token';

/**
* API key or Secret Key in Citrix's Developer Portal
* @var String
*/
private $apiKey;

/**
* Access Token
* @var String
*/
private $accessToken;

/**
* Organizer Key
* @var int
*/
private $organizerKey;

/**
* Being here bu passing the api key
*
* @param String $apiKey
*/
public function __construct($apiKey = null)
{
$this->setApiKey($apiKey);
}

/**
* Authenticate by passing username and password. Those are
* the same username and password that you use to login to
* www.gotowebinar.com
*
* @param String $username
* @param String $password
* @return \Citrix\Citrix
*/
public function auth($username, $password)
{

if(is_null($this->getApiKey())){
$this->addError('Direct Authentication requires API key. Please provide API key.');
return $this;
}

if(is_null($username) || is_null($password)){
$this->addError('Direct Authentication requires username and password. Please provide username and password.');
return $this;
}

$params = array(
'grant_type' => 'password',
'user_id' => $username,
'password' => $password,
'client_id' => $this->getApiKey()
);

$this->setHttpMethod('GET')
->setUrl($this->authorizeUrl)
->setParams($params)
->sendRequest()
->processResponse();

return $this;
}

/**
*
* @return the $apiKey
*/
public function getApiKey()
{
return $this->apiKey;
}

/**
*
* @param String $apiKey
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;

return $this;
}

/* (non-PHPdoc)
* @see \Citrix\CitrixApiAware::processResponse()
*/
public function processResponse()
{
$response = $this->getResponse();

if (empty($response)) {
return $this;
}

if (isset($response['int_err_code'])) {
$this->addError($response['msg']);
return $this;
}

$this->setAccessToken($response['access_token']);
$this->setOrganizerKey($response['organizer_key']);
return $this;
}

/**
*
* @return the $accessToken
*/
public function getAccessToken()
{
return $this->accessToken;
}

/**
*
* @param String $accessToken
*/
public function setAccessToken($accessToken)
{
$this->accessToken = $accessToken;

return $this;
}

/**
*
* @return the $authorizeUrl
*/
public function getAuthorizeUrl()
{
return $this->authorizeUrl;
}

/**
*
* @param string $authorizeUrl
*/
public function setAuthorizeUrl($authorizeUrl)
{
$this->authorizeUrl = $authorizeUrl;

return $this;
}

/**
*
* @return the $organizerKey
*/
public function getOrganizerKey()
{
return $this->organizerKey;
}

/**
*
* @param int $organizerKey
*/
public function setOrganizerKey($organizerKey)
{
$this->organizerKey = $organizerKey;

return $this;
}
}
Loading

0 comments on commit d3b7ecd

Please sign in to comment.