Skip to content

Commit

Permalink
Completed addition of Attendees and Session operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Leslie Price committed Oct 2, 2019
1 parent 8ea660b commit 2a203fa
Show file tree
Hide file tree
Showing 22 changed files with 485 additions and 70 deletions.
140 changes: 134 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ https://goto-developer.logmeininc.com/content/gotowebinar-api-reference-v2

## Known Issues

* There are still some issues with the deletion of Registrants from a Webinar.
* There are still some issues with the deletion of Registrants from a Webinar by registrantKey
* Retrieving session attendees by registrantKey

## Contributions and Bug

Expand Down Expand Up @@ -103,15 +104,26 @@ _goto/flush-auth
_goto/webinars
_goto/webinars/create
_goto/webinars/createByArray
_goto/webinars/{webinarKey}/show
_goto/webinars/{webinarKey}/view
_goto/webinars/{webinarKey}/update
_goto/webinars/{webinarKey}/updateByArray
_goto/webinars/{webinarKey}/registrants
_goto/webinars/{webinarKey}/registrants/create
_goto/webinars/{webinarKey}/registrants/{registrantKey}/view
_goto/webinars/{webinarKey}/registrants/{registrantKey}/delete
_goto/webinars/{webinarKey}/registrants/{registrantKey}/show
_goto/webinars/{webinarKey}/attendees
_goto/webinars/{webinarKey}/delete
_goto/webinars/{webinarKey}/sessions
_goto/webinars/{webinarKey}/sessions/{sessionKey}
_goto/webinars/{webinarKey}/sessions/{sessionKey}/performance
_goto/webinars/{webinarKey}/sessions/{sessionKey}/polls
_goto/webinars/{webinarKey}/sessions/{sessionKey}/questions
_goto/webinars/{webinarKey}/sessions/{sessionKey}/surveys
_goto/webinars/{webinarKey}/sessions/{sessionKey}/attendees
_goto/webinars/{webinarKey}/sessions/{sessionKey}/attendees/{registrantKey}
_goto/webinars/{webinarKey}/sessions/{sessionKey}/attendees/{registrantKey}/polls
_goto/webinars/{webinarKey}/sessions/{sessionKey}/attendees/{registrantKey}/questions
_goto/webinars/{webinarKey}/sessions/{sessionKey}/attendees/{registrantKey}/surveys
```

## Authentication Token Caching
Expand Down Expand Up @@ -392,15 +404,131 @@ Delete a specific registrant by webinarKey and registrantKey, method returns `tr
->delete();
```

## Sessions

#### Get Organizer Sessions (Fluent)

```php
$from = Carbon\Carbon::now()->subYears(50)->startOfDay();
$to = Carbon\Carbon::now()->addYears(50)->endOfDay();

// Example: sessions?page=10&size=1
$page = request()->query('page') ?? 0;
$size = request()->query('size') ?? 5;

return Sessions::organizerSessions()
->fromTime($from)
->toTime($to)
->page($page)
->size($size)
->get();
```

#### Get Webinar Sessions (Fluent)

```php
// Example: sessions?page=10&size=1
$page = request()->query('page') ?? 0;
$size = request()->query('size') ?? 5;

