Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/join-block/src/Services/ActionNetworkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public static function signup($data)
];
}

$joinBlockLog->info("Action Network payload for {$data['email']}: " . json_encode($anData));

try {
$client = new Client();
$client->request(
Expand All @@ -113,8 +115,36 @@ public static function signup($data)
}
}

public static function personExists($email)
{
$client = new Client();

$response = $client->request(
"GET",
"https://actionnetwork.org/api/v2/people/",
[
"headers" => [
"OSDI-API-Token" => Settings::get("ACTION_NETWORK_API_KEY")
],
"query" => [
"filter" => "email_address eq '" . $email . "'"
]
]
Comment on lines +128 to +132
);

$data = json_decode($response->getBody()->getContents(), true);
return !empty($data["_embedded"]["osdi:people"]);
}
Comment on lines +118 to +137

public static function addTag($email, $tag)
{
global $joinBlockLog;

if (!self::personExists($email)) {
$joinBlockLog->warning("Skipping Action Network addTag('$tag') for $email: person does not exist");
return;
}

$client = new Client();

$data = [
Expand Down Expand Up @@ -143,6 +173,13 @@ public static function addTag($email, $tag)

public static function removeTag($email, $tag)
{
global $joinBlockLog;

if (!self::personExists($email)) {
$joinBlockLog->warning("Skipping Action Network removeTag('$tag') for $email: person does not exist");
return;
}

$client = new Client();

$data = [
Expand Down
10 changes: 10 additions & 0 deletions packages/join-block/src/Services/MailchimpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public static function addTag($email, $tag)
{
global $joinBlockLog;

if (!self::memberExists($email)) {
$joinBlockLog->warning("Skipping Mailchimp addTag('$tag') for $email: member does not exist");
return;
}
Comment on lines +255 to +258

$mailchimp = self::getClient();
$mailchimp_audience_id = Settings::get("MAILCHIMP_AUDIENCE_ID");

Expand All @@ -274,6 +279,11 @@ public static function removeTag($email, $tag)
{
global $joinBlockLog;

if (!self::memberExists($email)) {
$joinBlockLog->warning("Skipping Mailchimp removeTag('$tag') for $email: member does not exist");
return;
}

$mailchimp = self::getClient();
$mailchimp_audience_id = Settings::get("MAILCHIMP_AUDIENCE_ID");

Expand Down
Loading