Skip to content

Commit

Permalink
Merge pull request #9 from mouhsinelonly/master
Browse files Browse the repository at this point in the history
Https endpoint instead of http
  • Loading branch information
mikemix authored Apr 13, 2020
2 parents 9a7899f + c20e517 commit 702660d
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/vendor/
phpunit.xml
composer.lock
composer.phar
composer.phar
.phpintel
/.phpintel
26 changes: 26 additions & 0 deletions docs/virtual-classroom-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ try {
}
```

### Modify a class

```php
require 'vendor/autoload.php';

use mikemix\Wiziq;

$auth = new Wiziq\API\Auth('your-secret-access-key', 'public-access-key');
$gateway = new Wiziq\API\Gateway($auth);
$api = new Wiziq\API\ClassroomApi($gateway);

try {
$classroomId = 12345;
$classroom = Wiziq\Entity\Classroom::build('Class title', new \DateTime('now'))
->withPresenter(100, 'Presenter Name');

$response = $api->modify($classroomId, $classroom);

printf('Class %s created: %s', $classroom, var_export($response, true));
} catch (Wiziq\Common\Api\Exception\CallException $e) {
die($e->getMessage());
} catch (Wiziq\Common\Http\Exception\InvalidResponseException $e) {
die($e->getMessage());
}
```

### Add attendees to the class (not permament one)

```php
Expand Down
51 changes: 50 additions & 1 deletion src/API/ClassroomApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,60 @@ public function create(Classroom $classroom)
];
}

/**
* {@inheritdoc}
*/
public function modify($classroomId, Classroom $classroom)
{

$response = (boolean)$this->gateway->sendRequest(new Request\Modify($classroomId, $classroom))->modify["status"];

return $response;
}
/**
* {@inheritdoc}
*/
public function download($classroomId, $recordingFormat = 'zip')
{

$response = $this->gateway->sendRequest(new Request\Download($classroomId, $recordingFormat))->download_recording;

return $response;
}
/**
* {@inheritdoc}
*/
public function cancel($classroomId)
{
$this->gateway->sendRequest(new Request\Cancel($classroomId));
$response = (boolean)$this->gateway->sendRequest(new Request\Cancel($classroomId))->cancel['status'];
return $response;
}

/**
* {@inheritdoc}
*/
public function getAttendanceReport($classroomId)
{
$attendance = [];

$response = $this->gateway->sendRequest(new Request\AttendanceReport($classroomId))->get_attendance_report;

foreach($response->attendee_list[0] as $attendee) {
$data = [
'entry_time' => (string)$attendee->entry_time,
'exit_time' => (string)$attendee->exit_time,
'attended_minutes' => (string)$attendee->attended_minutes,
];
if(isset($attendee['presenter']) and $attendee['presenter']==true) {
$data['presenter_id'] = (int)$attendee->presenter_id;
} else {
$data['attendee_id'] = (int)$attendee->attendee_id;
}

$attendance[] = $data;
}

return $attendance;
}

/**
Expand Down Expand Up @@ -73,6 +121,7 @@ public function addAttendeesToClass($classroomId, Attendees $attendees)
}

/**
* @codeCoverageIgnore
* @param \SimpleXMLElement $response
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion src/API/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class Gateway
{
const URL = 'http://class.api.wiziq.com';
const URL = 'https://class.api.wiziq.com';

/** @var Auth */
private $auth;
Expand Down
32 changes: 32 additions & 0 deletions src/API/Request/AttendanceReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace mikemix\Wiziq\API\Request;

use mikemix\Wiziq\Common\Api\RequestInterface;
use mikemix\Wiziq\Entity\Classroom;

class AttendanceReport implements RequestInterface
{
/** @var ClassroomId */
private $classroomId;

public function __construct($classroomId)
{
$this->classroomId = $classroomId;
}

/**
* {@inheritdoc}
*/
public function getMethod()
{
return 'get_attendance_report';
}

/**
* {@inheritdoc}
*/
public function getParams()
{
return ['class_id' => $this->classroomId];
}
}
38 changes: 38 additions & 0 deletions src/API/Request/Download.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace mikemix\Wiziq\API\Request;

use mikemix\Wiziq\Common\Api\RequestInterface;

class Download implements RequestInterface
{
/** @var int */
private $classroomId;

private $recordingFormat;

public function __construct($classroomId, $recordingFormat)
{
$this->classroomId = $classroomId;

$this->recordingFormat = $recordingFormat;
}

/**
* {@inheritdoc}
*/
public function getMethod()
{
return 'download_recording';
}

/**
* {@inheritdoc}
*/
public function getParams()
{
return [
'class_id' => $this->classroomId,
'recording_format' => $this->recordingFormat
];
}
}
37 changes: 37 additions & 0 deletions src/API/Request/Modify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace mikemix\Wiziq\API\Request;

use mikemix\Wiziq\Common\Api\RequestInterface;
use mikemix\Wiziq\Entity\Classroom;

class Modify implements RequestInterface
{

/** @var int */
private $classroomId;

/** @var Classroom */
private $classroom;

public function __construct($classroomId, Classroom $classroom)
{
$this->classroomId = (int)$classroomId;
$this->classroom = $classroom;
}

/**
* {@inheritdoc}
*/
public function getMethod()
{
return 'modify';
}

/**
* {@inheritdoc}
*/
public function getParams()
{
return array_merge(['class_id' => $this->classroomId], $this->classroom->toArray());
}
}
18 changes: 17 additions & 1 deletion src/Common/Api/ClassroomApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,27 @@ interface ClassroomApiInterface
*/
public function create(Classroom $classroom);

