Skip to content

Commit

Permalink
- Added behaviour attributes
Browse files Browse the repository at this point in the history
- Added behaviour delete
- Added behaviour post
- Added achievement attributes
- Added achievement delete
- Added achievement post
  • Loading branch information
philipmclifton committed May 10, 2017
1 parent d11f917 commit eb49452
Show file tree
Hide file tree
Showing 13 changed files with 417 additions and 130 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ vendor/*
composer.lock
composer.phar
.token
.school
.school
.idea
116 changes: 116 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,60 @@ foreach ($school->achievements->all() as $achievement) {
echo $achievement->comment . PHP_EOL;
}
```

### POST Achievements

```php
$client = new \Wonde\Client('TOKEN_GOES_HERE');
$school = $client->school('SCHOOL_ID_GOES_HERE');

$array = [
'students' => [
[
'student_id' => 'A1039521228',
'points' => 200,
'award' => 'TROP',
'award_date' => '2016-04-05',
],
],
'employee_id' => 'A1375078684',
'date' => '2016-04-04',
'type' => 'NYPA',
'comment' => 'A4',
'activity_type' => 'RE',
];

try {
$response = $school->achievements->create($array);
} catch (\Wonde\Exceptions\ValidationError $error) {
$errors = $error->getErrors();
}
```

### DELETE Achievements

```php
$client = new \Wonde\Client('TOKEN_GOES_HERE');

$school = $client->school('SCHOOL_ID_GOES_HERE');

$school->achievements->delete('WONDE_ACHIEVEMENTS_ID_HERE');
```

### Achievements Attributes

```php
$client = new \Wonde\Client('TOKEN_GOES_HERE');

$school = $client->school('SCHOOL_ID_GOES_HERE');

// Get achievement attributes
foreach ($school->achievementsAttributes->all() as $achievement) {
echo $achievement->id . PHP_EOL;
}
```


### Assessment - (BETA)
This endpoint is included in the stable release but is likely to change in the future. Please contact support for more information.

Expand Down Expand Up @@ -245,6 +299,68 @@ foreach ($school->behaviours->all() as $behaviour) {
}
```

### POST Behaviours

```php
$client = new \Wonde\Client('TOKEN_GOES_HERE');
$school = $client->school('SCHOOL_ID_GOES_HERE');

$array = [
'students' => [
[
'student_id' => 'A1039521228',
'role' => 'AG',
'action' => 'COOL',
'action_date' => '2016-04-01',
'points' => 200,
],
[
'student_id' => 'A870869351',
'role' => 'TA',
'points' => 2,
],
],
'employee_id' => 'A1375078684',
'date' => '2016-03-31',
'status' => 'REV2',
'type' => 'BULL',
'bullying_type' => 'B_INT',
'comment' => 'Bulling incident',
'activity_type' => 'RE',
'location' => 'CORR',
'time' => 'LUN',
];

try {
$response = $school->behaviours->create($array);
} catch (\Wonde\Exceptions\ValidationError $error) {
$errors = $error->getErrors();
}
```

### DELETE Behaviours

```php
$client = new \Wonde\Client('TOKEN_GOES_HERE');

$school = $client->school('SCHOOL_ID_GOES_HERE');

$school->behaviours->delete('WONDE_BEHAVIOUR_ID_HERE');
```

### Behaviours Attributes

```php
$client = new \Wonde\Client('TOKEN_GOES_HERE');

$school = $client->school('SCHOOL_ID_GOES_HERE');

// Get behaviours
foreach ($school->behavioursAttributes->all() as $behaviour) {
echo $behaviour->id . PHP_EOL;
}
```

### Classes

```php
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function revokeAccess($schoolId)
{
$uri = 'schools/' . $schoolId . '/revoke-access';

return (new BootstrapEndpoint($this->token, $uri))->delete();
return (new BootstrapEndpoint($this->token, $uri))->deleteRequestReturnBody($uri);
}
}

24 changes: 24 additions & 0 deletions src/Endpoints/Achievements.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
<?php namespace Wonde\Endpoints;

use GuzzleHttp\Psr7\Response;

class Achievements extends BootstrapEndpoint
{
/**
* @var string
*/
public $uri = 'achievements/';

/**
* Delete a achievement record by it's Wonde ID
*
* @param array $id
* @return Response
*/
public function delete($id)
{
return parent::deleteRequestReturnBody($this->uri . $id);
}

/**
* Create a achievement record
*
* @param $array
* @return \stdClass
*/
public function create($array)
{
return parent::post($array);
}
}
9 changes: 9 additions & 0 deletions src/Endpoints/AchievementsAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php namespace Wonde\Endpoints;

class AchievementsAttributes extends BootstrapEndpoint
{
/**
* @var string
*/
public $uri = 'achievements/attributes/';
}
24 changes: 24 additions & 0 deletions src/Endpoints/Behaviours.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
<?php namespace Wonde\Endpoints;

use GuzzleHttp\Psr7\Response;

