-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
533 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.6.2 | ||
1.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.6 | ||
1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8.2.8-r0 | ||
8.2.9-r0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace Feeds\ChurchSuite; | ||
|
||
use Feeds\App; | ||
use Feeds\Config\Config as C; | ||
use Feeds\Helpers\Arr; | ||
use Feeds\Helpers\Hash; | ||
use Feeds\Prayer\Person; | ||
use Feeds\Prayer\Prayer_Calendar; | ||
|
||
App::check(); | ||
|
||
class Api | ||
{ | ||
/** | ||
* ChurchSuite API version. | ||
* | ||
* @var string | ||
*/ | ||
private readonly string $version; | ||
|
||
/** | ||
* Set the version to use for all API requests. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->version = "v1"; | ||
} | ||
|
||
/** | ||
* Make a request to the ChurchSuite API and return the response - logging any errors. | ||
* | ||
* @param string $endpoint ChurchSuite API endpoint. | ||
* @param array $data Request data. | ||
* @return mixed API response. | ||
*/ | ||
private function make_request(string $endpoint, array $data): mixed | ||
{ | ||
// build URL from data | ||
$url = sprintf("https://api.churchsuite.com/%s/%s?%s", $this->version, $endpoint, http_build_query($data)); | ||
|
||
// create curl request | ||
$handle = curl_init($url); | ||
curl_setopt($handle, CURLOPT_HTTPHEADER, array( | ||
sprintf("X-Account: %s", C::$churchsuite->org), | ||
sprintf("X-Application: %s", C::$churchsuite->api_application), | ||
sprintf("X-Auth: %s", C::$churchsuite->api_key) | ||
)); | ||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); | ||
|
||
// make request - on error log and return null | ||
$json = curl_exec($handle); | ||
if (!$json) { | ||
_l(print_r(curl_error($handle), true)); | ||
return null; | ||
} | ||
|
||
// decode JSON response - on error log and return null | ||
$result = json_decode($json, true); | ||
if (!$result) { | ||
_l("Unable to decode JSON response from %s", $url); | ||
return null; | ||
} elseif (isset($result["error"])) { | ||
_l("Error retrieving %s: %s", $url, $result["error"]["message"]); | ||
return null; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Make a request to the ChurchSuite API to get people. | ||
* | ||
* @param string $endpoint API endpoint (e.g. 'addressbook/contacts'). | ||
* @param string $kind The kind of people being requested ('contacts' or 'children'). | ||
* @param bool $are_children Whether or not the people being requested are children. | ||
* @return Person[] Array of Person objects where the key is a unique hash (see Hash::person). | ||
*/ | ||
private function get_people(string $endpoint, string $kind, bool $are_children): array | ||
{ | ||
// make request and return empty array on failure | ||
$response = $this->make_request($endpoint, array($kind => "true")); | ||
if ($response === null) { | ||
return array(); | ||
} | ||
|
||
// build array of People from the response | ||
$people = array(); | ||
foreach ($response[$kind] as $person) { | ||
$thumb_url = Arr::get(Arr::get(Arr::get($person, "images", array()), "md", array()), "url"); | ||
$person = new Person( | ||
first_name: $person["first_name"], | ||
last_name: $person["last_name"], | ||
is_child: $are_children, | ||
image_url: $thumb_url | ||
); | ||
$people[Hash::person($person)] = $person; | ||
} | ||
|
||
// return - the list is returned sorted by ChurchSuite | ||
return $people; | ||
} | ||
|
||
/** | ||
* Get everyone who has consented to being in the Prayer Calendar. | ||
* | ||
* @return Person[] Array of Person objects where the key is a unique hash (see Hash::person). | ||
*/ | ||
public static function get_prayer_calendar_people(): array | ||
{ | ||
// create API object | ||
$api = new Api(); | ||
|
||
// get adults and children with the Prayer Calendar tag | ||
$contacts = $api->get_people(sprintf("addressbook/tag/%s", C::$churchsuite->tag_id_adults), "contacts", false); | ||
$children = $api->get_people(sprintf("children/tag/%s", C::$churchsuite->tag_id_children), "children", true); | ||
|
||
// merge and sort array | ||
$people = array_merge($contacts, $children); | ||
Prayer_Calendar::sort_people($people); | ||
|
||
return $people; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Feeds\Config; | ||
|
||
use Feeds\App; | ||
use Feeds\Helpers\Arr; | ||
|
||
App::check(); | ||
|
||
class Config_ChurchSuite | ||
{ | ||
/** | ||
* Church Suite API application. | ||
* | ||
* @var string | ||
*/ | ||
public readonly string $api_application; | ||
|
||
/** | ||
* Church Suite API key. | ||
* | ||
* @var string | ||
*/ | ||
public readonly string $api_key; | ||
|
||
/** | ||
* Church Suite organisation subdomain (e.g. 'kingshope' for 'kingshope.churchsuite.com'). | ||
* | ||
* @var string | ||
*/ | ||
public readonly string $org; | ||
|
||
/** | ||
* Church Suite Tag ID for adults who have consented to be in the Prayer Calendar. | ||
* | ||
* @var int | ||
*/ | ||
public readonly int $tag_id_adults; | ||
|
||
/** | ||
* Church Suite Tag ID for children whose parents have consented for them to be in the Prayer Calendar. | ||
* | ||
* @var int | ||
*/ | ||
public readonly int $tag_id_children; | ||
|
||
/** | ||
* Get values from general configuration array. | ||
* | ||
* @param array $config General configuration array. | ||
* @return void | ||
*/ | ||
public function __construct(array $config) | ||
{ | ||
$this->api_application = Arr::get($config, "api_application", ""); | ||
$this->api_key = Arr::get($config, "api_key", ""); | ||
$this->org = Arr::get($config, "org", ""); | ||
$this->tag_id_adults = Arr::get_integer($config, "tag_id_adults", 0); | ||
$this->tag_id_children = Arr::get_integer($config, "tag_id_children", 0); | ||
} | ||
} |
Oops, something went wrong.