return Sessions::webinarKey($webinarKey)
->page($page)
->size($size)
->get();
```

#### Get Session (Fluent)

```php
return Sessions::webinarKey($webinarKey)
->sessionKey($sessionKey)
->get();
```

#### Get Session Performance (Fluent)

```php
return Sessions::webinarKey($webinarKey)
->sessionKey($sessionKey)
->performance()
->get();
```

#### Get Session Polls (Fluent)

```php
return Sessions::webinarKey($webinarKey)
->sessionKey($sessionKey)
->polls()
->get();
```

#### Get Session Questions (Fluent)

```php
return Sessions::webinarKey($webinarKey)
->sessionKey($sessionKey)
->questions()
->get();
```

#### Get Session Surveys (Fluent)

```php
return Sessions::webinarKey($webinarKey)
->sessionKey($sessionKey)
->surveys()
->get();
```

## Attendees

Will be added shortly
#### Get Session Attendees (Fluent)

## Sessions
```php
return Attendees::webinarKey($webinarKey)
->sessionKey($sessionKey)
->get();
```

Will be added shortly
#### Get Attendee (Fluent)

```php
return Attendees::webinarKey($webinarKey)
->sessionKey($sessionKey)
->registrantKey($registrantKey)
->get();
```

#### Get Attendee Polls (Fluent)

```php
return Attendees::webinarKey($webinarKey)
->sessionKey($sessionKey)
->registrantKey($registrantKey)
->polls()
->get();
```

#### Get Attendee Questions (Fluent)

```php
return Attendees::webinarKey($webinarKey)
->sessionKey($sessionKey)
->registrantKey($registrantKey)
->questions()
->get();
```

#### Get Attendee Surveys (Fluent)

```php
return Attendees::webinarKey($webinarKey)
->sessionKey($sessionKey)
->registrantKey($registrantKey)
->surveys()
->get();
```

Your contribution or bug fixes are welcome!

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"aliases": {
"Webinars": "Slakbal\\Gotowebinar\\Facade\\Webinars",
"Registrants": "Slakbal\\Gotowebinar\\Facade\\Registrants",
"Attendees": "Slakbal\\Gotowebinar\\Facade\\Attendees"
"Attendees": "Slakbal\\Gotowebinar\\Facade\\Attendees",
"Sessions": "Slakbal\\Gotowebinar\\Facade\\Sessions"
}
}
},
Expand Down
25 changes: 16 additions & 9 deletions src/Client/GotoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Httpful\Mime;
use Httpful\Request;
use Illuminate\Http\Response;
use Slakbal\Gotowebinar\Exception\GotoException;

final class GotoClient
Expand Down Expand Up @@ -120,16 +119,24 @@ public function delete()

private function processResponse($response, $verb)
{
if ($response->code >= Response::HTTP_BAD_REQUEST) {
throw GotoException::responseException($response, null, $verb);
}

if ($response->code >= 200 && $response->code < 300) {
if ($verb === self::DELETE) {
return collect(true);
if ($response->code >= 100 && $response->code < 300) {
switch ($verb) {
case self::DELETE:
return collect(true);
break;
case self::PUT:
return collect(true);
break;
default:
return collect($response->body);
}
}

return collect($response->body);
throw GotoException::responseException($response, 'HTTP Response code: '.$response->code, $verb);
/*
if ($response->code >= Response::HTTP_BAD_REQUEST) {
throw GotoException::responseException($response, 'Response code: '.$response->code, $verb);
}
*/
}
}
2 changes: 1 addition & 1 deletion src/Exception/GotoException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static function responseException($response, $customMessage = null, $verb
{
$message = self::getResponseMessage($response, $customMessage);

Log::error('GOTOWEBINAR: '.self::formatVerb($verb).$message.' Payload: '.json_encode($response->body));
Log::error('GOTOWEBINAR: '.self::formatVerb($verb).$message.' - Payload: '.json_encode($response->body));

return new static($message);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Facade/Sessions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Slakbal\Gotowebinar\Facade;

use Illuminate\Support\Facades\Facade;
use Slakbal\Gotowebinar\Resources\Session\Session;

class Sessions extends Facade
{
protected static function getFacadeAccessor()
{
return Session::class;
}
}
7 changes: 6 additions & 1 deletion src/GotoWebinarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;
use Slakbal\Gotowebinar\Resources\Session\Session;
use Slakbal\Gotowebinar\Resources\Webinar\Webinar;
use Slakbal\Gotowebinar\Resources\Attendee\Attendee;
use Slakbal\Gotowebinar\Resources\Registrant\Registrant;
Expand All @@ -19,7 +20,7 @@ public function boot()
if (! App::environment('production')) {
$this->loadRoutesFrom(__DIR__.'/Routes/routes.php');
} else {
$this->defer = true;
$this->defer = true; //todo GotoIssue: this is deprecated, see if can be safely removed
}

$this->publishes([__DIR__.'/../config/goto.php' => config_path('goto.php')], 'config');
Expand All @@ -38,6 +39,10 @@ public function register()
return new Registrant();
});

$this->app->bind(Session::class, function () {
return new Session();
});

$this->app->bind(Attendee::class, function () {
return new Attendee();
});
Expand Down
5 changes: 2 additions & 3 deletions src/Resources/Attendee/Attendee.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace Slakbal\Gotowebinar\Resources\Attendee;

use Slakbal\Gotowebinar\Resources\AbstractResource;
use Slakbal\Gotowebinar\Resources\Traits\PagingQueryParameters;

final class Attendee extends AbstractResource
{
use PagingQueryParameters, AttendeeOperations;
use AttendeeQueryParameters, AttendeeOperations;

/** RESOURCE PATH **/
protected $baseResourcePath = '/organizers/:organizerKey/webinars/:webinarKey/attendees';
protected $baseResourcePath = '/organizers/:organizerKey/webinars/:webinarKey/sessions/:sessionKey/attendees';

public function __construct()
{
Expand Down
59 changes: 59 additions & 0 deletions src/Resources/Attendee/AttendeeOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,71 @@

namespace Slakbal\Gotowebinar\Resources\Attendee;

/*
* Operations available for attendees of a given webinar session.
*/

trait AttendeeOperations
{
/**
* Set the webinar key.
*/
public function webinarKey($webinarKey): self
{
$this->pathKeys['webinarKey'] = $webinarKey;

return $this;
}

/**
* Set the session key.
*/
public function sessionKey($sessionKey): self
{
$this->pathKeys['sessionKey'] = $sessionKey;

return $this;
}

/**
* Set the registrant key.
*/
public function registrantKey($registrantKey): self
{
$this->pathKeys['registrantKey'] = $registrantKey;

$this->resourcePath = $this->baseResourcePath.'/:registrantKey';

return $this;
}

/**
* Set the polls path.
*/
public function polls(): self
{
$this->resourcePath = $this->baseResourcePath.'/:registrantKey/polls';

return $this;
}

/**
* Set the questions path.
*/
public function questions(): self
{
$this->resourcePath = $this->baseResourcePath.'/:registrantKey/questions';

return $this;
}

/**
* Set the surveys path.
*/
public function surveys(): self
{
$this->resourcePath = $this->baseResourcePath.'/:registrantKey/surveys';

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Slakbal\Gotowebinar\Resources;
namespace Slakbal\Gotowebinar\Resources\Attendee;

trait HasPaging
use Carbon\Carbon;

trait AttendeeQueryParameters
{
public function page($value): self
{
Expand Down
13 changes: 0 additions & 13 deletions src/Resources/HasWebinar.php

This file was deleted.

Loading

0 comments on commit 2a203fa

Please sign in to comment.