Skip to content

Commit

Permalink
Add support for regional domains (#11)
Browse files Browse the repository at this point in the history
* Add missing attribute objects to School endpoint

* Add support for regional domains

* Test functions for regional domain support

Co-authored-by: Ben Hewitt <[email protected]>
  • Loading branch information
bluesky-ben and sidrablueben authored Jul 2, 2020
1 parent ad909ee commit 38e7a38
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 5 deletions.
30 changes: 26 additions & 4 deletions src/Endpoints/BootstrapEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ class BootstrapEndpoint
{
/**
* @var string
* @deprecated To allow for regional domains. Use getEndpoint instead
* @see BootstrapEndpoint::getEndpoint()
*/
const endpoint = 'https://api.wonde.com/v1.0/';

/**
* @var string
*/
public $domain = 'api.wonde.com';

/**
* @var string
*/
public $version = 'v1.0';

/**
* @var string
*/
Expand Down Expand Up @@ -110,7 +122,7 @@ public function all($includes = [], $parameters = [])
*/
private function getRequest($endpoint)
{
return $this->getUrl(self::endpoint . $endpoint);
return $this->getUrl($this->getEndpoint() . $endpoint);
}

/**
Expand Down Expand Up @@ -166,7 +178,7 @@ public function getWithMeta($id, $includes = [], $parameters = [])
*/
public function postRequest($endpoint, $body = [])
{
return $this->postUrl(self::endpoint . $endpoint, $body);
return $this->postUrl($this->getEndpoint() . $endpoint, $body);
}

/**
Expand Down Expand Up @@ -215,7 +227,7 @@ public function post($body = [])
*/
public function deleteRequest($endpoint, $body = [])
{
return $this->deleteUrl(self::endpoint . $endpoint, $body);
return $this->deleteUrl($this->getEndpoint() . $endpoint, $body);
}

/**
Expand All @@ -228,7 +240,7 @@ public function deleteRequest($endpoint, $body = [])
public function deleteRequestReturnBody($endpoint, $body = [])
{
/** @var Response $response */
$response = $this->deleteUrl(self::endpoint . $endpoint, $body);
$response = $this->deleteUrl($this->getEndpoint() . $endpoint, $body);
return json_decode($response->getBody()->getContents());
}

Expand All @@ -243,4 +255,14 @@ private function deleteUrl($url, $body = [])
{
return $this->client()->delete($url, $body);
}

/**
* Get base endpoint
*
* @return string
*/
public function getEndpoint()
{
return "https://{$this->domain}/{$this->version}/";
}
}
41 changes: 40 additions & 1 deletion src/Endpoints/Schools.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Schools extends BootstrapEndpoint
*/
public $achievements;

/**
* @var AchievementsAttributes
*/
public $achievementsAttributes;

/**
* @var Attendance
*/
Expand All @@ -27,6 +32,11 @@ class Schools extends BootstrapEndpoint
*/
public $behaviours;

/**
* @var BehavioursAttributes
*/
public $behavioursAttributes;

/**
* @var Classes
*/
Expand Down Expand Up @@ -121,7 +131,6 @@ class Schools extends BootstrapEndpoint
* @var Events
*/
public $events;

/**
* @var Doctors
*/
Expand Down Expand Up @@ -168,6 +177,36 @@ public function __construct($token, $id = false)
$this->subjects = new Subjects($token, $this->uri);
}

public function updateDomain($domain)
{
$this->achievements->domain = $domain;
$this->achievementsAttributes->domain = $domain;
$this->assessment->domain = $domain;
$this->attendance->domain = $domain;
$this->attendanceSummaries->domain = $domain;
$this->behaviours->domain = $domain;
$this->behavioursAttributes->domain = $domain;
$this->classes->domain = $domain;
$this->contacts->domain = $domain;
$this->counts->domain = $domain;
$this->deletions->domain = $domain;
$this->doctors->domain = $domain;
$this->employees->domain = $domain;
$this->employeeAbsences->domain = $domain;
$this->events->domain = $domain;
$this->groups->domain = $domain;
$this->lessons->domain = $domain;
$this->lessonAttendance->domain = $domain;
$this->medicalConditions->domain = $domain;
$this->medicalEvents->domain = $domain;
$this->periods->domain = $domain;
$this->photos->domain = $domain;
$this->rooms->domain = $domain;
$this->students->domain = $domain;
$this->studentsPreAdmission->domain = $domain;
$this->subjects->domain = $domain;
}

/**
* Return all pending schools
*
Expand Down
Loading

0 comments on commit 38e7a38

Please sign in to comment.