/**
* Edit the classroom.
*
* @see http://developer.wiziq.com/classroom/method/modify
* Returned response is a boolean
* @param int $classroomId Wiziq's classroom ID
* @param Classroom $classroom New classroom's data
*
* @return void
*
* @throws Exception\CallException
*/
public function modify($classroomId, Classroom $classroom);


public function download($classroomId, $recordingFormat);
/**
* Cancel a class
*
* @see http://developer.wiziq.com/class/method/cancel
*
* Returned response is a boolean true or false
* @param int $classroomId Classroom ID
*
* @return void
Expand Down
6 changes: 5 additions & 1 deletion src/Entity/Classroom.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function toArray()
'title' => $this->title,
'start_time' => $this->startTime,
'language_culture_name' => $this->languageCultureName,
'extend_duration' => $this->extendDuration,
'duration' => $this->duration,
'time_zone' => $this->timeZone,
'attendee_limit' => $this->attendeeLimit,
Expand All @@ -95,6 +94,11 @@ public function toArray()
'status_ping_url' => $this->statusPingUrl,
];

if($this->extendDuration) {
$params['extend_duration'] = $this->extendDuration;

}

if ($this->presenterEmail) {
$params['presenter_email'] = $this->presenterEmail;
} else {
Expand Down
5 changes: 5 additions & 0 deletions tests/.resources/cancel-classroom-success-response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<rsp status="ok" call_id="g7hj8h2dgty4">
<method>cancel</method>
<cancel status="true">
</cancel>
</rsp>
30 changes: 30 additions & 0 deletions tests/.resources/get-attendance-report-success-response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<rsp status="ok">
<method>get_attendance_report</method>
<get_attendance_report status="true">
<class_id>15485</class_id>
<class_duration>20</class_duration>
<attendee_list>
<attendee presenter="true">
<presenter_id><![CDATA[656]]></presenter_id>
<screen_name><![CDATA[tsb_kid]]></screen_name>
<entry_time><![CDATA[6/22/2011 1:40:59 AM]]></entry_time>
<exit_time><![CDATA[6/22/2011 1:45:59 AM]]></exit_time>
<attended_minutes><![CDATA[6]]></attended_minutes>
</attendee>
<attendee>
<attendee_id><![CDATA[801]]></attendee_id>
<screen_name><![CDATA[shish801]]></screen_name>
<entry_time><![CDATA[6/22/2011 1:41:47 AM]]></entry_time>
<exit_time><![CDATA[6/22/2011 1:45:54 AM]]></exit_time>
<attended_minutes><![CDATA[5]]></attended_minutes>
</attendee>
<attendee>
<attendee_id><![CDATA[102]]></attendee_id>
<screen_name><![CDATA[shishpal]]></screen_name>
<entry_time><![CDATA[6/22/2011 1:42:11 AM]]></entry_time>
<exit_time><![CDATA[6/22/2011 1:46:18 AM]]></exit_time>
<attended_minutes><![CDATA[5]]></attended_minutes>
</attendee>
</attendee_list>
</get_attendance_report>
</rsp>
5 changes: 5 additions & 0 deletions tests/.resources/modify-classroom-success-response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<rsp status="ok" call_id="g7hj8h2dgty4">
<method>modify</method>
<modify status="true">
</modify>
</rsp>
45 changes: 42 additions & 3 deletions tests/API/ClassroomApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ public function testCreateClassroom()
], $this->sdk->create($classroom));
}

public function testModifyClassroom()
{
$classroom = Classroom::build('Title', new \DateTime('2015-12-30 12:30:50'));
$classroomId = 12187;

$this->assertArrayNotHasKey('extend_duration', $classroom->toArray());

$this->gateway->expects($this->once())
->method('sendRequest')
->with($this->equalTo(new Request\Modify($classroomId, $classroom)))
->will($this->returnValue(
simplexml_load_string(
file_get_contents(__DIR__ . '/../.resources/modify-classroom-success-response.txt')
)
));

$this->assertTrue($this->sdk->modify($classroomId, $classroom));
}

public function testGetAttendanceReport()
{
$classroomId = 12365;

$this->gateway->expects($this->once())
->method('sendRequest')
->with($this->equalTo(new Request\AttendanceReport($classroomId)))
->will($this->returnValue(
simplexml_load_string(
file_get_contents(__DIR__ . '/../.resources/get-attendance-report-success-response.txt')
)
));

$this->assertArraySubset([['entry_time'=>"6/22/2011 1:40:59 AM"]], $this->sdk->getAttendanceReport($classroomId));
}

public function testCreatePermaClass()
{
$classroom = PermaClassroom::build('Title', '[email protected]');
Expand Down Expand Up @@ -103,8 +138,12 @@ public function testCancel()

$this->gateway->expects($this->once())
->method('sendRequest')
->with($this->equalTo(new Request\Cancel($classroomId)));

$this->sdk->cancel($classroomId);
->with($this->equalTo(new Request\Cancel($classroomId)))
->will($this->returnValue(
simplexml_load_string(
file_get_contents(__DIR__ . '/../.resources/cancel-classroom-success-response.txt')
)
));
$this->assertTrue($this->sdk->cancel($classroomId));
}
}
Loading

0 comments on commit 702660d

Please sign in to comment.