class Behaviours extends BootstrapEndpoint
{
/**
* @var string
*/
public $uri = 'behaviours/';

/**
* Delete a behaviour record by it's Wonde ID
*
* @param array $id
* @return Response
*/
public function delete($id)
{
return parent::deleteRequestReturnBody($this->uri . $id);
}

/**
* Create a behaviour record
*
* @param $array
* @return \stdClass
*/
public function create($array)
{
return parent::post($array);
}
}
9 changes: 9 additions & 0 deletions src/Endpoints/BehavioursAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php namespace Wonde\Endpoints;

class BehavioursAttributes extends BootstrapEndpoint
{
/**
* @var string
*/
public $uri = 'behaviours/attributes/';
}
33 changes: 12 additions & 21 deletions src/Endpoints/BootstrapEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Response;
use Wonde\Exceptions\ValidationError;
use Wonde\ResultIterator;

Expand Down Expand Up @@ -205,38 +206,28 @@ public function deleteRequest($endpoint, $body = [])
}

/**
* Make a delete request to url
* Make a delete request and return json decoded body
*
* @param $url
* @param $endpoint
* @param array $body
* @return mixed|\Psr\Http\Message\ResponseInterface
*/
private function deleteUrl($url, $body = [])
public function deleteRequestReturnBody($endpoint, $body = [])
{
return $this->client()->delete($url, $body);
/** @var Response $response */
$response = $this->deleteUrl(self::endpoint . $endpoint, $body);
return json_decode($response->getBody()->getContents());
}

/**
* Make a delete request and decode the response
* Make a delete request to url
*
* @param $url
* @param array $body
* @return \stdClass
* @return mixed|\Psr\Http\Message\ResponseInterface
*/
public function delete($body = [])
private function deleteUrl($url, $body = [])
{
$body = ['body' => json_encode($body)];
$body['headers']['Content-Type'] = 'application/json';

try {
$delete = $this->deleteRequest($this->uri, $body);
} catch ( ClientException $exception ) {
return $this->throwError($exception);
}

$response = $delete->getBody()->getContents();

$decoded = json_decode($response);

return $decoded;
return $this->client()->delete($url, $body);
}
}
43 changes: 23 additions & 20 deletions src/Endpoints/Schools.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Schools extends BootstrapEndpoint

/**
* Schools constructor.
*
* @param string $uri
*/
public function __construct($token, $id = false)
Expand All @@ -119,26 +120,28 @@ public function __construct($token, $id = false)
$this->uri = $this->uri . $id . '/';
}

$this->achievements = new Achievements($token, $this->uri);
$this->assessment = new Assessment($token, $this->uri);
$this->attendance = new Attendance($token, $this->uri);
$this->behaviours = new Behaviours($token, $this->uri);
$this->classes = new Classes($token, $this->uri);
$this->contacts = new Contacts($token, $this->uri);
$this->counts = new Counts($token, $this->uri);
$this->deletions = new Deletions($token, $this->uri);
$this->employees = new Employees($token, $this->uri);
$this->events = new Events($token, $this->uri);
$this->groups = new Groups($token, $this->uri);
$this->lessons = new Lessons($token, $this->uri);
$this->lessonAttendance = new LessonAttendance($token, $this->uri);
$this->medicalConditions = new MedicalConditions($token, $this->uri);
$this->medicalEvents = new MedicalEvents($token, $this->uri);
$this->periods = new Periods($token, $this->uri);
$this->photos = new Photos($token, $this->uri);
$this->rooms = new Rooms($token, $this->uri);
$this->students = new Students($token, $this->uri);
$this->subjects = new Subjects($token, $this->uri);
$this->achievements = new Achievements($token, $this->uri);
$this->achievementsAttributes = new AchievementsAttributes($token, $this->uri);
$this->assessment = new Assessment($token, $this->uri);
$this->attendance = new Attendance($token, $this->uri);
$this->behaviours = new Behaviours($token, $this->uri);
$this->behavioursAttributes = new BehavioursAttributes($token, $this->uri);
$this->classes = new Classes($token, $this->uri);
$this->contacts = new Contacts($token, $this->uri);
$this->counts = new Counts($token, $this->uri);
$this->deletions = new Deletions($token, $this->uri);
$this->employees = new Employees($token, $this->uri);
$this->events = new Events($token, $this->uri);
$this->groups = new Groups($token, $this->uri);
$this->lessons = new Lessons($token, $this->uri);
$this->lessonAttendance = new LessonAttendance($token, $this->uri);
$this->medicalConditions = new MedicalConditions($token, $this->uri);
$this->medicalEvents = new MedicalEvents($token, $this->uri);
$this->periods = new Periods($token, $this->uri);
$this->photos = new Photos($token, $this->uri);
$this->rooms = new Rooms($token, $this->uri);
$this->students = new Students($token, $this->uri);
$this->subjects = new Subjects($token, $this->uri);
}

/**
Expand Down
Loading

0 comments on commit eb49452

Please sign in to comment.