Skip to content

Commit

Permalink
Merge pull request #14 from jacob-v-dam/upgrade-to-php80
Browse files Browse the repository at this point in the history
PHP 8.0 upgrade
  • Loading branch information
jeroendesloovere authored Mar 16, 2023
2 parents 3dc8e13 + 387f49b commit 17e9c50
Show file tree
Hide file tree
Showing 6 changed files with 2,345 additions and 548 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 5.7
- 7.4
- 8.0
- hhvm

sudo: false
Expand Down
61 changes: 20 additions & 41 deletions Gateway/MailChimpSubscriberGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace MailMotor\Bundle\MailChimpBundle\Gateway;

use GuzzleHttp\RequestOptions;
use Illuminate\Support\Collection;
use Mailchimp\Mailchimp;
use MailchimpMarketing\ApiClient;
use MailMotor\Bundle\MailMotorBundle\Gateway\SubscriberGateway;

/**
Expand All @@ -17,13 +15,17 @@ class MailChimpSubscriberGateway implements SubscriberGateway
/**
* The external MailChimp API
*
* @var Mailchimp
* @var ApiClient
*/
protected $api;

public function __construct(Mailchimp $api)
public function __construct(string $apiKey)
{
$this->api = $api;
$this->api = new ApiClient();

$this->api->setConfig([
'apiKey' => $apiKey,
]);
}

public function exists(string $email, string $listId): bool
Expand Down Expand Up @@ -51,15 +53,7 @@ public function exists(string $email, string $listId): bool
private function get(string $email, string $listId): array
{
try {
/** @var Collection $result */
$result = $this->api->request(
'lists/' . $listId . '/members/' . $this->getHashedEmail($email),
array(),
'get'
);

// will return the one and only member array('id', ...) from Collection
return $result->all();
return $this->api->lists->getListMember($listId, $this->getHashedEmail($email));
} catch (\Exception $e) {
return [];
}
Expand All @@ -68,12 +62,7 @@ private function get(string $email, string $listId): array
public function getInterests(string $listId): array
{
try {
/** @var Collection $result */
$interestCategories = $this->api->request(
'lists/' . $listId . '/interest-categories',
array(RequestOptions::TIMEOUT => 5),
'get'
);
$interestCategories = $this->api->lists->getListInterestCategories($listId);

// Init $interests
$interests = array();
Expand Down Expand Up @@ -111,15 +100,7 @@ public function getInterests(string $listId): array
protected function getInterestsForCategoryId(string $interestCategoryId, string $listId): array
{
try {
/** @var Collection $result */
$result = $this->api->request(
'lists/' . $listId . '/interest-categories/' . $interestCategoryId . '/interests',
array(),
'get'
);

// will return the one and only member array('id', ...) from Collection
return $result->all();
return $this->api->lists->getInterestCategory($listId, $interestCategoryId);
} catch (\Exception $e) {
return [];
}
Expand All @@ -144,7 +125,9 @@ public function hasStatus(string $email, string $listId, string $status): bool
public function ping(string $listId): bool
{
try {
return $this->api->get('/lists/' . $listId) instanceof Collection;
$this->api->lists->getList($listId);

return true;
} catch (\Exception $e) {
return false;
}
Expand Down Expand Up @@ -209,23 +192,19 @@ public function subscribe(
$parameters['interests'] = $interestsObject;
}

$this->api->request(
'lists/' . $listId . '/members/' . $this->getHashedEmail($email),
$parameters,
'put'
);
$this->api->lists->setListMember($listId, $this->getHashedEmail($email), $parameters);

return true;
}

public function unsubscribe(string $email, string $listId): bool
{
$this->api->request(
'lists/' . $listId . '/members/' . $this->getHashedEmail($email),
$this->api->lists->updateListMember(
$listId,
$this->getHashedEmail($email),
array(
'status' => 'unsubscribed',
),
'patch'
'status' => 'unsubscribed',
)
);

return true;
Expand Down
8 changes: 1 addition & 7 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ services:
mailmotor.mailchimp.subscriber.gateway:
class: MailMotor\Bundle\MailChimpBundle\Gateway\MailChimpSubscriberGateway
arguments:
- "@mailmotor.mailchimp.api"
- "%mailmotor.api_key%"
tags:
- { name: mailmotor.subscriber_gateway, alias: mailchimp }

# the external mailchimp api that we are using
mailmotor.mailchimp.api:
class: Mailchimp\Mailchimp
arguments:
- "%mailmotor.api_key%"
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
}
],
"require": {
"php": "^7.1",
"pacely/mailchimp-apiv3": "~1.0",
"mailmotor/mailmotor-bundle": "^3.0"
"php": "^7.4||^8.0",
"mailmotor/mailmotor-bundle" : "^4.0",
"mailchimp/marketing": "^3.0"
},
"autoload": {
"psr-4": { "MailMotor\\Bundle\\MailChimpBundle\\": "" }
},
"require-dev": {
"phpunit/phpunit": "^9.6"
}
}
Loading

0 comments on commit 17e9c50

Please sign in to comment.