├── lib
├── .redaxo
├── rapidmail
│ ├── examples
│ │ ├── example-06-import-blacklist-data.csv
│ │ ├── example-05-import-recipient-data.csv
│ │ ├── example-01-client-initialization.php
│ │ ├── example-02-fetch-mailings.php
│ │ ├── example-03-fetch-recipients.php
│ │ ├── example-04-create-recipient.php
│ │ ├── example-06-import-blacklist.php
│ │ └── example-05-import-recipients.php
│ ├── src
│ │ ├── Exception
│ │ │ ├── ApiClientException.php
│ │ │ ├── NotImplementedException.php
│ │ │ ├── InvalidArgumentException.php
│ │ │ ├── IncompatiblePlatformException.php
│ │ │ └── ApiException.php
│ │ ├── Service
│ │ │ ├── Response
│ │ │ │ ├── ResponseInterface.php
│ │ │ │ ├── ResponseFactory.php
│ │ │ │ ├── HalResponsePaginationIterator.php
│ │ │ │ ├── HalResponseResourceIterator.php
│ │ │ │ └── HalResponse.php
│ │ │ ├── ServiceInterface.php
│ │ │ ├── Parameter
│ │ │ │ ├── ParameterInterface.php
│ │ │ │ ├── FileAttr.php
│ │ │ │ └── GenericParameter.php
│ │ │ ├── ServiceFactoryInterface.php
│ │ │ ├── V1
│ │ │ │ └── Api
│ │ │ │ │ ├── Blacklist
│ │ │ │ │ └── Blacklist
│ │ │ │ │ │ ├── Parameter
│ │ │ │ │ │ ├── BlacklistImportParamFileAttr.php
│ │ │ │ │ │ ├── BlacklistCreateParam.php
│ │ │ │ │ │ ├── BlacklistQueryParam.php
│ │ │ │ │ │ ├── ParameterFactory.php
│ │ │ │ │ │ └── BlacklistImportParam.php
│ │ │ │ │ │ ├── BlacklistServiceFactory.php
│ │ │ │ │ │ └── BlacklistService.php
│ │ │ │ │ ├── Mailings
│ │ │ │ │ ├── Mailing
│ │ │ │ │ │ ├── Parameter
│ │ │ │ │ │ │ ├── MailingCreateParamFileAttr.php
│ │ │ │ │ │ │ ├── ParameterFactory.php
│ │ │ │ │ │ │ ├── MailingQueryParam.php
│ │ │ │ │ │ │ ├── MailingCreateParamDestinationAttr.php
│ │ │ │ │ │ │ └── MailingCreateParam.php
│ │ │ │ │ │ ├── MailingServiceFactory.php
│ │ │ │ │ │ └── MailingService.php
│ │ │ │ │ ├── MailingStats
│ │ │ │ │ │ ├── MailingStatsServiceFactory.php
│ │ │ │ │ │ └── MailingStatsService.php
│ │ │ │ │ ├── MailingRecipients
│ │ │ │ │ │ ├── MailingRecipientsServiceFactory.php
│ │ │ │ │ │ └── MailingRecipientsService.php
│ │ │ │ │ └── MailingStatsAnonymize
│ │ │ │ │ │ ├── MailingStatsAnonymizeServiceFactory.php
│ │ │ │ │ │ └── MailingStatsAnonymizeService.php
│ │ │ │ │ ├── TrxEmails
│ │ │ │ │ └── TrxEmail
│ │ │ │ │ │ ├── Parameter
│ │ │ │ │ │ ├── ParameterFactory.php
│ │ │ │ │ │ └── TrxEmailQueryParam.php
│ │ │ │ │ │ ├── TrxEmailsServiceFactory.php
│ │ │ │ │ │ └── TrxEmailService.php
│ │ │ │ │ ├── Recipients
│ │ │ │ │ └── Recipient
│ │ │ │ │ │ ├── Parameter
│ │ │ │ │ │ ├── RecipientImportParamFileAttr.php
│ │ │ │ │ │ ├── RecipientDeleteQueryParam.php
│ │ │ │ │ │ ├── RecipientCreateQueryParam.php
│ │ │ │ │ │ ├── ParameterFactory.php
│ │ │ │ │ │ ├── RecipientImportParam.php
│ │ │ │ │ │ ├── RecipientImportQueryParam.php
│ │ │ │ │ │ ├── RecipientQueryParam.php
│ │ │ │ │ │ └── RecipientCreateParam.php
│ │ │ │ │ │ ├── RecipientServiceFactory.php
│ │ │ │ │ │ └── RecipientService.php
│ │ │ │ │ ├── Jobs
│ │ │ │ │ └── Job
│ │ │ │ │ │ ├── JobServiceFactory.php
│ │ │ │ │ │ └── JobService.php
│ │ │ │ │ ├── ApiUsers
│ │ │ │ │ └── ApiUser
│ │ │ │ │ │ ├── Parameter
│ │ │ │ │ │ ├── ParameterFactory.php
│ │ │ │ │ │ ├── ApiUserQueryParam.php
│ │ │ │ │ │ └── ApiUserCreateParam.php
│ │ │ │ │ │ ├── ApiUserServiceFactory.php
│ │ │ │ │ │ └── ApiUserService.php
│ │ │ │ │ └── Recipientlists
│ │ │ │ │ └── Recipientlist
│ │ │ │ │ ├── RecipientlistServiceFactory.php
│ │ │ │ │ ├── Parameter
│ │ │ │ │ ├── ParameterFactory.php
│ │ │ │ │ ├── RecipientlistActivityStatsParam.php
│ │ │ │ │ └── RecipientlistCreateParam.php
│ │ │ │ │ └── RecipientlistService.php
│ │ │ ├── AbstractService.php
│ │ │ └── ServiceFactory.php
│ │ ├── Http
│ │ │ ├── HttpClientInterface.php
│ │ │ ├── HttpClientFacade.php
│ │ │ ├── HttpClientFactory.php
│ │ │ └── ThrottleMiddleware.php
│ │ ├── Util
│ │ │ ├── PlatformRequirements.php
│ │ │ └── CallbackIterator.php
│ │ ├── Config
│ │ │ └── services.php
│ │ └── Client.php
│ ├── docs
│ │ ├── jobs-services.md
│ │ ├── transaction-emails-services.md
│ │ ├── typed-parameters.md
│ │ ├── api-users-services.md
│ │ ├── blacklist-services.md
│ │ ├── available-services.md
│ │ ├── recipientlists-services.md
│ │ ├── mailing-services.md
│ │ └── recipients-services.md
│ ├── LICENSE
│ ├── CHANGELOG.md
│ └── README.md
└── yform
│ └── action
│ └── yform_rapidmail.php
├── pages
├── index.php
├── yform.rapidmail.docs.php
└── yform.rapidmail.settings.php
├── boot.php
├── .DS_Store
├── .github
├── FUNDING.yml
└── workflows
│ ├── publish-to-redaxo-org.yml
│ └── code-style.yml
├── package.yml
├── LICENSE
├── lang
└── de_de.lang
└── README.md
/lib/.redaxo:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pages/index.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/boot.php:
--------------------------------------------------------------------------------
1 | jobs();
10 | ```
11 |
12 | ### Available methods
13 | #### Get details about a specific job
14 | ```php
15 | $response = $service->get(/* JOB ID */);
16 | ```
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/Mailing/Parameter/MailingCreateParamFileAttr.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('page', $page);
31 |
32 | return $this;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/MailingStatsAnonymize/MailingStatsAnonymizeServiceFactory.php:
--------------------------------------------------------------------------------
1 | transactionEmails();
10 | ```
11 |
12 | ### Available methods
13 | #### Get list of transaction emails
14 | See [GET call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Transaction%20Emails#/TrxEmails/get_trx_emails) on how to setup OPTIONAL FILTER
15 | ```php
16 | $collection = $service->query(/* OPTIONAL FILTER */);
17 | ```
18 | #### Get info about a single transaction email
19 | ```php
20 | $response = $service->get(/* MAILHASH */);
21 | ```
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/Mailing/MailingServiceFactory.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('track_unsubscription', $this->convertBool($flag));
29 |
30 | return $this;
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipientlists/Recipientlist/Parameter/ParameterFactory.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('pattern', $pattern);
33 |
34 | return $this;
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/.github/workflows/publish-to-redaxo-org.yml:
--------------------------------------------------------------------------------
1 | # Instructions: https://github.com/FriendsOfREDAXO/installer-action/
2 |
3 | name: Publish to REDAXO.org
4 | on:
5 | release:
6 | types:
7 | - published
8 |
9 | jobs:
10 | redaxo_publish:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | - if: hashFiles('composer.json') != ''
15 | uses: shivammathur/setup-php@v2
16 | with:
17 | php-version: "8.2"
18 | - if: hashFiles('composer.json') != ''
19 | uses: ramsey/composer-install@v2
20 | with:
21 | composer-options: "--no-dev"
22 | - uses: FriendsOfREDAXO/installer-action@v1
23 | with:
24 | myredaxo-username: ${{ secrets.MYREDAXO_USERNAME }}
25 | myredaxo-api-key: ${{ secrets.MYREDAXO_API_KEY }}
26 | description: ${{ github.event.release.body }}
27 | version: ${{ github.event.release.tag_name }}
28 |
--------------------------------------------------------------------------------
/lib/rapidmail/examples/example-01-client-initialization.php:
--------------------------------------------------------------------------------
1 | getMessage()
30 | );
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Http/HttpClientFacade.php:
--------------------------------------------------------------------------------
1 | client = $client;
25 | }
26 |
27 | /**
28 | * @inheritDoc
29 | */
30 | public function request($method, $uri, array $options = [])
31 | {
32 |
33 | try {
34 | return $this->client->request($method, $uri, $options);
35 | } catch (GuzzleException $e) {
36 | throw ApiException::fromGuzzleException($e);
37 | }
38 |
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/lib/rapidmail/examples/example-02-fetch-mailings.php:
--------------------------------------------------------------------------------
1 | mailings();
10 |
11 | // Configure an optional filter for those mailings with status "sent"
12 |
13 | $filter = [
14 | 'status' => 'sent'
15 | ];
16 |
17 | // Iterate all mailings with status filter applied
18 |
19 | try {
20 |
21 | foreach ($mailingService->query($filter) as $mailing) {
22 | echo "Mailing '{$mailing['subject']}' (id {$mailing['id']}) sent at {$mailing['sent']}" . PHP_EOL;
23 | }
24 |
25 | } catch (ApiClientException $e) {
26 |
27 | // @TODO: Implement your own error handling
28 |
29 | if ($e->getCode() == 401) {
30 | die('Unauthorized access. Check if username and password are correct');
31 | }
32 |
33 | die('An API exception occurred: ' . $e->getMessage());
34 |
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Jobs/Job/JobService.php:
--------------------------------------------------------------------------------
1 | responseFactory
35 | ->newHalResponse(
36 | $this->client,
37 | $this->_get($jobId)
38 | );
39 |
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Blacklist/Blacklist/Parameter/BlacklistQueryParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('page', $page);
27 |
28 | return $this;
29 | }
30 |
31 | /**
32 | * Filter pattern types (email/domain/regex) by pattern
33 | *
34 | * @param string $pattern
35 | * @return static
36 | */
37 | public function setPattern($pattern)
38 | {
39 | $this->setAttributeRaw('pattern', $pattern);
40 |
41 | return $this;
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/lib/rapidmail/docs/typed-parameters.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | ## Typed parameters
4 |
5 | Typed parameters are an alternative way of passing in parameters into service methods instead of using the array notation.
6 |
7 | Therefore most of the services provide a `params()` method that will return a factory to build parameters. That way you can make use of the auto completion features within your IDE and easily access documentation of the available attributes.
8 |
9 | ## Example
10 |
11 | ```php
12 | // Typed parameter notation
13 |
14 | $response = $service->query(
15 | $service
16 | ->params()
17 | ->newQueryParam()
18 | ->setSortOrder('desc')
19 | // Use setAttribute($attrName, $attrValue) for arbitrary undocumented values
20 | ->setAttribute('sort_by' 'updated')
21 | );
22 |
23 | // The same result achieved using array notation
24 |
25 | $response = $service->query([
26 | 'sort_order' => 'desc',
27 | 'sort_by' => 'updated'
28 | ]);
29 | ````
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/MailingStats/MailingStatsService.php:
--------------------------------------------------------------------------------
1 | client->request(
34 | 'GET',
35 | "{$this->getResourcePath()}/{$mailingId}/stats"
36 |
37 | );
38 |
39 | return $this->responseFactory->newHalResponse($this->client, $response);
40 |
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Friends Of REDAXO
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/lib/rapidmail/docs/api-users-services.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | ## Service
4 |
5 | API Service to manage API users
6 |
7 | ### Retrieve a service instance
8 | ```php
9 | $service = $client->apiUsers();
10 | ```
11 |
12 | ### Available methods
13 |
14 | #### Get details about an API user
15 | ```php
16 | $response = $service->get(/* API USER ID */);
17 | ```
18 | #### Delete a single API user
19 | ```php
20 | $collection = $service->delete(/* API USER ID */);
21 | ```
22 | #### Get a list of API users
23 | ```php
24 | $collection = $service->query();
25 | ```
26 | #### Create a new API user
27 | See [POST call documentation](https://developer.rapidmail.wiki/documentation.html#/ApiUsers/post_apiusers) on how to setup PAYLOAD
28 | ```php
29 | $response = $service->create(/* PAYLOAD */);
30 | ```
31 | #### Partially update an API user
32 | See [PATCH call documentation](https://developer.rapidmail.wiki/documentation.html#/ApiUsers/patch_apiusers__apiuser_id_) on how to setup PAYLOAD
33 | ```php
34 | $response = $service->update(/* API USER ID */, /* PAYLOAD */);
35 | ```
--------------------------------------------------------------------------------
/lib/rapidmail/examples/example-03-fetch-recipients.php:
--------------------------------------------------------------------------------
1 | recipients();
10 |
11 | // Configure a required filter to fetch recipients for a certain recipientlist id
12 | // Note that if no "status" filter is provided only "active" recipients will be returned
13 |
14 | $filter = [
15 | 'recipientlist_id' => 9876543210 // Enter your own recipientlist id
16 | ];
17 |
18 | // Iterate all recipients with recipientlist id filter applied
19 |
20 | try {
21 |
22 | foreach ($recipientService->query($filter) as $recipient) {
23 | echo "Recipient '{$recipient['email']}' (id {$recipient['id']}) in status '{$recipient['status']}'" . PHP_EOL;
24 | }
25 |
26 | } catch (ApiClientException $e) {
27 |
28 | // @TODO: Implement your own error handling
29 |
30 | if ($e->getCode() == 401) {
31 | die('Unauthorized access. Check if username and password are correct');
32 | }
33 |
34 | die('An API exception occurred: ' . $e->getMessage());
35 |
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipientlists/Recipientlist/Parameter/RecipientlistActivityStatsParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('from', $this->stringifyDateTime($from, 'Y-m-d'));
31 | return $this;
32 | }
33 |
34 | /**
35 | * Sets the to date
36 | *
37 | * @param string|\DateTimeInterface $to
38 | * @return static
39 | */
40 | public function setTo($to)
41 | {
42 | $this->setAttributeRaw('to', $this->stringifyDateTime($to, 'Y-m-d'));
43 | return $this;
44 | }
45 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/MailingStatsAnonymize/MailingStatsAnonymizeService.php:
--------------------------------------------------------------------------------
1 | client
35 | ->request(
36 | 'PUT',
37 | "{$this->getResourcePath()}/{$mailingId}/stats/anonymize"
38 | )
39 | ->getStatusCode() == 200;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/lang/de_de.lang:
--------------------------------------------------------------------------------
1 | yform_rapidmail = Rapidmail für REDAXO YForm
2 | yform_rapidmail_config = Einstellungen
3 |
4 | yform_rapidmail_api_user = API-Benutzer
5 | yform_rapidmail_hash = Passwort-Hash
6 |
7 | yform_rapidmail_list = Empfängerliste(n)
8 | yform_rapidmail_list_link = Link zur Liste
9 |
10 | yform_rapidmail_info_donate = Anders als die meisten Addons aus der REDAXO-Community ist die Entstehung und Weiterentwicklung dieses Addons nicht durch eigene Projekte gedeckt. Mit einer Spende oder einer Beauftragung sicherst du zusätzliche Features, die Stabilität, Funktionsumfang und Weiterentwicklung weiter verbessern können, sowie eine bessere Anleitung.
11 | yform_rapidmail_donate = Weiterentwicklung unterstützen
12 |
13 | yform_rapidmail_DME = Dokumentation
14 | yform_rapidmail_-users-services = API Users Service
15 | yform_rapidmail_ilable-services = Available Services
16 | yform_rapidmail_cklist-services = Blacklist Service
17 | yform_rapidmail_s-services = Jobs Service
18 | yform_rapidmail_ling-services = Mailing Service
19 | yform_rapidmail_ipientlists-services = Recipients Lists Service
20 | yform_rapidmail_ipients-services = Recipients Service
21 | yform_rapidmail_nsaction-emails-services = Transactional Emails Service
22 | yform_rapidmail_ed-parameters = Typed Parameters
23 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Util/PlatformRequirements.php:
--------------------------------------------------------------------------------
1 | =")) {
34 |
35 | throw new IncompatiblePlatformException(
36 | "Minimum version of PHP required is {$version}"
37 | );
38 |
39 | }
40 |
41 | foreach (static::REQUIRED_EXTENSIONS as $extension) {
42 |
43 | if (!extension_loaded($extension)) {
44 |
45 | throw new IncompatiblePlatformException(
46 | "Required PHP extension {$extension} is not loaded"
47 | );
48 |
49 | }
50 |
51 | }
52 |
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/lib/rapidmail/docs/blacklist-services.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | ## Blacklist Service
4 |
5 | API service to manage blacklist entries
6 |
7 | ### Examples
8 |
9 | * [Import blacklist data](/examples/example-06-import-blacklist.php)
10 |
11 | ### Retrieve a service instance
12 | ```php
13 | $service = $client->blacklist();
14 | ```
15 |
16 | ### Available methods
17 |
18 | #### Get info about a single blacklist entry
19 | ```php
20 | $response = $service->get(/* BLACKLIST ID */);
21 | ```
22 | #### Delete blacklist entry by ID
23 | ```php
24 | $response = $service->delete(/* BLACKLIST ID */);
25 | ```
26 | #### Get list of blacklist entries
27 | See [GET call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Blacklist#/Blacklist/get_blacklist) on how to setup OPTIONAL FILTER
28 | ```php
29 | $collection = $service->query(/* OPTIONAL FILTER */);
30 | ```
31 | #### Create a new blacklist entry
32 | See [POST call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Blacklist#/Blacklist/post_blacklist) on how to setup PAYLOAD
33 | ```php
34 | $response = $service->create(/* PAYLOAD */);
35 | ```
36 | #### Import blacklist from CSV file
37 | ```php
38 | $response = $service->import(/* FILE */);
39 | ```
--------------------------------------------------------------------------------
/lib/rapidmail/examples/example-04-create-recipient.php:
--------------------------------------------------------------------------------
1 | recipients();
10 |
11 | // Set up a recipient data to be inserted. "email" and "recipientlist_id" are both required
12 |
13 | $payload = [
14 | 'email' => 'info@example.net', // Enter your own recipient address
15 | 'recipientlist_id' => 9876543210 // Enter your own recipientlist id
16 | ];
17 |
18 | // Optional modifier that changes recipient creation behavior
19 |
20 | $modifier = [
21 | 'send_activationmail' => 'no' // Set to 'yes' if you want to sent an activation email to your recipient, Warning: activation emails are _never_ sent for demo accounts.
22 | ];
23 |
24 | // Create a recipient
25 |
26 | try {
27 |
28 | $recipient = $recipientService->create($payload, $modifier);
29 | echo "Created recipient '{$recipient['email']}' (id {$recipient['id']})" . PHP_EOL;
30 |
31 | } catch (ApiClientException $e) {
32 |
33 | // @TODO: Implement your own error handling
34 |
35 | if ($e->getCode() == 401) {
36 | die('Unauthorized access. Check if username and password are correct');
37 | }
38 |
39 | die('An API exception occurred: ' . $e->getMessage());
40 |
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/.github/workflows/code-style.yml:
--------------------------------------------------------------------------------
1 | name: PHP-CS-Fixer
2 |
3 | on:
4 | push:
5 | branches: [ master, main ]
6 | pull_request:
7 | branches: [ master, main ]
8 |
9 | permissions:
10 | contents: read
11 |
12 | jobs:
13 | code-style:
14 |
15 | runs-on: ubuntu-latest
16 | permissions:
17 | contents: write # for Git to git apply
18 |
19 | steps:
20 | - uses: actions/checkout@v3
21 |
22 | - name: Setup PHP
23 | uses: shivammathur/setup-php@v2
24 | with:
25 | php-version: '8.1'
26 | extensions: gd, intl, pdo_mysql
27 | coverage: none # disable xdebug, pcov
28 |
29 | # install dependencies from composer.json
30 | - name: Install test dependencies
31 | env:
32 | COMPOSER: composer.json
33 | run: composer install --prefer-dist --no-progress
34 |
35 | # run php-cs-fixer, fix code styles
36 | - name: Run PHP CS Fixer
37 | run: composer cs-fix
38 |
39 | # commit and push fixed files
40 | - uses: stefanzweifel/git-auto-commit-action@v4
41 | with:
42 | commit_message: Apply php-cs-fixer changes
43 | push_options: --force
44 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Exception/ApiException.php:
--------------------------------------------------------------------------------
1 | getMessage();
22 |
23 | if (method_exists($e, 'hasResponse') && method_exists($e, 'getResponse')) {
24 |
25 | if ($e->hasResponse()) {
26 |
27 | $uri = '';
28 |
29 | if (method_exists($e, 'getRequest')) {
30 | /** @var RequestInterface $request */
31 | $request = $e->getRequest();
32 | $uri = $request->getUri();
33 | }
34 |
35 | /** @var ResponseInterface $response */
36 | $response = $e->getResponse();
37 |
38 | $message = "API error {$e->getCode()} when requesting {$uri}. Detail: {$response->getBody()}";
39 |
40 | }
41 |
42 | }
43 |
44 | return new static($message, $e->getCode());
45 |
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Blacklist/Blacklist/Parameter/ParameterFactory.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('description', $description);
30 |
31 | return $this;
32 | }
33 |
34 | /**
35 | * Authentication type used for API user
36 | *
37 | * Please note that setting authentication_type to “key” will currently only result
38 | * in a usable user if a default authentication key has been configured for the whitelabel.
39 | *
40 | * @param string $authenticationType Available: password, key
41 | * @return static
42 | */
43 | public function setAuthenticationType($authenticationType)
44 | {
45 | $this->setAttributeRaw('authentication_type', $authenticationType);
46 |
47 | return $this;
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/lib/rapidmail/docs/available-services.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | The API client was designed to access all rapidmail APIs in a simple and homogenous way. Each service can be accessed with only a few lines of code. Here you will find information about how to access the various APIs and services.
4 |
5 | ## Available Services
6 |
7 | Follow the links to receive an in-depth documentation about the available services and their callable methods:
8 |
9 | * [API users](/docs/api-users-services.md)
10 | * [Blacklist](/docs/blacklist-services.md)
11 | * [Jobs](/docs/jobs-services.md)
12 | * [Mailings](/docs/mailing-services.md)
13 | * [Recipient lists](/docs/recipientlists-services.md)
14 | * [Recipients](/docs/recipients-services.md)
15 | * [Transaction emails](/docs/transaction-emails-services.md)
16 |
17 | ## Request design
18 |
19 | We target for a concise and consistent wording within service methods which is described as follows:
20 |
21 | * get($id) Will receive a single entity by a given ID
22 | * delete($id) Will delete single entity by a given ID
23 | * query($filter = []) Will receive a collection (optionally filtered)
24 | * create($payload = []) Will create a single entity
25 | * update($id, $payload = []) Will update a single entity by a given ID
26 |
27 | Refer to the section above to to see which methods exist within a service context.
28 |
--------------------------------------------------------------------------------
/lib/rapidmail/examples/example-06-import-blacklist.php:
--------------------------------------------------------------------------------
1 | blacklist();
10 |
11 | // Create a job service instance to poll for job status later on
12 |
13 | $jobService = $client->jobs();
14 |
15 | try {
16 |
17 | // Blacklist import is an asynchronous operation. Poll the resulting job info until the job finished
18 |
19 | $jobInfo = $blacklistService->import(__DIR__ . '/example-06-import-blacklist-data.csv');
20 |
21 | $retries = 12;
22 |
23 | do {
24 |
25 | echo "Sleeping 5 seconds before asking job (id {$jobInfo['id']}) having status '{$jobInfo['status']}' to complete" . PHP_EOL;
26 |
27 | sleep(5);
28 |
29 | $jobInfo = $jobService->get($jobInfo['id']);
30 |
31 | if (!in_array($jobInfo['status'], ['new', 'running'])) {
32 | break;
33 | }
34 |
35 | } while (--$retries > 0);
36 |
37 | echo "Import job completed having status '{$jobInfo['status']}'" . PHP_EOL;
38 |
39 | } catch (ApiClientException $e) {
40 |
41 | // @TODO: Implement your own error handling
42 |
43 | if ($e->getCode() == 401) {
44 | die('Unauthorized access. Check if username and password are correct');
45 | }
46 |
47 | die('An API exception occurred: ' . $e->getMessage());
48 |
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Util/CallbackIterator.php:
--------------------------------------------------------------------------------
1 | iterator = $iterator;
27 | $this->callback = $callback;
28 | }
29 |
30 | /**
31 | * @inheritDoc
32 | */
33 | #[\ReturnTypeWillChange]
34 | public function current()
35 | {
36 |
37 | return $this->callback->__invoke(
38 | $this->iterator->current()
39 | );
40 |
41 | }
42 |
43 | /**
44 | * @inheritDoc
45 | */
46 | #[\ReturnTypeWillChange]
47 | public function next()
48 | {
49 | $this->iterator->next();
50 | }
51 |
52 | /**
53 | * @inheritDoc
54 | */
55 | #[\ReturnTypeWillChange]
56 | public function key()
57 | {
58 | return $this->iterator->key();
59 | }
60 |
61 | /**
62 | * @inheritDoc
63 | */
64 | #[\ReturnTypeWillChange]
65 | public function valid()
66 | {
67 | return $this->iterator->valid();
68 | }
69 |
70 | /**
71 | * @inheritDoc
72 | */
73 | #[\ReturnTypeWillChange]
74 | public function rewind()
75 | {
76 | $this->iterator->rewind();
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/lib/rapidmail/examples/example-05-import-recipients.php:
--------------------------------------------------------------------------------
1 | recipients();
10 |
11 | // Create a job service instance to poll for job status later on
12 |
13 | $jobService = $client->jobs();
14 |
15 | // Set up recipient data to be imported
16 |
17 | $payload = [
18 | 'file' => __DIR__ . '/example-05-import-recipient-data.csv', // Let this point to your own recipients data file
19 | 'recipientlist_id' => 9876543210 // Enter your own recipientlist id
20 | ];
21 |
22 | try {
23 |
24 | // Recipient import is an asynchronous operation. Poll the resulting job info until the job finished
25 |
26 | $jobInfo = $recipientService->import($payload);
27 |
28 | $retries = 12;
29 |
30 | do {
31 |
32 | echo "Sleeping 5 seconds before asking job (id {$jobInfo['id']}) having status '{$jobInfo['status']}' to complete" . PHP_EOL;
33 |
34 | sleep(5);
35 |
36 | $jobInfo = $jobService->get($jobInfo['id']);
37 |
38 | if (!in_array($jobInfo['status'], ['new', 'running'])) {
39 | break;
40 | }
41 |
42 | } while (--$retries > 0);
43 |
44 | echo "Import job completed having status '{$jobInfo['status']}'" . PHP_EOL;
45 |
46 | } catch (ApiClientException $e) {
47 |
48 | // @TODO: Implement your own error handling
49 |
50 | if ($e->getCode() == 401) {
51 | die('Unauthorized access. Check if username and password are correct');
52 | }
53 |
54 | die('An API exception occurred: ' . $e->getMessage());
55 |
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Http/HttpClientFactory.php:
--------------------------------------------------------------------------------
1 | push(
23 | ThrottleMiddleware::getInstance(
24 | $config['throttle_interval'],
25 | $config['throttle_requests_per_interval']
26 | ), 'throttle'
27 | );
28 |
29 | $clientConfig = array_replace_recursive(
30 | $config,
31 | [
32 | 'base_uri' => rtrim($config['base_uri'], '/') . '/' . $config['version'] . '/',
33 | 'handler' => $stack,
34 | RequestOptions::HEADERS => [
35 | 'Accept' => 'application/json',
36 | 'User-Agent' => $this->buildUserAgentString()
37 | ]
38 | ]
39 | );
40 | unset($clientConfig['version']);
41 |
42 | return new HttpClientFacade(
43 | new Client($clientConfig)
44 | );
45 |
46 | }
47 |
48 | /**
49 | * @return string
50 | */
51 | private function buildUserAgentString()
52 | {
53 |
54 | return sprintf(
55 | 'rapidmail-apiv3-client-php/%s (%s)',
56 | \Rapidmail\ApiClient\Client::VERSION,
57 | PHP_VERSION
58 | );
59 |
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipients/Recipient/Parameter/RecipientCreateQueryParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('track_stats', $this->convertBool($flag));
33 |
34 | return $this;
35 | }
36 |
37 | /**
38 | * Sets if an activationmail will be sent
39 | *
40 | * Note that this applies only for recipients with status “new” and is ignored for all other recipient statuses.
41 | * Activation mails are never sent for demo accounts.
42 | *
43 | * @param mixed $flag
44 | * @return static
45 | */
46 | public function setSendActivationmail($flag)
47 | {
48 | $this->setAttributeRaw('send_activationmail', $this->convertBool($flag));
49 |
50 | return $this;
51 | }
52 |
53 | /**
54 | * If specified, extrabig fields will be returned for each recipient
55 | *
56 | * @param mixed $flag
57 | * @return static
58 | */
59 | public function setGetExtraBigFields($flag)
60 | {
61 |
62 | $this->setAttributeRaw('get_extra_big_fields', $this->convertBool($flag));
63 |
64 | return $this;
65 |
66 | }
67 |
68 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/Mailing/Parameter/ParameterFactory.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('content', $content);
49 |
50 | return $this;
51 |
52 | }
53 |
54 | /**
55 | * Sets the associated content type
56 | *
57 | * @param string $type
58 | * @return static
59 | */
60 | public function setType($type)
61 | {
62 |
63 | if (!in_array($type, static::ALLOWED_MIME_TYPES)) {
64 | throw new InvalidArgumentException(
65 | 'Invalid mime type for file content. Must be one of: ' . implode(', ', static::ALLOWED_MIME_TYPES)
66 | );
67 | }
68 |
69 | $this->setAttributeRaw('type', $type);
70 |
71 | return $this;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/lib/rapidmail/docs/recipientlists-services.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | ## Recipientlists Service
4 |
5 | API Service to manage recipientlists
6 |
7 | ### Retrieve a service instance
8 | ```php
9 | $service = $client->recipientlists();
10 | ```
11 |
12 | ### Available methods
13 | #### Get details for a specific recipientlist
14 | ```php
15 | $response = $service->get(/* RECIPIENTLIST ID */);
16 | ```
17 | #### Delete recipientlist specified by ID
18 | ```php
19 | $response = $service->delete(/* RECIPIENTLIST ID */);
20 | ```
21 | #### Get a list of recipientlists from current account
22 | See [GET call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipientlists#/Recipientlists/get_recipientlists) on how to setup OPTIONAL FILTER
23 | ```php
24 | $collection = $service->query(/* OPTIONAL FILTER */);
25 | ```
26 | #### Create a new recipientlist
27 | See [POST call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipientlists#/Recipientlists/post_recipientlists) on how to setup PAYLOAD
28 | ```php
29 | $response = $service->create(/* PAYLOAD */);
30 | ```
31 | #### Update a specific recipientlist allowing partial updates
32 | See [PATCH call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipientlists#/Recipientlists/patch_recipientlists__recipientlist_id_) on how to setup PAYLOAD
33 | ```php
34 | $response = $service->update(/* RECIPIENTLIST ID */, /* PAYLOAD */);
35 | ```
36 | #### Get activity stats for a specific recipientlist
37 | See [GET call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipientlists#/Recipientlists/get_recipientlists__recipientlist_id__stats_activity) on how to setup REQUIRED FILTER
38 | ```php
39 | $response = $service->activityStats(/* RECIPIENTLIST ID */, /* REQUIRED FILTER */);
40 | ```
--------------------------------------------------------------------------------
/pages/yform.rapidmail.docs.php:
--------------------------------------------------------------------------------
1 | getPath('') . 'README.md';
10 | foreach (glob(rex_addon::get('yform_rapidmail')->getPath('lib/rapidmail/docs') . '/*.md') ?: [] as $file) {
11 | $mdFiles[mb_substr(basename($file), 0, -3)] = $file;
12 | }
13 |
14 |
15 | $currenMDFile = rex_request('mdfile', 'string', 'README');
16 | if (!array_key_exists($currenMDFile, $mdFiles)) {
17 | $currenMDFile = 'README';
18 | }
19 |
20 | $page = rex_be_controller::getPageObject('yform/rapidmail');
21 |
22 | if (null !== $page) {
23 | foreach ($mdFiles as $key => $mdFile) {
24 | if($key === 'README') {
25 | continue;
26 | }
27 | $keyWithoudPrio = mb_substr($key, 3);
28 | $currenMDFileWithoudPrio = mb_substr($currenMDFile, 3);
29 | $page->addSubpage(
30 | (new rex_be_page($key, rex_i18n::msg('yform_rapidmail_' . $keyWithoudPrio)))
31 | ->setSubPath($mdFile)
32 | ->setHref('index.php?page=yform/rapidmail/docs&mdfile=' . $key)
33 | ->setIsActive($key == $currenMDFile),
34 | );
35 | }
36 | }
37 |
38 | echo rex_view::title($this->i18n('yform_rapidmail'));
39 |
40 | [$Toc, $Content] = rex_markdown::factory()->parseWithToc(rex_file::require($mdFiles[$currenMDFile]), 2, 3, [
41 | rex_markdown::SOFT_LINE_BREAKS => false,
42 | rex_markdown::HIGHLIGHT_PHP => true,
43 | ]);
44 |
45 | $fragment = new rex_fragment();
46 | $fragment->setVar('content', $Content, false);
47 | $fragment->setVar('toc', $Toc, false);
48 | $content = $fragment->parse('core/page/docs.php');
49 |
50 | $fragment = new rex_fragment();
51 | $fragment->setVar('title', rex_i18n::msg('package_help') . ' YForm Rapidmail', false);
52 | $fragment->setVar('body', $content, false);
53 | echo $fragment->parse('core/page/section.php');
54 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipientlists/Recipientlist/Parameter/RecipientlistCreateParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('name', $name);
32 |
33 | return $this;
34 | }
35 |
36 | /**
37 | * Set recipientlist as default
38 | *
39 | * @param mixed $flag
40 | * @return static
41 | */
42 | public function setDefault($flag)
43 | {
44 | $this->setAttributeRaw('default', $this->convertBool($flag));
45 |
46 | return $this;
47 | }
48 |
49 | /**
50 | * Specify if recipients should be blacklisted upon unsubscription
51 | *
52 | * @param mixed $flag
53 | * @return static
54 | */
55 | public function setUnsubscribeBlacklist($flag)
56 | {
57 | $this->setAttributeRaw('unsubscribe_blacklist', $this->convertBool($flag));
58 |
59 | return $this;
60 | }
61 |
62 | /**
63 | * Specify if a welcome email should be sent on subscribe
64 | *
65 | * @param mixed $flag
66 | * @return static
67 | */
68 | public function setRecipientSubscribeEmail($flag)
69 | {
70 | $this->setAttributeRaw('recipient_subscribe_email', $this->convertBool($flag));
71 |
72 | return $this;
73 | }
74 |
75 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/MailingRecipients/MailingRecipientsService.php:
--------------------------------------------------------------------------------
1 | client->request(
37 | 'GET',
38 | "{$this->getResourcePath()}/{$mailingId}/stats/activity/{$mailingRecipientId}"
39 |
40 | );
41 |
42 | return $this->responseFactory->newHalResponse($this->client, $response);
43 |
44 | }
45 |
46 | /**
47 | * Get recipients for mailing
48 | *
49 | * @param int $mailingId
50 | * @return HalResponseResourceIterator
51 | * @throws ApiException
52 | */
53 | public function query($mailingId)
54 | {
55 |
56 | $response =
57 | $this->client->request(
58 | 'GET',
59 | "{$this->getResourcePath()}/{$mailingId}/stats/activity"
60 |
61 | );
62 |
63 | return $this
64 | ->responseFactory
65 | ->newHalResponseResourceIterator(
66 | $this->client,
67 | 'mailingrecipients',
68 | $response
69 | );
70 |
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/Response/ResponseFactory.php:
--------------------------------------------------------------------------------
1 | decodeResponse($response));
23 | }
24 |
25 | /**
26 | * Returns a new HalResponseResourceIterator to transparently iterate all nested resources within a paged result
27 | *
28 | * @param HttpClientInterface $client
29 | * @param string $resourceKey
30 | * @param HttpResponseInterface $response
31 | * @return HalResponseResourceIterator
32 | * @throws ApiException
33 | */
34 | public function newHalResponseResourceIterator(
35 | HttpClientInterface $client,
36 | $resourceKey,
37 | HttpResponseInterface $response
38 | ) {
39 |
40 | return new HalResponseResourceIterator(
41 | new HalResponsePaginationIterator(
42 | $this->newHalResponse($client, $response)
43 | ),
44 | $resourceKey
45 | );
46 |
47 | }
48 |
49 | /**
50 | * @inheritDoc
51 | */
52 | protected function decodeResponse(HttpResponseInterface $response)
53 | {
54 | $decodedResponse = json_decode($response->getBody(), true);
55 |
56 | if (json_last_error() !== JSON_ERROR_NONE) {
57 | throw new ApiException(json_last_error_msg());
58 | }
59 |
60 | if (empty($decodedResponse)) {
61 | $decodedResponse = [];
62 | }
63 |
64 | return $decodedResponse;
65 |
66 | }
67 |
68 | }
--------------------------------------------------------------------------------
/lib/rapidmail/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file, in reverse chronological order by release.
4 |
5 | ## 1.1.6
6 | - Fix issue with API version number from config being passed to Guzzle client instance
7 | See [#20](https://github.com/rapidmail/rapidmail-apiv3-client-php/issues/20) for details. Thanks to
8 | [schelmo](https://github.com/schelmo) for the current workaround.
9 |
10 | ## 1.1.5
11 | - [#19](https://github.com/rapidmail/rapidmail-apiv3-client-php/pull/19) allow psr/http-message 2.0
12 | (Thganks to [saitho](https://github.com/saitho))
13 |
14 | ## 1.1.4
15 | - Fixed deprecation warnings caused by use of deprecated variable replacement notation.
16 |
17 | ## 1.1.3
18 | - [#15](https://github.com/rapidmail/rapidmail-apiv3-client-php/pull/15) fix deprecation message in throttling
19 | middleware (Thanks to [mklewitz](https://github.com/mklewitz))
20 |
21 | ## 1.1.2
22 | - Add missing #ReturnTypeWillChange attributes
23 | - Fix variable substitution syntax to be compatible with PHP 8.2+
24 |
25 | ## 1.1.1
26 | - Add #ReturnTypeWillChange attribute to prevent deprecation notices on PHP 8+
27 | - Run tests for PHP 8.1 and 8.2
28 | - Remove ZIP installation instructions
29 |
30 | ## 1.1.0
31 | ### Added
32 | - [#8](https://github.com/rapidmail/rapidmail-apiv3-client-php/pull/8) adds support for PHP 8.0.
33 | - [#8](https://github.com/rapidmail/rapidmail-apiv3-client-php/pull/8) adds support for Guzzle7 releases
34 | fixing issue #7
35 |
36 | ### Fixed
37 | - [#8](https://github.com/rapidmail/rapidmail-apiv3-client-php/pull/8) fixes base64 content validation
38 | failing with large base64 payloads.
39 |
40 | ## 1.0.1
41 |
42 | ### Added
43 |
44 | - [#3](https://github.com/rapidmail/rapidmail-apiv3-client-php/pull/3) adds support for PHP 7.4.
45 |
46 | ### Changed
47 |
48 | - Nothing.
49 |
50 | ### Deprecated
51 |
52 | - Nothing.
53 |
54 | ### Removed
55 |
56 | - Nothing.
57 |
58 | ### Fixed
59 |
60 | - [#4](https://github.com/rapidmail/rapidmail-apiv3-client-php/pull/4) fixes a bug where setting the "updated_since"
61 | filter when listing mailings would instead apply a "created_since" filter (Issue #2)
62 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/AbstractService.php:
--------------------------------------------------------------------------------
1 | client = $client;
42 | $this->responseFactory = $responseFactory;
43 | }
44 |
45 | /**
46 | * Retrieve a single resource
47 | *
48 | * @param int $id
49 | * @return ResponseInterface
50 | *
51 | * @throws ApiException
52 | */
53 | protected function _get($id)
54 | {
55 | return $this->client->request('GET', "{$this->getResourcePath()}/{$id}");
56 | }
57 |
58 | /**
59 | * Query for a collection of resources
60 | *
61 | * @param array $filter
62 | * @return ResponseInterface
63 | *
64 | * @throws ApiException
65 | */
66 | protected function _query(array $filter = [])
67 | {
68 | return $this->client->request('GET', $this->getResourcePath(), ['query' => $filter]);
69 | }
70 |
71 | /**
72 | * Delete a resource
73 | *
74 | * @param int $id
75 | * @return ResponseInterface
76 | *
77 | * @throws ApiException
78 | */
79 | protected function _delete($id)
80 | {
81 | return $this->client->request('DELETE', "{$this->getResourcePath()}/{$id}");
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipients/Recipient/Parameter/ParameterFactory.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
25 | parent::__construct($attributes);
26 | }
27 |
28 | /**
29 | * @inheritDoc
30 | */
31 | protected function getKnownAttributeKeys()
32 | {
33 | return [
34 | 'file'
35 | ];
36 | }
37 |
38 | /**
39 | * Sets the file containing all recipients
40 | *
41 | * @param BlacklistImportParamFileAttr|array|string|\SplFileInfo $file
42 | * @return static
43 | */
44 | public function setFile($file)
45 | {
46 |
47 | if ($file instanceof BlacklistImportParamFileAttr) {
48 | $this->setAttributeRaw('file', $file);
49 |
50 | return $this;
51 | }
52 |
53 | if (is_array($file)) {
54 | $this->setAttributeRaw('file', $this->parameterFactory->newImportParamFileAttr($file));
55 |
56 | return $this;
57 | }
58 |
59 | $info = new \finfo(FILEINFO_MIME_TYPE);
60 |
61 | if ($file instanceof \SplFileInfo || is_file($file)) {
62 |
63 | if (!is_readable($file)) {
64 | throw new InvalidArgumentException("File {$file} is not readable");
65 | }
66 |
67 | $fileAttr = $this->parameterFactory->newImportParamFileAttr([
68 | 'content' => base64_encode(file_get_contents($file)),
69 | 'type' => $info->file($file)
70 | ]);
71 |
72 | $this->setAttributeRaw('file', $fileAttr);
73 |
74 | return $this;
75 |
76 | }
77 |
78 | throw new InvalidArgumentException("{$file} does not appear to be a valid file");
79 |
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipients/Recipient/Parameter/RecipientImportParam.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
25 | parent::__construct($attributes);
26 | }
27 |
28 | /**
29 | * @inheritDoc
30 | */
31 | protected function getKnownAttributeKeys()
32 | {
33 | return [
34 | 'recipientlist_id',
35 | 'file'
36 | ];
37 | }
38 |
39 | /**
40 | * Sets the file containing all recipients
41 | *
42 | * @param RecipientImportParamFileAttr|array|string|\SplFileInfo $file
43 | * @return static
44 | */
45 | public function setFile($file)
46 | {
47 |
48 | if ($file instanceof RecipientImportParamFileAttr) {
49 | $this->setAttributeRaw('file', $file);
50 |
51 | return $this;
52 | }
53 |
54 | if (is_array($file)) {
55 | $this->setAttributeRaw('file', $this->parameterFactory->newImportParamFileAttr($file));
56 |
57 | return $this;
58 | }
59 |
60 | $info = new \finfo(FILEINFO_MIME_TYPE);
61 |
62 | if ($file instanceof \SplFileInfo || is_file($file)) {
63 |
64 | if (!is_readable($file)) {
65 | throw new InvalidArgumentException("File {$file} is not readable");
66 | }
67 |
68 | $fileAttr = $this->parameterFactory->newImportParamFileAttr([
69 | 'content' => base64_encode(file_get_contents($file)),
70 | 'type' => $info->file($file)
71 | ]);
72 |
73 | $this->setAttributeRaw('file', $fileAttr);
74 |
75 | return $this;
76 |
77 | }
78 |
79 | throw new InvalidArgumentException("{$file} does not appear to be a valid file");
80 |
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/lib/rapidmail/docs/mailing-services.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | ## Mailing Service
4 |
5 | The API service to manage mailings.
6 |
7 | ### Examples
8 |
9 | * [Fetch mailings](/examples/example-02-fetch-mailings.php)
10 |
11 | ### Retrieve a service instance
12 | ```php
13 | $service = $client->mailings();
14 | ```
15 | ### Available methods
16 | #### Get detailed info about single mailing
17 | ```php
18 | $response = $service->get(/* MAILING ID */);
19 | ```
20 | #### Delete a single mailing
21 | ```php
22 | $response = $service->delete(/* MAILING ID */);
23 | ```
24 | #### List available mailings with optional filter criteria applied
25 | See [GET call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Mailings#/Mailings/get_mailings) on how to setup OPTIONAL FILTER
26 | ```php
27 | $collection = $service->query(/* OPTIONAL FILTER */);
28 | ```
29 | #### Create a new mailing using zip file content
30 | See [POST call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Mailings#/Mailings/post_mailings) on how to setup PAYLOAD
31 | ```php
32 | $response = $service->create(/* PAYLOAD */);
33 | ```
34 | #### Pause a mailing
35 | ```php
36 | $response = $service->pause(/* MAILING ID */);
37 | ```
38 |
39 | #### Cancel a mailing
40 | ```php
41 | $response = $service->cancel(/* MAILING ID */);
42 | ```
43 |
44 | ## MailingRecipients Service
45 |
46 | API service to get recipient details for specific mailing
47 |
48 | ```php
49 | $service = $client->mailingRecipients();
50 | ```
51 |
52 | ### Available methods
53 | #### Get recipients for mailing
54 | ```php
55 | $collection = $service->query(/* MAILING ID */);
56 | ```
57 | #### Get details about specific mailing recipient
58 | ```php
59 | $response = $service->get(/* MAILING ID */, /* MAILING RECIPIENT ID */);
60 | ```
61 |
62 | ## MailingStats Service
63 |
64 | API Service to get stats for a mailing
65 |
66 | ```php
67 | $service = $client->mailingStats();
68 | ```
69 |
70 | ### Available methods
71 | #### Get stats for specific mailing
72 | ```php
73 | $response = $service->get(/* MAILING ID */);
74 | ```
75 |
76 | ## MailingStatsAnonymize Service
77 |
78 | API service to anonymize stats for a sent mailing
79 |
80 | ```php
81 | $service = $client->mailingStatsAnonymize();
82 | ```
83 |
84 | ### Available methods
85 |
86 | #### Anonymize mailing stats for a specific sent mailing
87 | ```php
88 | $response = $service->anonymize(/* MAILING ID */);
89 | ```
90 |
--------------------------------------------------------------------------------
/lib/rapidmail/docs/recipients-services.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | ## Recipients Service
4 |
5 | API Service to manage recipients
6 |
7 | ### Examples
8 |
9 | * [Fetch recipients](/examples/example-03-fetch-recipients.php)
10 | * [Create recipient](/examples/example-04-create-recipient.php)
11 | * [Import recipient data](/examples/example-05-import-recipients.php)
12 |
13 | ### Retrieve a service instance
14 | ```php
15 | $service = $client->recipients();
16 | ```
17 |
18 | ### Available methods
19 | #### Load a single recipient by ID
20 | ```php
21 | $response = $service->get(/* RECIPIENT ID */);
22 | ```
23 | #### Delete recipient by ID
24 | See [DELETE call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipients#/Recipients/delete_recipients__recipient_id_) on how to setup OPTIONAL MODIFIER
25 | ```php
26 | $response = $service->delete(/* RECIPIENT ID */, /* OPTIONAL MODIFIER */);
27 | ```
28 | #### List all recipients
29 | See [GET call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipients#/Recipients/get_recipients) on how to setup REQUIRED FILTER
30 | ```php
31 | $collection = $service->query(/* REQUIRED FILTER */);
32 | ```
33 | #### Create a new recipient
34 | See [POST call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipients#/Recipients/post_recipients) on how to setup PAYLOAD and OPTIONAL MODIFIER
35 | ```php
36 | $response = $service->create(/* PAYLOAD */, /* OPTIONAL MODIFIER */);
37 | ```
38 | * PAYLOAD: Represents the dataset you're creating
39 | * OPTIONAL MODIFIER: Configures system behavior, like sending activationmails
40 | #### Update a specific recipient allowing partial updates
41 | See [PATCH call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipients#/Recipients/patch_recipients__recipient_id_) on how to setup PAYLOAD
42 | ```php
43 | $response = $service->update(/* RECIPIENT ID */, /* PAYLOAD */);
44 | ```
45 | #### Import a list of recipients into a recipientlist from a CSV file
46 | See [POST call documentation](https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipients#/RecipientImport/post_recipients_import) on how to setup PAYLOAD and OPTIONAL MODIFIER
47 | ```php
48 | $response = $service->import(/* PAYLOAD */, /* OPTIONAL MODIFIER */);
49 | ```
50 | * PAYLOAD: Expects recipientlist_id and a file to be set
51 | * OPTIONAL MODIFIER: Configures system behavior, like setting import enclosure and delimiter
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/Mailing/Parameter/MailingQueryParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('page', $page);
51 |
52 | return $this;
53 | }
54 |
55 | /**
56 | * Sets the status filter
57 | *
58 | * @param string $status
59 | * @return static
60 | */
61 | public function setStatus($status)
62 | {
63 |
64 | if (!in_array($status, static::STATUS_VALUES)) {
65 |
66 | throw new InvalidArgumentException(
67 | 'Invalid status provided. Must be one of: ' . implode(', ', static::STATUS_VALUES)
68 | );
69 |
70 | }
71 |
72 | $this->setAttributeRaw('status', $status);
73 |
74 | return $this;
75 | }
76 |
77 | /**
78 | * Sets the mailings created since datetime filter
79 | *
80 | * @param string|\DateTimeInterface $dateTime
81 | *
82 | * @return static
83 | */
84 | public function setCreatedSince($dateTime)
85 | {
86 | $this->setAttributeRaw('created_since', $this->stringifyDateTime($dateTime));
87 |
88 | return $this;
89 | }
90 |
91 | /**
92 | * Sets the mailings updated since datetime filter
93 | *
94 | * @param string|\DateTimeInterface $dateTime
95 | *
96 | * @return static
97 | */
98 | public function setUpdatedSince($dateTime)
99 | {
100 | $this->setAttributeRaw('updated_since', $this->stringifyDateTime($dateTime));
101 |
102 | return $this;
103 | }
104 |
105 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/Response/HalResponsePaginationIterator.php:
--------------------------------------------------------------------------------
1 | initial = $response;
28 | $this->current = $this->initial;
29 | }
30 |
31 | /**
32 | * @inheritDoc
33 | */
34 | #[\ReturnTypeWillChange]
35 | public function current()
36 | {
37 | return $this->current;
38 | }
39 |
40 | /**
41 | * @inheritDoc
42 | */
43 | #[\ReturnTypeWillChange]
44 | public function next()
45 | {
46 | $this->current = $this->current->next();
47 | }
48 |
49 | /**
50 | * @inheritDoc
51 | */
52 | #[\ReturnTypeWillChange]
53 | public function key()
54 | {
55 | return $this->current['page'];
56 | }
57 |
58 | /**
59 | * @inheritDoc
60 | */
61 | #[\ReturnTypeWillChange]
62 | public function valid()
63 | {
64 | return $this->current !== null;
65 | }
66 |
67 | /**
68 | * @inheritDoc
69 | */
70 | #[\ReturnTypeWillChange]
71 | public function rewind()
72 | {
73 | $this->current = $this->initial;
74 | }
75 |
76 | /**
77 | * @inheritDoc
78 | */
79 | #[\ReturnTypeWillChange]
80 | public function count()
81 | {
82 | return $this->current['page_count'];
83 | }
84 |
85 | /**
86 | * @return int
87 | */
88 | public function totalCount()
89 | {
90 | return $this->current['total_items'];
91 | }
92 |
93 | /**
94 | * @return array
95 | */
96 | protected function toArray()
97 | {
98 |
99 | return iterator_to_array(
100 | new CallbackIterator(
101 | $this,
102 | function ($item) {
103 | return $item instanceof HalResponse ? $item->toArray() : $item;
104 | }
105 | )
106 | );
107 |
108 | }
109 |
110 | /**
111 | * @inheritDoc
112 | */
113 | public function __debugInfo()
114 | {
115 | return $this->toArray();
116 | }
117 |
118 | /**
119 | * @inheritDoc
120 | */
121 | public function __toString()
122 | {
123 | return (string)print_r($this->toArray(), true);
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/lib/yform/action/yform_rapidmail.php:
--------------------------------------------------------------------------------
1 | getElement(2);
16 | $email = $this->params['value_pool']['sql'][$this->getElement(3)] ?? null; // email field
17 | $optin = true;
18 | if($this->getElement(4)) {
19 | $optin = (bool) $this->params['value_pool']['sql'][$this->getElement(4)]; // opt: DSGVO optin field
20 | }
21 | $fullname = $this->params['value_pool']['sql'][$this->getElement(5)] ?? ""; // opt: fullname field
22 |
23 | if($list_id && $optin && $email && 0 == count($this->params['warning_messages'])) {
24 |
25 | $recipientService = $client->recipients();
26 |
27 | $payload = [
28 | 'email' => $email,
29 | 'recipientlist_id' => $list_id
30 | ];
31 |
32 |
33 | $modifier = [
34 | 'send_activationmail' => 'yes'
35 | ];
36 |
37 | try {
38 |
39 | $recipientService->create($payload, $modifier);
40 |
41 | } catch (ApiClientException $e) {
42 | if ($e->getCode() == 400) {
43 | dump('Client error. Check if the data is correct.');
44 | }
45 | if ($e->getCode() == 401) {
46 | dump('Unauthorized access. Check if username and password are correct.');
47 | }
48 | if ($e->getCode() == 403) {
49 | dump('Forbidden access. Check if the user has the necessary rights.');
50 | }
51 | if ($e->getCode() == 406) {
52 | dump('Not acceptable. Check if the data is correct.');
53 | }
54 | if ($e->getCode() == 409) {
55 | dump('E-Mail already exists in the list.');
56 | }
57 | if ($e->getCode() == 415) {
58 | dump('Unsupported Media Type.');
59 | }
60 | if ($e->getCode() == 422) {
61 | dump('Validation failure. Check if the data is correct.');
62 | }
63 |
64 | dump('An API exception occurred: ' . $e->getMessage());
65 |
66 | }
67 |
68 | }
69 | }
70 |
71 | public function getDescription(): string
72 | {
73 | return 'action|yform_rapidmail|list_id|email_fieldname(e.g. email)|opt:optin_fieldname(e.g. newsletter)|opt:fieldname_fullname(fullname)';
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/ServiceFactory.php:
--------------------------------------------------------------------------------
1 | httpClientFactory = $httpClientFactory;
32 | $this->userConfig = $config;
33 | }
34 |
35 | /**
36 | * @return array
37 | */
38 | private function getGlobalConfig()
39 | {
40 | return require __DIR__ . '/../Config/services.php';
41 | }
42 |
43 | /**
44 | * Create a specific API service
45 | *
46 | * @param string $service
47 | * @param string|null $version
48 | * @return \Rapidmail\ApiClient\Service\ServiceInterface
49 | * @throws NotImplementedException
50 | */
51 | public function createService($service, $version = null)
52 | {
53 |
54 | $globalConfig = $this->getGlobalConfig();
55 |
56 | if (!isset($globalConfig['services'][$service])) {
57 | throw new NotImplementedException("API service '{$service}' not found");
58 | }
59 |
60 | if ($version === null) {
61 | $version = $globalConfig['services'][$service]['current'];
62 | }
63 |
64 | if (!isset($globalConfig['services'][$service]['config'][$version])) {
65 | throw new NotImplementedException("API service '{$service}' for version '{$version}' not found");
66 | }
67 |
68 | $connectionSettings = array_replace_recursive(
69 | $globalConfig['connection'],
70 | ['version' => $version],
71 | $this->userConfig
72 | );
73 |
74 | $factoryClass = $globalConfig['services'][$service]['config'][$version]['factory_class'];
75 | $interfaces = class_implements($factoryClass);
76 |
77 | if ($interfaces === false || in_array(ServiceFactoryInterface::class, $interfaces) === false) {
78 | throw new NotImplementedException("Service factory {$factoryClass} must implement ServiceFactoryInterface");
79 | }
80 |
81 | /** @var ServiceFactoryInterface $factory */
82 | $factory = new $factoryClass();
83 |
84 | return $factory->create(
85 | [
86 | HttpClientInterface::class => $this->httpClientFactory->createClient($connectionSettings),
87 | ResponseFactory::class => new ResponseFactory()
88 | ]
89 | );
90 |
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/Mailing/Parameter/MailingCreateParamDestinationAttr.php:
--------------------------------------------------------------------------------
1 | 'recipientlist',
38 | 'action' => 'include'
39 | ],
40 | $attributes
41 | )
42 | );
43 |
44 | }
45 |
46 | /**
47 | * @inheritDoc
48 | */
49 | protected function getKnownAttributeKeys()
50 | {
51 | return [
52 | 'id',
53 | 'type',
54 | 'action'
55 | ];
56 | }
57 |
58 | /**
59 | * Sets the destination ID
60 | *
61 | * @return static
62 | * @var int $destinationId
63 | */
64 | public function setId($destinationId)
65 | {
66 |
67 | if (!is_numeric($destinationId)) {
68 | throw new InvalidArgumentException('Destination ID must be numeric');
69 | }
70 |
71 | $this->setAttributeRaw('id', $destinationId);
72 |
73 | return $this;
74 | }
75 |
76 | /**
77 | * Sets the destination type
78 | *
79 | * @return static
80 | * @var string $type
81 | */
82 | public function setType($type)
83 | {
84 |
85 | if (!in_array($type, static::ALLOWED_TYPES)) {
86 |
87 | throw new InvalidArgumentException(
88 | 'Destination type not allowed. Must be one of: ' . implode(', ', static::ALLOWED_TYPES)
89 | );
90 |
91 | }
92 | $this->setAttributeRaw('type', $type);
93 |
94 | return $this;
95 | }
96 |
97 | /**
98 | * Sets the destination action
99 | *
100 | * @return static
101 | * @var string $action
102 | */
103 | public function setAction($action)
104 | {
105 |
106 | if (!in_array($action, static::ALLOWED_ACTIONS)) {
107 |
108 | throw new InvalidArgumentException(
109 | 'Destination action not allowed. Must be one of: ' . implode(', ', static::ALLOWED_ACTIONS)
110 | );
111 |
112 | }
113 | $this->setAttributeRaw('action', $action);
114 |
115 | return $this;
116 | }
117 |
118 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Http/ThrottleMiddleware.php:
--------------------------------------------------------------------------------
1 | interval = $interval;
49 | $this->requestsPerInterval = $requestsPerInterval;
50 | }
51 |
52 | /**
53 | * Get a global instance
54 | *
55 | * @param float $interval Interval in seconds
56 | * @param int $requestsPerInterval
57 | * @return static
58 | */
59 | public static function getInstance($interval, $requestsPerInterval)
60 | {
61 |
62 | if (static::$instance === null) {
63 | static::$instance = new static($interval, $requestsPerInterval);
64 | }
65 |
66 | return static::$instance;
67 | }
68 |
69 | /**
70 | * Create the throttle middleware
71 | *
72 | * @param callable $handler
73 | * @return callable
74 | */
75 | public function __invoke(callable $handler)
76 | {
77 |
78 | return function (RequestInterface $request, array $options) use ($handler) {
79 | $this->throttle();
80 |
81 | return $handler($request, $options);
82 | };
83 |
84 | }
85 |
86 | /**
87 | * Apply throttling when requests per interval being exceeded
88 | */
89 | private function throttle()
90 | {
91 |
92 | $now = microtime(true);
93 |
94 | // Expire outdated
95 |
96 | $this->timestampStack = array_values(
97 | array_filter(
98 | $this->timestampStack,
99 | function ($last) use ($now) {
100 | return $now - $last < $this->interval;
101 | }
102 | )
103 | );
104 |
105 | // Sleep at least until oldest timestamp expires
106 |
107 | if (count($this->timestampStack) >= $this->requestsPerInterval) {
108 |
109 | usleep(
110 | (int) abs(
111 | min($now - $this->timestampStack[0] - $this->interval, 0)
112 | ) * 1000000
113 | );
114 |
115 | }
116 |
117 | $this->timestampStack[] = microtime(true);
118 |
119 | }
120 |
121 | }
--------------------------------------------------------------------------------
/pages/yform.rapidmail.settings.php:
--------------------------------------------------------------------------------
1 | getName());
13 |
14 | $field = $form->addTextField('api_user_hash');
15 | $field->setLabel(rex_i18n::msg('yform_rapidmail_api_user'));
16 | $field->setNotice('hier erstellen');
17 |
18 | $field = $form->addTextField('api_password_hash');
19 | $field->setLabel(rex_i18n::msg('yform_rapidmail_hash'));
20 |
21 | $fragment = new rex_fragment();
22 | $fragment->setVar('class', 'edit', false);
23 | $fragment->setVar('title', $addon->i18n('yform_rapidmail_config'), false);
24 | $fragment->setVar('body', $form->get(), false);
25 |
26 |
27 |
28 | /* Empfängerlisten-Fragment */
29 | $client = new Client(rex_config::get('yform_rapidmail', 'api_user_hash'), rex_config::get('yform_rapidmail', 'api_password_hash'));
30 |
31 | $listService = $client->recipientlists();
32 | $listFragment = new rex_fragment();
33 | $content = '';
34 |
35 | $table = '
' . $this->i18n('yform_rapidmail_list') . '
';
36 |
37 | try {
38 | foreach ($listService->query() as $list) {
39 | $content .= '';
40 | $content .= '| ' . $list['id'] . ' | ';
41 | $content .= '' . $list['name'] . ' ' . $list['description'] . ' | ';
42 | $content .= ''.rex_i18n::msg('yform_rapidmail_list_link').' | ';
43 | $content .= '
';
44 | }
45 |
46 | $table = '
47 |
48 |
49 | | ID |
50 | Name |
51 | '.rex_i18n::msg('yform_rapidmail_list_link').' |
52 |
53 |
54 |
55 | ' . $content . '
56 |
57 |
';
58 | } catch (ApiClientException $e) {
59 | $table = '' . $this->i18n('yform_rapidmail_info_list_error') . '
';
60 | }
61 | $listFragment->setVar('class', 'info', false);
62 | $listFragment->setVar('title', $this->i18n('yform_rapidmail_list'), false);
63 |
64 | $listFragment->setVar('content', $table, false);
65 | ?>
66 |
67 |
68 |
69 | = $fragment->parse('core/page/section.php') ?>
70 | = $listFragment->parse('core/page/section.php') ?>
71 |
72 |
73 |
.')
';
76 |
77 | $fragment = new rex_fragment();
78 | $fragment->setVar('class', 'info', false);
79 | $fragment->setVar('title', $this->i18n('yform_rapidmail_donate'), false);
80 | $fragment->setVar('body', '
' . $this->i18n('yform_rapidmail_info_donate') . '
' . $anchor, false);
81 | echo !rex_config::get("alexplusde", "donated") ? $fragment->parse('core/page/section.php') : "";
82 | ?>
83 |
84 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/TrxEmails/TrxEmail/TrxEmailService.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
39 | parent::__construct($client, $responseFactory);
40 | }
41 |
42 | /**
43 | * @return ParameterFactory
44 | */
45 | public function params()
46 | {
47 | return $this->parameterFactory;
48 | }
49 |
50 | /**
51 | * @inheritDoc
52 | */
53 | protected function getResourcePath()
54 | {
55 | return 'trx/emails';
56 | }
57 |
58 | /**
59 | * Get list of transaction emails
60 | *
61 | * @param array|TrxEmailQueryParam $filter
62 | * @return HalResponseResourceIterator
63 | * @throws ApiException
64 | */
65 | public function query($filter = [])
66 | {
67 |
68 | if (is_array($filter)) {
69 | $filter = $this->parameterFactory->newQueryParam($filter);
70 | }
71 |
72 | if (!$filter instanceof TrxEmailQueryParam) {
73 |
74 | throw new InvalidArgumentException(
75 | 'Invalid filter provided. Must be an array or TrxEmailQueryParam'
76 | );
77 |
78 | }
79 |
80 | return $this->responseFactory->newHalResponseResourceIterator(
81 | $this->client,
82 | 'trxemails',
83 | $this->_query(
84 | $filter->toArray()
85 | )
86 | );
87 |
88 | }
89 |
90 | /**
91 | * Get info about a single transaction email
92 | *
93 | * @param string $hash
94 | * @return HalResponse
95 | * @throws ApiException
96 | */
97 | public function get($hash)
98 | {
99 |
100 | return $this
101 | ->responseFactory
102 | ->newHalResponse(
103 | $this->client,
104 | $this->_get($hash)
105 | );
106 |
107 | }
108 |
109 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Config/services.php:
--------------------------------------------------------------------------------
1 | [
5 | 'base_uri' => 'https://apiv3.emailsys.net',
6 | 'throttle_interval' => 1, // in seconds
7 | 'throttle_requests_per_interval' => 10
8 | ],
9 | 'services' => [
10 | 'mailings' => [
11 | 'current' => 'v1',
12 | 'config' => [
13 | 'v1' => [
14 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Mailings\Mailing\MailingServiceFactory::class
15 | ]
16 | ]
17 | ],
18 | 'mailing_recipients' => [
19 | 'current' => 'v1',
20 | 'config' => [
21 | 'v1' => [
22 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Mailings\MailingRecipients\MailingRecipientsServiceFactory::class
23 | ]
24 | ]
25 | ],
26 | 'mailing_stats' => [
27 | 'current' => 'v1',
28 | 'config' => [
29 | 'v1' => [
30 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Mailings\MailingStats\MailingStatsServiceFactory::class
31 | ]
32 | ]
33 | ],
34 | 'mailing_stats_anonymize' => [
35 | 'current' => 'v1',
36 | 'config' => [
37 | 'v1' => [
38 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Mailings\MailingStatsAnonymize\MailingStatsAnonymizeServiceFactory::class
39 | ]
40 | ]
41 | ],
42 | 'recipientlists' => [
43 | 'current' => 'v1',
44 | 'config' => [
45 | 'v1' => [
46 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Recipientlists\Recipientlist\RecipientlistServiceFactory::class
47 | ]
48 | ]
49 | ],
50 | 'recipients' => [
51 | 'current' => 'v1',
52 | 'config' => [
53 | 'v1' => [
54 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Recipients\Recipient\RecipientServiceFactory::class
55 | ]
56 | ]
57 | ],
58 | 'jobs' => [
59 | 'current' => 'v1',
60 | 'config' => [
61 | 'v1' => [
62 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Jobs\Job\JobServiceFactory::class
63 | ]
64 | ]
65 | ],
66 | 'trx_emails' => [
67 | 'current' => 'v1',
68 | 'config' => [
69 | 'v1' => [
70 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\TrxEmails\TrxEmail\TrxEmailsServiceFactory::class
71 | ]
72 | ]
73 | ],
74 | 'apiusers' => [
75 | 'current' => 'v1',
76 | 'config' => [
77 | 'v1' => [
78 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\ApiUsers\ApiUser\ApiUserServiceFactory::class
79 | ]
80 | ]
81 | ],
82 | 'blacklist' => [
83 | 'current' => 'v1',
84 | 'config' => [
85 | 'v1' => [
86 | 'factory_class' => \Rapidmail\ApiClient\Service\V1\Api\Blacklist\Blacklist\BlacklistServiceFactory::class
87 | ]
88 | ]
89 | ]
90 | ]
91 | ];
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/Parameter/GenericParameter.php:
--------------------------------------------------------------------------------
1 | attributeStore = new \ArrayObject();
27 |
28 | foreach ($attributes as $attributeKey => $attributeValue) {
29 | $this->setAttribute($attributeKey, $attributeValue);
30 | }
31 |
32 | }
33 |
34 | /**
35 | * Sets a single attribute
36 | *
37 | * @param string $key
38 | * @param mixed $value
39 | * @return static
40 | */
41 | public function setAttribute($key, $value)
42 | {
43 |
44 | $keys = $this->getKnownAttributeKeys();
45 |
46 | if (in_array($key, $keys)) {
47 |
48 | $setterMethod = 'set' . str_replace('_', '', ucwords($key, '_'));
49 |
50 | if (method_exists($this, $setterMethod)) {
51 | $this->{$setterMethod}($value);
52 |
53 | return $this;
54 | }
55 |
56 | }
57 |
58 | $this->setAttributeRaw($key, $value);
59 |
60 | return $this;
61 |
62 | }
63 |
64 | /**
65 | * Sets a single attribute
66 | *
67 | * @param string $key
68 | * @param mixed $value
69 | */
70 | protected function setAttributeRaw($key, $value)
71 | {
72 | $this->attributeStore->offsetSet($key, $value);
73 | }
74 |
75 | /**
76 | * @inheritDoc
77 | */
78 | public function toArray()
79 | {
80 | return array_map(
81 | function ($value) {
82 | return $value instanceof ParameterInterface ? $value->toArray() : $value;
83 | },
84 | $this->attributeStore->getArrayCopy()
85 | );
86 | }
87 |
88 | /**
89 | * A list of known attribute keys that will be mapped to an appropriate setter method
90 | *
91 | * @return string[]
92 | */
93 | protected function getKnownAttributeKeys()
94 | {
95 | return [];
96 | }
97 |
98 | /**
99 | * Prepare date time string
100 | *
101 | * @param string|\DateTimeInterface $dateTime
102 | * @param string $format
103 | * @return string
104 | */
105 | protected function stringifyDateTime($dateTime, $format = 'Y-m-d H:i:s')
106 | {
107 |
108 | if ($dateTime instanceof \DateTimeInterface) {
109 | return $dateTime->format($format);
110 | }
111 |
112 | if (!is_string($dateTime)) {
113 |
114 | throw new InvalidArgumentException(
115 | 'Date time must be either a string or an instance of \DateTimeInterface'
116 | );
117 |
118 | }
119 |
120 | return $dateTime;
121 |
122 | }
123 |
124 | /**
125 | * @param mixed
126 | * @return mixed
127 | */
128 | protected function convertBool($input)
129 | {
130 |
131 | if (!in_array($input, [false, true, 0, 1, '0', '1'], true)) {
132 | return $input;
133 | }
134 |
135 | return $input ? 'yes' : 'no';
136 |
137 | }
138 |
139 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipients/Recipient/Parameter/RecipientImportQueryParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('delimiter', $delimiter);
59 |
60 | return $this;
61 | }
62 |
63 | /**
64 | * Sets the enclosure character. Defaults to "
65 | *
66 | * @param string $enclosure
67 | * @return static
68 | */
69 | public function setEnclosure($enclosure)
70 | {
71 | $this->setAttributeRaw('enclosure', $enclosure);
72 |
73 | return $this;
74 | }
75 |
76 | /**
77 | * Specify handling for recipients that already exist
78 | *
79 | * @param string $mode
80 | * @return static
81 | */
82 | public function setRecipientExists($mode)
83 | {
84 |
85 | if (!in_array($mode, static::RECIPIENT_EXISTS_HANDLING)) {
86 |
87 | throw new InvalidArgumentException(
88 | 'Invalid mode provided. Must be one of: ' . implode(', ', static::RECIPIENT_EXISTS_HANDLING)
89 | );
90 |
91 | }
92 | $this->setAttributeRaw('recipient_exists', $mode);
93 |
94 | return $this;
95 | }
96 |
97 | /**
98 | * Specify handling for recipients that do not yet exist
99 | *
100 | * @param string $mode
101 | * @return static
102 | */
103 | public function setRecipientMissing($mode)
104 | {
105 |
106 | if (!in_array($mode, static::RECIPIENT_MISSING_HANDLING)) {
107 |
108 | throw new InvalidArgumentException(
109 | 'Invalid mode provided. Must be one of: ' . implode(', ', static::RECIPIENT_MISSING_HANDLING)
110 | );
111 |
112 | }
113 | $this->setAttributeRaw('recipient_missing', $mode);
114 |
115 | return $this;
116 | }
117 |
118 | /**
119 | * Specify handling for recipients that have been marked as deleted
120 | *
121 | * @param string $mode
122 | * @return static
123 | */
124 | public function setRecipientDeleted($mode)
125 | {
126 |
127 | if (!in_array($mode, static::RECIPIENT_DELETED_HANDLING)) {
128 |
129 | throw new InvalidArgumentException(
130 | 'Invalid mode provided. Must be one of: ' . implode(', ', static::RECIPIENT_DELETED_HANDLING)
131 | );
132 |
133 | }
134 | $this->setAttributeRaw('recipient_deleted', $mode);
135 |
136 | return $this;
137 | }
138 |
139 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipients/Recipient/Parameter/RecipientQueryParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('recipientlist_id', $recipientlistId);
56 |
57 | return $this;
58 | }
59 |
60 | /**
61 | * Filter recipients by email address
62 | *
63 | * @param string $email
64 | * @return static
65 | */
66 | public function setEmail($email)
67 | {
68 | $this->setAttributeRaw('email', $email);
69 |
70 | return $this;
71 | }
72 |
73 | /**
74 | * Filter recipients by foreign/external ID
75 | *
76 | * @param string $foreignId
77 | * @return static
78 | */
79 | public function setForeignId($foreignId)
80 | {
81 | $this->setAttributeRaw('foreign_id', $foreignId);
82 |
83 | return $this;
84 | }
85 |
86 | /**
87 | * Sets the page to load
88 | *
89 | * @param int $page
90 | * @return static
91 | */
92 | public function setPage($page)
93 | {
94 | $this->setAttributeRaw('page', $page);
95 |
96 | return $this;
97 | }
98 |
99 | /**
100 | * Sets the sort by
101 | *
102 | * @param string $sortBy
103 | * @return static
104 | */
105 | public function setSortBy($sortBy)
106 | {
107 |
108 | if (!in_array($sortBy, static::SORT_BY_VALUES)) {
109 |
110 | throw new InvalidArgumentException(
111 | 'Invalid sort by provided. Must be one of: ' . implode(', ', static::SORT_BY_VALUES)
112 | );
113 |
114 | }
115 |
116 | $this->setAttributeRaw('sort_by', $sortBy);
117 |
118 | return $this;
119 |
120 | }
121 |
122 | /**
123 | * Order to sort in
124 | *
125 | * @param string $sortOrder
126 | * @return static
127 | */
128 | public function setSortOrder($sortOrder)
129 | {
130 |
131 | if (!in_array($sortOrder, static::SORT_ORDER_VALUES)) {
132 |
133 | throw new InvalidArgumentException(
134 | 'Invalid sort order provided. Must be one of: ' . implode(', ', static::SORT_ORDER_VALUES)
135 | );
136 |
137 | }
138 |
139 | $this->setAttributeRaw('sort_order', $sortOrder);
140 |
141 | return $this;
142 |
143 | }
144 |
145 | /**
146 | * Filter by one or more status
147 | *
148 | * @param string|array $status
149 | * @return static
150 | */
151 | public function setStatus($status)
152 | {
153 |
154 | $this->setAttributeRaw('status', $status);
155 |
156 | return $this;
157 |
158 | }
159 |
160 | /**
161 | * If specified, extrabig fields will be returned for each recipient
162 | *
163 | * @param mixed $flag
164 | * @return static
165 | */
166 | public function setGetExtraBigFields($flag)
167 | {
168 |
169 | $this->setAttributeRaw('get_extra_big_fields', $this->convertBool($flag));
170 |
171 | return $this;
172 |
173 | }
174 |
175 | }
--------------------------------------------------------------------------------
/lib/rapidmail/README.md:
--------------------------------------------------------------------------------
1 | #  rapidmail APIv3 client
2 |
3 | API client written in PHP providing access to the current version of the [rapidmail](https://www.rapidmail.de) API.
4 |
5 | [](https://github.com/rapidmail/rapidmail-apiv3-client-php/actions)
6 | [](https://packagist.org/packages/rapidmail/rapidmail-apiv3-client-php)
7 | ## Installation With Composer
8 |
9 | Preferred installation method is to use the [Composer](https://getcomposer.org) dependency manager.
10 |
11 | ```bash
12 | composer require rapidmail/rapidmail-apiv3-client-php
13 | ```
14 |
15 | ## Getting started
16 |
17 | Create a new API client instance and provide your APIv3 credentials:
18 |
19 | ```php
20 | require_once __DIR__ . '/vendor/autoload.php';
21 |
22 | use Rapidmail\ApiClient\Client;
23 |
24 | $client = new Client('api_username_hash', 'api_password_hash');
25 | ```
26 |
27 | After that you can access various services encapsulated within the client:
28 |
29 | ```php
30 | $mailingService = $client->mailings();
31 |
32 | // Iterate all mailings
33 |
34 | foreach($mailingService->query() as $mailing) {
35 | var_dump($mailing);
36 | }
37 | ```
38 |
39 | ## Examples
40 |
41 | ### Retrieve mailings
42 |
43 | Get a list of your mailings with some filters applied:
44 |
45 | ```php
46 | // Filter for sent mailings newer than a given date
47 |
48 | var_dump(
49 | $mailingService->query([
50 | 'created_since' => '2019-09-01 10:22:00',
51 | 'status' => 'sent'
52 | ])
53 | );
54 | ```
55 |
56 | ### Retrieve recipient lists
57 |
58 | ```php
59 | $listService = $client->recipientlists();
60 |
61 | foreach ($listService->query() as $list) {
62 | var_dump($list);
63 | }
64 | ```
65 |
66 | ### Retrieve recipients
67 | ```php
68 | $recipientsService = $client->recipients();
69 |
70 | $collection = $recipientsService->query(
71 | [
72 | 'recipientlist_id' => 123456789 // Recipientlist ID MUST be provided
73 | ]
74 | );
75 |
76 | foreach ($collection as $recipient) {
77 | var_dump($recipient);
78 | }
79 | ```
80 |
81 | ### Create a new recipient
82 | ```php
83 | $recipientsService = $client->recipients();
84 |
85 | var_dump(
86 | $recipientsService->create(
87 | // Dataset: Represents the recipient dataset you're creating
88 | [
89 | 'recipientlist_id' => 123456789, // Required
90 | 'email' => 'john@example.net', // Required
91 | 'firstname' => 'John',
92 | 'lastname' => 'Doe',
93 | 'gender' => 'male'
94 | ],
95 | // Flags: Configures system behavior, like sending activationmails
96 | [
97 | 'send_activationmail' => 'yes'
98 | ]
99 | )
100 | );
101 | ```
102 |
103 | ## Error handling
104 |
105 | Always keep in mind to handle errors properly and catch exceptions that might occur:
106 |
107 | ```php
108 | use \Rapidmail\ApiClient\Exception\ApiClientException;
109 |
110 | try {
111 | $mailingService->query(['status' => 'unknown']);
112 | } catch (ApiClientException $e) {
113 | // Catch API client exceptions
114 | echo "Exception raised: " . $e->getMessage();
115 | }
116 | ```
117 |
118 | ## Documentation
119 |
120 | More information about using the API client can be found in the following subsections:
121 |
122 | * [Available services](/docs/available-services.md)
123 | * [Typed parameters](/docs/typed-parameters.md)
124 |
125 | ## Known issues
126 |
127 | 1. Exceptions on 201 HTTP-Response-Code (used when a dataset was successfully created) are generated when using PHP Versions 7.4.5 and 8.1.2. If you're having issues with these versions, please try updating to a later version of PHP.
128 | 2. Client versions <1.1.6 do not work with guzzlehttp/guzzle 7.8+. Please upgrade to version 1.1.6 or later or downgrade
129 | your version of guzzlehttp/guzzle to 7.7.
130 |
131 | Also refer to the [API documentation](https://developer.rapidmail.wiki/documentation.html) for a complete list of the available endpoints and their parameters.
132 |
133 | ## License
134 |
135 | rapidmail APIv3 client is licensed under the terms of the [BSD 2-clause](LICENSE) license.
136 |
137 | ## Support
138 |
139 | Contact: [www.rapidmail.de](https://www.rapidmail.de) - support@rapidmail.de - +49 761 - 216 08 720
140 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/Response/HalResponseResourceIterator.php:
--------------------------------------------------------------------------------
1 | responseCollection = $responseCollection;
44 | $this->embeddedResourcePathKey = $embeddedResourcePathKey;
45 | }
46 |
47 | /**
48 | * @inheritDoc
49 | */
50 | #[\ReturnTypeWillChange]
51 | public function current()
52 | {
53 | return $this->currentResourceIterator->current();
54 | }
55 |
56 | /**
57 | * @inheritDoc
58 | */
59 | #[\ReturnTypeWillChange]
60 | public function next()
61 | {
62 |
63 | $this->currentResourceIterator->next();
64 |
65 | if (!$this->currentResourceIterator->valid()) {
66 | $this->responseCollection->next();
67 | $this->currentResourceIterator = $this->createIteratorFromInnerResource();
68 | }
69 |
70 | $this->currentIndex++;
71 |
72 | }
73 |
74 | /**
75 | * @inheritDoc
76 | */
77 | #[\ReturnTypeWillChange]
78 | public function key()
79 | {
80 | return $this->currentIndex;
81 | }
82 |
83 | /**
84 | * @inheritDoc
85 | */
86 | #[\ReturnTypeWillChange]
87 | public function valid()
88 | {
89 | return $this->currentResourceIterator !== null && $this->currentResourceIterator->valid();
90 | }
91 |
92 | /**
93 | * @inheritDoc
94 | */
95 | #[\ReturnTypeWillChange]
96 | public function rewind()
97 | {
98 | $this->currentIndex = 0;
99 | $this->responseCollection->rewind();
100 | $this->currentResourceIterator = $this->createIteratorFromInnerResource();
101 | }
102 |
103 | /**
104 | * @inheritDoc
105 | */
106 | #[\ReturnTypeWillChange]
107 | public function count()
108 | {
109 | return $this->responseCollection->totalCount();
110 | }
111 |
112 | /**
113 | * @return null|\Iterator
114 | */
115 | private function createIteratorFromInnerResource()
116 | {
117 |
118 | if (!$this->responseCollection->valid()) {
119 | return null;
120 | }
121 |
122 | /** @var HalResponse $halResponse */
123 | $halResponse = $this->responseCollection->current();
124 |
125 | $canAccessInnerResources = isset($halResponse['_embedded'])
126 | && isset($halResponse['_embedded'][$this->embeddedResourcePathKey]);
127 |
128 | if (!$canAccessInnerResources) {
129 | return null;
130 | }
131 |
132 | $innerResource = $halResponse['_embedded'][$this->embeddedResourcePathKey];
133 |
134 | if (!$innerResource instanceof HalResponse) {
135 | return null;
136 | }
137 |
138 | return $innerResource->getIterator();
139 |
140 | }
141 |
142 | /**
143 | * @return array
144 | */
145 | protected function toArray()
146 | {
147 |
148 | return iterator_to_array(
149 | new CallbackIterator(
150 | $this,
151 | function ($item) {
152 | return $item instanceof HalResponse ? $item->toArray() : $item;
153 | }
154 | )
155 | );
156 |
157 | }
158 |
159 | /**
160 | * @inheritDoc
161 | */
162 | public function __debugInfo()
163 | {
164 | return $this->toArray();
165 | }
166 |
167 | /**
168 | * @inheritDoc
169 | */
170 | public function __toString()
171 | {
172 | return (string)print_r($this->toArray(), true);
173 | }
174 |
175 | }
176 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # YForm Rapidmail für REDAXO 5
2 |
3 | Stellt den Rapidmail PHP-SDK zur Verfügung. Und synchronisiert Email-Adressen mit Empfängerlisten. REDAXO-Add-on für die Newsletter-Software rapidmail, kein offizielles rapidmail-Add-on.
4 |
5 | ## Einrichtung
6 |
7 | 1. API-Zugang bei Rapidmail einrichten
8 | 2. API-Zugang in den Einstellungen YForm > Rapidmail > Einstellungen hinterlegen.
9 | 3. Gewünschte Empfängerliste(n) bei Rapidmail anlegen
10 |
11 | Wenn erfolgreich, dann werden in den Einstellungen die verfügbaren Empfängerlisten und deren IDs angezeigt.
12 |
13 | ## Beispiel-Action
14 |
15 | Voraussetzung:
16 |
17 | * Empfänger-Liste mit bekannter ID, diese als `###LIST_ID###` in der Action verwenden.
18 |
19 | Optional:
20 |
21 | * `newsletter_optin` als Checkbox, um Opt-In DSGVO-konform abzufragen.
22 |
23 | Pipe-Schreibweise
24 |
25 | ```plaintext
26 | checkbox|newsletter_optin|Möchten Sie den Newsletter empfangen?|0|
27 | email|email|E-Mail-Adresse
28 | action|yform_rapidmail|###LIST_ID###|email|newsletter_optin
29 | ```
30 |
31 | PHP-Schreibweise
32 |
33 | ```php
34 | $yform->setValueField('checkbox', ['newsletter_optin','Möchten Sie den Newsletter empfangen?','0','0']);
35 | $yform->setValueField('text', ['email','E-Mail-Adresse','','0','{"type":"email"}','']);
36 | $yform->setActionField('yform_rapidmail', ['###LIST_ID###', 'email', 'newsletter_optin']);
37 | ```
38 | Vollständige Definition:
39 |
40 | ```
41 | action|yform_rapidmail|list_id|email_fieldname(e.g. email)|opt:optin_fieldname(e.g. newsletter)|opt:fieldname_fullname(fullname)
42 | ```
43 |
44 | ## Beispiel für eigene Nutzung / Ausgabe / etc
45 |
46 | ```php
47 |
48 | recipients();
55 |
56 | /*
57 |
58 | $collection = $recipientsService->query(
59 | [
60 | 'recipientlist_id' => rex_config::get('yform_rapidmail', 'sh_group_list_id') // Recipientlist ID MUST be provided
61 | ]
62 | );
63 |
64 | foreach ($collection as $recipient) {
65 | // dump($recipient);
66 | // Echo additional properties of $recipient individually
67 | echo $recipient['recipientlist_id'] . '
';
68 | echo $recipient['email'] . '
';
69 | echo $recipient['firstname'] . '
';
70 | echo $recipient['lastname'] . '
';
71 | echo $recipient['gender'] . '
';
72 | echo $recipient['title'] . '
';
73 | echo $recipient['zip'] . '
';
74 | echo $recipient['birthdate'] . '
';
75 | echo $recipient['extra1'] . '
';
76 | echo $recipient['extra2'] . '
';
77 | echo $recipient['extra3'] . '
';
78 | echo $recipient['extra4'] . '
';
79 | echo $recipient['extra5'] . '
';
80 | echo $recipient['extra6'] . '
';
81 | echo $recipient['extra7'] . '
';
82 | echo $recipient['extra8'] . '
';
83 | echo $recipient['extra9'] . '
';
84 | echo $recipient['extra10'] . '
';
85 | echo $recipient['mailtype'] . '
';
86 | echo $recipient['foreign_id'] . '
';
87 | echo $recipient['created_ip'] . '
';
88 | echo $recipient['created_host'] . '
';
89 | echo $recipient['created'] . '
';
90 | echo $recipient['updated'] . '
';
91 | echo $recipient['status'] . '
';
92 | // Add more properties as needed
93 | }
94 | */
95 |
96 |
97 | // https://developer.rapidmail.wiki/documentation.html?urls.primaryName=Recipients#/RecipientImport/post_recipients_import
98 | $import = [];
99 | $import['recipientlist_id'] = rex_config::get('yform_rapidmail', 'sh_group_list_id');
100 | $import['file']['type'] = "text/csv";
101 | $import['file']['content'] = base64_encode(rex_file::get(rex_path::addon('yform_rapidmail', 'rapidmail.csv')));
102 |
103 | $config = [];
104 | $config['recipient_exists'] = "importfile";
105 | $config['recipient_missing'] = "softdelete";
106 | $config['recipient_deleted'] = "import";
107 | $config['test_mode'] = "yes";
108 | $response = $recipientsService->import($import, $config);
109 |
110 | dump($response);
111 |
112 | ```
113 |
114 | ## Lizenz
115 |
116 | [MIT Lizenz](LICENSE)
117 | Bitte Lizenzbedingungen des Drittanbieters (Rapidmail PHP-SDK) beachten!
118 |
119 | ## Autor
120 |
121 | **Friends Of REDAXO**
122 | http://www.redaxo.org
123 | https://github.com/FriendsOfREDAXO
124 |
125 | **Projekt-Lead**
126 | [Alexander Walther](https://github.com/alexplusde)
127 |
128 | ## Credits
129 | [@alexplusde](https://github.com/sponsors/alexplusde) (Initiator)
130 | [rapidmail APIv3 client](https://github.com/rapidmail/rapidmail-apiv3-client-php)
131 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/Response/HalResponse.php:
--------------------------------------------------------------------------------
1 | client = $client;
43 | $this->responseFactory = $responseFactory;
44 |
45 | if (isset($data['_links'])) {
46 | $this->links = $data['_links'];
47 | unset($data['_links']);
48 | }
49 |
50 | $data = array_map(
51 | function ($item) {
52 | return is_array($item) ? new static($this->client, $this->responseFactory, $item) : $item;
53 | },
54 | $data
55 | );
56 |
57 | $this->data = $data;
58 | }
59 |
60 | /**
61 | * @inheritDoc
62 | */
63 | #[\ReturnTypeWillChange]
64 | public function offsetExists($offset)
65 | {
66 | return isset($this->data[$offset]);
67 | }
68 |
69 | /**
70 | * @inheritDoc
71 | */
72 | #[\ReturnTypeWillChange]
73 | public function offsetGet($offset)
74 | {
75 | return $this->data[$offset];
76 | }
77 |
78 | /**
79 | * @inheritDoc
80 | */
81 | #[\ReturnTypeWillChange]
82 | public function offsetSet($offset, $value)
83 | {
84 | throw new NotImplementedException('Write access is not implemented for ' . static::class);
85 | }
86 |
87 | /**
88 | * @inheritDoc
89 | */
90 | #[\ReturnTypeWillChange]
91 | public function offsetUnset($offset)
92 | {
93 | throw new NotImplementedException('Write access is not implemented for ' . static::class);
94 | }
95 |
96 | /**
97 | * @return array
98 | */
99 | public function toArray()
100 | {
101 |
102 | return array_map(
103 | function ($item) {
104 | return $item instanceof static ? $item->toArray() : $item;
105 | },
106 | $this->data
107 | );
108 |
109 | }
110 |
111 | /**
112 | * @inheritDoc
113 | */
114 | public function __debugInfo()
115 | {
116 | return $this->toArray();
117 | }
118 |
119 | /**
120 | * @inheritDoc
121 | */
122 | public function __toString()
123 | {
124 | return (string)print_r($this->toArray(), true);
125 | }
126 |
127 | /**
128 | * @return HalResponse
129 | */
130 | public function self()
131 | {
132 | return $this;
133 | }
134 |
135 | /**
136 | * @return HalResponse|null
137 | * @throws ApiException
138 | */
139 | public function next()
140 | {
141 | return $this->navigate('next');
142 | }
143 |
144 | /**
145 | * @return HalResponse|null
146 | * @throws ApiException
147 | */
148 | public function prev()
149 | {
150 | return $this->navigate('prev');
151 | }
152 |
153 | /**
154 | * @return HalResponse|null
155 | * @throws ApiException
156 | */
157 | public function first()
158 | {
159 | return $this->navigate('first');
160 | }
161 |
162 | /**
163 | * @return HalResponse|null
164 | * @throws ApiException
165 | */
166 | public function last()
167 | {
168 | return $this->navigate('last');
169 | }
170 |
171 | /**
172 | * Navigate Hal links
173 | *
174 | * @param string $target
175 | * @return HalResponse|null
176 | * @throws ApiException
177 | */
178 | protected function navigate($target)
179 | {
180 |
181 | if (!isset($this->links[$target]) || !isset($this->links[$target]['href'])) {
182 | return null;
183 | }
184 |
185 | return $this->responseFactory->newHalResponse(
186 | $this->client,
187 | $this
188 | ->client
189 | ->request(
190 | 'GET',
191 | $this->links[$target]['href']
192 | )
193 | );
194 |
195 | }
196 |
197 | /**
198 | * @inheritDoc
199 | */
200 | #[\ReturnTypeWillChange]
201 | public function getIterator()
202 | {
203 | return new \ArrayIterator($this->data);
204 | }
205 |
206 | }
207 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/Mailing/Parameter/MailingCreateParam.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
25 | parent::__construct($attributes);
26 | }
27 |
28 | /**
29 | * @inheritDoc
30 | */
31 | protected function getKnownAttributeKeys()
32 | {
33 | return [
34 | 'from_name',
35 | 'from_email',
36 | 'subject',
37 | 'file',
38 | 'destinations',
39 | 'send_at'
40 | ];
41 | }
42 |
43 | /**
44 | * Sets the name of mailing sender
45 | *
46 | * @param string $name
47 | * @return static
48 | */
49 | public function setFromName($name)
50 | {
51 | $this->setAttributeRaw('from_name', $name);
52 |
53 | return $this;
54 | }
55 |
56 | /**
57 | * Sets the email address of mailing sender. Note that the address needs to be a confirmed sender address
58 | *
59 | * @param string $email
60 | * @return static
61 | */
62 | public function setFromEmail($email)
63 | {
64 | $this->setAttributeRaw('from_email', $email);
65 |
66 | return $this;
67 | }
68 |
69 | /**
70 | * Sets the mailing subject
71 | *
72 | * @param string $subject
73 | * @return static
74 | */
75 | public function setSubject($subject)
76 | {
77 | $this->setAttributeRaw('subject', $subject);
78 |
79 | return $this;
80 | }
81 |
82 | /**
83 | * Sets the zip file containing all mailing content
84 | *
85 | * @param MailingCreateParamFileAttr|array|string|\SplFileInfo $file
86 | * @return static
87 | */
88 | public function setFile($file)
89 | {
90 |
91 | if ($file instanceof MailingCreateParamFileAttr) {
92 | $this->setAttributeRaw('file', $file);
93 |
94 | return $this;
95 | }
96 |
97 | if (is_array($file)) {
98 | $this->setAttributeRaw('file', $this->parameterFactory->newMailingCreateParamFileAttr($file));
99 |
100 | return $this;
101 | }
102 |
103 | $info = new \finfo(FILEINFO_MIME_TYPE);
104 |
105 | if ($file instanceof \SplFileInfo || is_file($file)) {
106 |
107 | if (!is_readable($file)) {
108 | throw new InvalidArgumentException("File {$file} is not readable");
109 | }
110 |
111 | $fileAttr = $this->parameterFactory->newMailingCreateParamFileAttr([
112 | 'content' => base64_encode(file_get_contents($file)),
113 | 'type' => $info->file($file)
114 | ]);
115 |
116 | $this->setAttributeRaw('file', $fileAttr);
117 |
118 | return $this;
119 |
120 | }
121 |
122 | throw new InvalidArgumentException("{$file} does not appear to be a valid file");
123 |
124 | }
125 |
126 | /**
127 | * Sets mailing destinations
128 | *
129 | * @return static
130 | * @var array[]|array[][]|MailingCreateParamDestinationAttr[] $destinations
131 | */
132 | public function setDestinations(array $destinations)
133 | {
134 |
135 | $parameter = [];
136 |
137 | foreach ($destinations as $key => $destination) {
138 |
139 | if ($destination instanceof MailingCreateParamDestinationAttr) {
140 | $parameter[$key] = $destination;
141 | continue;
142 | }
143 |
144 | if (is_numeric($destination)) {
145 |
146 | // Assume a recipient list ID was provided
147 | $parameter[$key] = $this->parameterFactory->newMailingCreateParamDestinationAttr()->setId($destination);
148 | continue;
149 | }
150 |
151 | if (is_array($destination)) {
152 | $parameter[$key] = $this->parameterFactory->newMailingCreateParamDestinationAttr($destination);
153 | continue;
154 | }
155 |
156 | throw new InvalidArgumentException(
157 | 'Destination must be either an array or instance of MailingCreateParamDestinationAttr'
158 | );
159 |
160 | }
161 |
162 | $this->setAttributeRaw('destinations', $this->parameterFactory->newGenericParameter($parameter));
163 |
164 | return $this;
165 |
166 | }
167 |
168 | /**
169 | * Sets the mailings send at date and time
170 | *
171 | * @param string|\DateTimeInterface $dateTime
172 | *
173 | * @return static
174 | */
175 | public function setSendAt($dateTime)
176 | {
177 | $this->setAttributeRaw('send_at', $this->stringifyDateTime($dateTime));
178 |
179 | return $this;
180 | }
181 |
182 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/ApiUsers/ApiUser/ApiUserService.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
41 | parent::__construct($client, $responseFactory);
42 | }
43 |
44 | /**
45 | * @return ParameterFactory
46 | */
47 | public function params()
48 | {
49 | return $this->parameterFactory;
50 | }
51 |
52 | /**
53 | * @inheritDoc
54 | */
55 | protected function getResourcePath()
56 | {
57 | return 'apiusers';
58 | }
59 |
60 | /**
61 | * Get a list of API users
62 | *
63 | * @param array|ApiUserQueryParam $filter
64 | * @return HalResponseResourceIterator
65 | * @throws ApiException
66 | */
67 | public function query($filter = [])
68 | {
69 |
70 | if (is_array($filter)) {
71 | $filter = $this->params()->newQueryParam($filter);
72 | }
73 |
74 | if (!$filter instanceof ApiUserQueryParam) {
75 | throw new InvalidArgumentException('Invalid filter provided. Must be an array or ApiUserQueryParam');
76 | }
77 |
78 | return $this->responseFactory->newHalResponseResourceIterator(
79 | $this->client,
80 | 'apiusers',
81 | $this->_query(
82 | $filter->toArray()
83 | )
84 | );
85 |
86 | }
87 |
88 | /**
89 | * Get details about an API user
90 | *
91 | * @param string
92 | * @return HalResponse
93 | * @throws ApiException
94 | */
95 | public function get($apiUserId)
96 | {
97 |
98 | return $this->responseFactory->newHalResponse(
99 | $this->client,
100 | $this->_get($apiUserId)
101 | );
102 |
103 | }
104 |
105 | /**
106 | * Delete a single API user
107 | *
108 | * @param int $apiUserId
109 | * @return bool
110 | *
111 | * @throws ApiException
112 | */
113 | public function delete($apiUserId)
114 | {
115 | return $this->_delete($apiUserId)->getStatusCode() == 204;
116 | }
117 |
118 | /**
119 | * Creates or updates an API user
120 | *
121 | * @param string $method
122 | * @param string $uri
123 | * @param array|ApiUserCreateParam $data
124 | * @return HalResponse
125 | * @throws ApiException
126 | */
127 | private function upsert($method, $uri, $data)
128 | {
129 |
130 | if (is_array($data)) {
131 | $data = $this->params()->newCreateParam($data);
132 | }
133 |
134 | if (!$data instanceof ApiUserCreateParam) {
135 |
136 | throw new InvalidArgumentException(
137 | 'Invalid filter provided. Must be an array or ApiUserCreateParam'
138 | );
139 |
140 | }
141 |
142 | $response = $this->client->request(
143 | $method,
144 | $uri,
145 | [
146 | RequestOptions::JSON => $data->toArray(),
147 | ]
148 |
149 | );
150 |
151 | return $this->responseFactory->newHalResponse($this->client, $response);
152 | }
153 |
154 | /**
155 | * Create a new API user
156 | *
157 | * Username and password will be created automatically.
158 | *
159 | * @param array|ApiUserCreateParam $data
160 | * @return HalResponse
161 | * @throws ApiException
162 | */
163 | public function create($data = [])
164 | {
165 |
166 | return $this->upsert(
167 | 'POST',
168 | $this->getResourcePath(),
169 | $data
170 | );
171 |
172 | }
173 |
174 | /**
175 | * Partially update an API user
176 | *
177 | * @param int $apiUserId
178 | * @param array|ApiUserCreateParam $data
179 | * @return HalResponse
180 | * @throws ApiException
181 | */
182 | public function update($apiUserId, $data = [])
183 | {
184 |
185 | return $this->upsert(
186 | 'PATCH',
187 | "{$this->getResourcePath()}/{$apiUserId}",
188 | $data
189 | );
190 |
191 | }
192 |
193 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Mailings/Mailing/MailingService.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
42 | }
43 |
44 | /**
45 | * @inheritDoc
46 | */
47 | protected function getResourcePath()
48 | {
49 | return 'mailings';
50 | }
51 |
52 | /**
53 | * @return ParameterFactory
54 | */
55 | public function params()
56 | {
57 | return $this->parameterFactory;
58 | }
59 |
60 | /**
61 | * Get detailed info about single mailing
62 | *
63 | * @param int $mailingId
64 | * @return HalResponse
65 | *
66 | * @throws ApiException
67 | */
68 | public function get($mailingId)
69 | {
70 |
71 | return $this->responseFactory->newHalResponse(
72 | $this->client,
73 | $this->_get($mailingId)
74 | );
75 |
76 | }
77 |
78 | /**
79 | * List all mailings
80 | *
81 | * @param MailingQueryParam|array $filter
82 | * @return HalResponseResourceIterator
83 | *
84 | * @throws ApiException
85 | */
86 | public function query($filter = [])
87 | {
88 |
89 | if (is_array($filter)) {
90 | $filter = $this->params()->newQueryParam($filter);
91 | }
92 |
93 | if (!$filter instanceof MailingQueryParam) {
94 |
95 | throw new InvalidArgumentException(
96 | 'Invalid filter provided. Must be an array or MailingQueryParam'
97 | );
98 |
99 | }
100 |
101 | return $this->responseFactory->newHalResponseResourceIterator(
102 | $this->client,
103 | 'mailings',
104 | $this->_query(
105 | $filter->toArray()
106 | )
107 | );
108 |
109 | }
110 |
111 | /**
112 | * Delete a single mailing
113 | *
114 | * @param int $mailingId
115 | * @return bool
116 | *
117 | * @throws ApiException
118 | */
119 | public function delete($mailingId)
120 | {
121 | return $this->_delete($mailingId)->getStatusCode() == 204;
122 | }
123 |
124 | /**
125 | * Pause a mailing
126 | *
127 | * @param int $mailingId
128 | * @return bool
129 | *
130 | * @throws ApiException
131 | */
132 | public function pause($mailingId)
133 | {
134 | return $this
135 | ->client
136 | ->request(
137 | 'POST',
138 | "{$this->getResourcePath()}/{$mailingId}/pause"
139 | )
140 | ->getStatusCode() == 200;
141 | }
142 |
143 | /**
144 | * Cancel a mailing
145 | *
146 | * @param int $mailingId
147 | * @param string $reason
148 | * @return bool
149 | *
150 | * @throws ApiException
151 | */
152 | public function cancel($mailingId, $reason)
153 | {
154 | return $this
155 | ->client
156 | ->request(
157 | 'POST',
158 | "{$this->getResourcePath()}/{$mailingId}/cancel",
159 | [
160 | RequestOptions::JSON => [
161 | "reason" => $reason
162 | ]
163 | ]
164 | )
165 | ->getStatusCode() == 200;
166 |
167 | }
168 |
169 | /**
170 | * Create a new mailing using zip file content
171 | *
172 | * @param array|MailingCreateParam $data
173 | * @return HalResponse
174 | * @throws ApiException
175 | */
176 | public function create($data = [])
177 | {
178 |
179 | if (is_array($data)) {
180 | $data = $this->params()->newCreateParam($data);
181 | }
182 |
183 | if (!$data instanceof MailingCreateParam) {
184 |
185 | throw new InvalidArgumentException(
186 | 'Invalid filter provided. Must be an array or MailingCreateParam'
187 | );
188 |
189 | }
190 |
191 | $response =
192 | $this->client->request(
193 | 'POST',
194 | $this->getResourcePath(),
195 | [
196 | RequestOptions::JSON => $data->toArray()
197 | ]
198 |
199 | );
200 |
201 | return $this->responseFactory->newHalResponse($this->client, $response);
202 |
203 | }
204 |
205 | }
206 |
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipients/Recipient/Parameter/RecipientCreateParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('email', $email);
60 |
61 | return $this;
62 | }
63 |
64 | /**
65 | * Sets the recipientlist ID the recipient is assigned to (required)
66 | *
67 | * @param int $recipientlistId
68 | * @return static
69 | */
70 | public function setRecipientlistId($recipientlistId)
71 | {
72 | $this->setAttributeRaw('recipientlist_id', $recipientlistId);
73 |
74 | return $this;
75 | }
76 |
77 | /**
78 | * Sets the firstname
79 | *
80 | * @param string $firstname
81 | * @return static
82 | */
83 | public function setFirstname($firstname)
84 | {
85 | $this->setAttributeRaw('firstname', $firstname);
86 |
87 | return $this;
88 | }
89 |
90 | /**
91 | * Sets the lastname
92 | *
93 | * @param string $lastname
94 | * @return static
95 | */
96 | public function setLastname($lastname)
97 | {
98 | $this->setAttributeRaw('lastname', $lastname);
99 |
100 | return $this;
101 | }
102 |
103 | /**
104 | * Sets the gender
105 | *
106 | * @param string $gender
107 | * @return static
108 | */
109 | public function setGender($gender)
110 | {
111 |
112 | if (!in_array($gender, static::GENDER)) {
113 |
114 | throw new InvalidArgumentException(
115 | 'Invalid gender provided. Must be one of: ' . implode(', ', static::GENDER)
116 | );
117 |
118 | }
119 |
120 | $this->setAttributeRaw('gender', $gender);
121 |
122 | return $this;
123 | }
124 |
125 | /**
126 | * Sets the title
127 | *
128 | * @param string $title
129 | * @return static
130 | */
131 | public function setTitle($title)
132 | {
133 | $this->setAttributeRaw('title', $title);
134 |
135 | return $this;
136 | }
137 |
138 | /**
139 | * Sets the zip code
140 | *
141 | * @param string $zip
142 | * @return static
143 | */
144 | public function setZip($zip)
145 | {
146 | $this->setAttributeRaw('zip', $zip);
147 |
148 | return $this;
149 | }
150 |
151 | /**
152 | * Sets the birthdate
153 | *
154 | * @param string|\DateTimeInterface $birthdate
155 | * @return static
156 | */
157 | public function setBirthdate($birthdate)
158 | {
159 | $this->setAttributeRaw('birthdate', $this->stringifyDateTime($birthdate, 'Y-m-d'));
160 |
161 | return $this;
162 | }
163 |
164 | /**
165 | * Sets the foreign/external ID
166 | *
167 | * @param mixed $foreignId
168 | * @return static
169 | */
170 | public function setForeignId($foreignId)
171 | {
172 | $this->setAttributeRaw('foreign_id', $foreignId);
173 |
174 | return $this;
175 | }
176 |
177 | /**
178 | * Sets the mailtype specifying if recipient wants text or html email
179 | *
180 | * @param string $mailtype
181 | * @return static
182 | */
183 | public function setMailtype($mailtype)
184 | {
185 |
186 | if (!in_array($mailtype, static::MAILTYPES)) {
187 |
188 | throw new InvalidArgumentException(
189 | 'Invalid mailtype provided. Must be one of: ' . implode(', ', static::MAILTYPES)
190 | );
191 |
192 | }
193 |
194 | $this->setAttributeRaw('mailtype', $mailtype);
195 |
196 | return $this;
197 | }
198 |
199 | /**
200 | * Sets the created IP
201 | *
202 | * @param string $createdIp
203 | * @return static
204 | */
205 | public function setCreatedIp($createdIp)
206 | {
207 | $this->setAttributeRaw('created_ip', $createdIp);
208 |
209 | return $this;
210 | }
211 |
212 | /**
213 | * Sets the created host name
214 | *
215 | * @param string $createdHost
216 | * @return static
217 | */
218 | public function setCreatedHost($createdHost)
219 | {
220 | $this->setAttributeRaw('created_host', $createdHost);
221 |
222 | return $this;
223 | }
224 |
225 | /**
226 | * Sets the datetime the recipient was activated
227 | *
228 | * @param string|\DateTimeInterface $activated
229 | * @return static
230 | */
231 | public function setActivated($activated)
232 | {
233 | $this->setAttributeRaw('activated', $this->stringifyDateTime($activated));
234 |
235 | return $this;
236 | }
237 |
238 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Blacklist/Blacklist/BlacklistService.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
42 | parent::__construct($client, $responseFactory);
43 | }
44 |
45 | /**
46 | * @inheritDoc
47 | */
48 | protected function getResourcePath()
49 | {
50 | return 'blacklist';
51 | }
52 |
53 | /**
54 | * @return ParameterFactory
55 | */
56 | public function params()
57 | {
58 | return $this->parameterFactory;
59 | }
60 |
61 | /**
62 | * Get list of blacklist entries
63 | *
64 | * @param array|BlacklistQueryParam $filter
65 | * @return HalResponseResourceIterator
66 | *
67 | * @throws ApiException
68 | */
69 | public function query($filter = [])
70 | {
71 |
72 | if (is_array($filter)) {
73 | $filter = $this->params()->newQueryParam($filter);
74 | }
75 |
76 | if (!$filter instanceof BlacklistQueryParam) {
77 |
78 | throw new InvalidArgumentException(
79 | 'Invalid filter provided. Must be an array or BlacklistQueryParam'
80 | );
81 |
82 | }
83 |
84 | return $this->responseFactory->newHalResponseResourceIterator(
85 | $this->client,
86 | 'blacklist',
87 | $this->_query(
88 | $filter->toArray()
89 | )
90 | );
91 |
92 | }
93 |
94 | /**
95 | * Create a new blacklist entry
96 | *
97 | * @param string|array|BlacklistCreateParam $data
98 | * @return HalResponse
99 | * @throws ApiException
100 | */
101 | public function create($data = [])
102 | {
103 |
104 | if (is_string($data)) {
105 |
106 | // Assume pattern was provided
107 |
108 | $data = $this->params()->newCreateParam()->setPattern($data);
109 | }
110 |
111 | if (is_array($data)) {
112 | $data = $this->params()->newCreateParam($data);
113 | }
114 |
115 | if (!$data instanceof BlacklistCreateParam) {
116 |
117 | throw new InvalidArgumentException(
118 | 'Invalid filter provided. Must be an array or MailingCreateParam'
119 | );
120 |
121 | }
122 |
123 | $response =
124 | $this->client->request(
125 | 'POST',
126 | $this->getResourcePath(),
127 | [
128 | RequestOptions::JSON => $data->toArray()
129 | ]
130 |
131 | );
132 |
133 | return $this->responseFactory->newHalResponse($this->client, $response);
134 |
135 | }
136 |
137 | /**
138 | * Get info about a single blacklist entry
139 | *
140 | * @param int $blacklistId
141 | * @return HalResponse
142 | *
143 | * @throws ApiException
144 | */
145 | public function get($blacklistId)
146 | {
147 |
148 | return $this->responseFactory->newHalResponse(
149 | $this->client,
150 | $this->_get($blacklistId)
151 | );
152 |
153 | }
154 |
155 | /**
156 | * Delete blacklist entry by ID
157 | *
158 | * @param int $blacklistId
159 | * @return bool
160 | * @throws ApiException
161 | */
162 | public function delete($blacklistId)
163 | {
164 | return $this->_delete($blacklistId)->getStatusCode() == 204;
165 | }
166 |
167 | /**
168 | * Import blacklist from CSV file
169 | *
170 | * The CSV file needs to contain the blacklist patterns in the first column only.
171 | * Additional fields cannot be imported. A header line is not supported.
172 | *
173 | * @param string|\SplFileInfo|array|BlacklistImportParam $data
174 | * @return HalResponse
175 | * @throws ApiException
176 | */
177 | public function import($data = [])
178 | {
179 |
180 | if (is_string($data) || $data instanceof \SplFileInfo) {
181 |
182 | // Assume a file is provided
183 |
184 | $data = $this->params()->newImportParam()->setFile($data);
185 |
186 | }
187 |
188 | if (is_array($data)) {
189 | $data = $this->params()->newImportParam($data);
190 | }
191 |
192 | if (!$data instanceof BlacklistImportParam) {
193 |
194 | throw new InvalidArgumentException(
195 | 'Invalid filter provided. Must be an array or BlacklistImportParam'
196 | );
197 |
198 | }
199 |
200 | $response =
201 | $this->client->request(
202 | 'POST',
203 | "{$this->getResourcePath()}/import",
204 | [
205 | RequestOptions::JSON => $data->toArray()
206 | ]
207 |
208 | );
209 |
210 | return $this->responseFactory->newHalResponse($this->client, $response);
211 |
212 | }
213 |
214 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Client.php:
--------------------------------------------------------------------------------
1 | [
45 | isset($args[0]) && is_string($args[0]) ? $args[0] : '',
46 | isset($args[1]) && is_string($args[1]) ? $args[1] : ''
47 | ]
48 | ];
49 |
50 | // Assume a configuration array was provided
51 |
52 | if (isset($args[0]) && is_array($args[0])) {
53 | $config = $args[0];
54 | }
55 |
56 | // Assume
57 |
58 | (new PlatformRequirements())->assertPlatformRequirements();
59 |
60 | $this->serviceFactory = new ServiceFactory(
61 | new HttpClientFactory(),
62 | $config
63 | );
64 |
65 | }
66 |
67 | /**
68 | * Creates a new mailing service
69 | *
70 | * @param string|null $version
71 | * @return \Rapidmail\ApiClient\Service\V1\Api\Mailings\Mailing\MailingService
72 | * @throws NotImplementedException
73 | */
74 | public function mailings($version = null)
75 | {
76 | /** @noinspection PhpIncompatibleReturnTypeInspection */
77 | return $this->serviceFactory->createService('mailings', $version);
78 | }
79 |
80 | /**
81 | * Creates a new mailing recipients service
82 | *
83 | * @param string|null $version
84 | * @return \Rapidmail\ApiClient\Service\V1\Api\Mailings\MailingRecipients\MailingRecipientsService
85 | * @throws NotImplementedException
86 | */
87 | public function mailingRecipients($version = null)
88 | {
89 | /** @noinspection PhpIncompatibleReturnTypeInspection */
90 | return $this->serviceFactory->createService('mailing_recipients', $version);
91 | }
92 |
93 | /**
94 | * Creates a new mailing stats service
95 | *
96 | * @param string|null $version
97 | * @return \Rapidmail\ApiClient\Service\V1\Api\Mailings\MailingStats\MailingStatsService
98 | * @throws NotImplementedException
99 | */
100 | public function mailingStats($version = null)
101 | {
102 | /** @noinspection PhpIncompatibleReturnTypeInspection */
103 | return $this->serviceFactory->createService('mailing_stats', $version);
104 | }
105 |
106 | /**
107 | * Creates a new mailing stats anonymize service
108 | *
109 | * @param string|null $version
110 | * @return \Rapidmail\ApiClient\Service\V1\Api\Mailings\MailingStatsAnonymize\MailingStatsAnonymizeService
111 | * @throws NotImplementedException
112 | */
113 | public function mailingStatsAnonymize($version = null)
114 | {
115 | /** @noinspection PhpIncompatibleReturnTypeInspection */
116 | return $this->serviceFactory->createService('mailing_stats_anonymize', $version);
117 | }
118 |
119 | /**
120 | * Creates a new API service to manage recipientlists
121 | *
122 | * @param string|null $version
123 | * @return \Rapidmail\ApiClient\Service\V1\Api\Recipientlists\Recipientlist\RecipientlistService
124 | * @throws NotImplementedException
125 | */
126 | public function recipientlists($version = null)
127 | {
128 | /** @noinspection PhpIncompatibleReturnTypeInspection */
129 | return $this->serviceFactory->createService('recipientlists', $version);
130 | }
131 |
132 | /**
133 | * Creates a new API service to manage recipients
134 | *
135 | * @param string|null $version
136 | * @return \Rapidmail\ApiClient\Service\V1\Api\Recipients\Recipient\RecipientService
137 | * @throws NotImplementedException
138 | */
139 | public function recipients($version = null)
140 | {
141 | /** @noinspection PhpIncompatibleReturnTypeInspection */
142 | return $this->serviceFactory->createService('recipients', $version);
143 | }
144 |
145 | /**
146 | * Creates a new API service to manage jobs
147 | *
148 | * @param string|null $version
149 | * @return \Rapidmail\ApiClient\Service\V1\Api\Jobs\Job\JobService
150 | * @throws NotImplementedException
151 | */
152 | public function jobs($version = null)
153 | {
154 | /** @noinspection PhpIncompatibleReturnTypeInspection */
155 | return $this->serviceFactory->createService('jobs', $version);
156 | }
157 |
158 | /**
159 | * Creates a new API service to fetch transactional emails
160 | *
161 | * @param string|null $version
162 | * @return \Rapidmail\ApiClient\Service\V1\Api\TrxEmails\TrxEmail\TrxEmailService
163 | * @throws NotImplementedException
164 | */
165 | public function transactionEmails($version = null)
166 | {
167 | /** @noinspection PhpIncompatibleReturnTypeInspection */
168 | return $this->serviceFactory->createService('trx_emails', $version);
169 | }
170 |
171 | /**
172 | * Creates a new API service to manage API users
173 | *
174 | * @param string|null $version
175 | * @return \Rapidmail\ApiClient\Service\V1\Api\ApiUsers\ApiUser\ApiUserService
176 | * @throws NotImplementedException
177 | */
178 | public function apiUsers($version = null)
179 | {
180 | /** @noinspection PhpIncompatibleReturnTypeInspection */
181 | return $this->serviceFactory->createService('apiusers', $version);
182 | }
183 |
184 | /**
185 | * Creates a new API service to manage blacklist entries
186 | *
187 | * @param string|null $version
188 | * @return \Rapidmail\ApiClient\Service\V1\Api\Blacklist\Blacklist\BlacklistService
189 | * @throws NotImplementedException
190 | */
191 | public function blacklist($version = null)
192 | {
193 | /** @noinspection PhpIncompatibleReturnTypeInspection */
194 | return $this->serviceFactory->createService('blacklist', $version);
195 | }
196 |
197 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipientlists/Recipientlist/RecipientlistService.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
41 | parent::__construct($client, $responseFactory);
42 | }
43 |
44 | /**
45 | * @inheritDoc
46 | */
47 | protected function getResourcePath()
48 | {
49 | return 'recipientlists';
50 | }
51 |
52 | /**
53 | * @return ParameterFactory
54 | */
55 | public function params()
56 | {
57 | return $this->parameterFactory;
58 | }
59 |
60 | /**
61 | * Get a list of recipientlists from current account
62 | *
63 | * @param array $filter
64 | * @return HalResponseResourceIterator
65 | * @throws ApiException
66 | */
67 | public function query($filter = [])
68 | {
69 |
70 | return $this
71 | ->responseFactory
72 | ->newHalResponseResourceIterator(
73 | $this->client,
74 | 'recipientlists',
75 | $this->_query(
76 | $filter
77 | )
78 | );
79 |
80 | }
81 |
82 | /**
83 | * Create a new recipientlist
84 | *
85 | * @param string|array|RecipientlistCreateParam
86 | * @return HalResponse
87 | * @throws ApiException
88 | */
89 | public function create($data = [])
90 | {
91 |
92 | $method = 'POST';
93 | $uri = $this->getResourcePath();
94 |
95 | return $this->upsert($method, $uri, $data);
96 |
97 | }
98 |
99 | /**
100 | * Get details for a specific recipientlist
101 | *
102 | * @param int $recipientlistId
103 | * @return HalResponse
104 | * @throws ApiException
105 | */
106 | public function get($recipientlistId)
107 | {
108 |
109 | return $this
110 | ->responseFactory
111 | ->newHalResponse(
112 | $this->client,
113 | $this->_get($recipientlistId)
114 | );
115 |
116 | }
117 |
118 | /**
119 | * Delete recipientlist specified by ID
120 | *
121 | * @param int $recipientlistId
122 | * @return bool
123 | * @throws ApiException
124 | */
125 | public function delete($recipientlistId)
126 | {
127 | return $this->_delete($recipientlistId)->getStatusCode() == 204;
128 | }
129 |
130 | /**
131 | * Update a specific recipientlist allowing partial updates
132 | *
133 | * @param int $recipientlistId
134 | * @param string|array|RecipientlistCreateParam $data
135 | * @return HalResponse
136 | * @throws ApiException
137 | */
138 | public function update($recipientlistId, $data = [])
139 | {
140 |
141 | $method = 'PATCH';
142 | $uri = "{$this->getResourcePath()}/{$recipientlistId}";
143 |
144 | return $this->upsert($method, $uri, $data);
145 |
146 | }
147 |
148 | /**
149 | * Get activity stats for a specific recipientlist
150 | *
151 | * @param int $recipientlistId
152 | * @param array|RecipientlistActivityStatsParam $filter
153 | * @return HalResponse
154 | * @throws ApiException
155 | */
156 | public function activityStats($recipientlistId, $filter = [])
157 | {
158 |
159 | if (is_array($filter)) {
160 | $filter = $this->params()->newActivityStatsParam($filter);
161 | }
162 |
163 | if (!$filter instanceof RecipientlistActivityStatsParam) {
164 |
165 | throw new InvalidArgumentException(
166 | 'Invalid filter provided. Must be an array or RecipientlistActivityStatsParam'
167 | );
168 |
169 | }
170 |
171 | return $this
172 | ->responseFactory
173 | ->newHalResponse(
174 | $this->client,
175 | $this->client->request(
176 | 'GET',
177 | "{$this->getResourcePath()}/{$recipientlistId}/stats/activity",
178 | [
179 | 'query' => $filter->toArray()
180 | ]
181 | )
182 |
183 | );
184 |
185 | }
186 |
187 | /**
188 | * Creates or updates a recipientlist
189 | *
190 | * @param string $method
191 | * @param string $uri
192 | * @param array|RecipientlistCreateParam $data
193 | * @return HalResponse
194 | * @throws ApiException
195 | */
196 | private function upsert($method, $uri, $data = [])
197 | {
198 |
199 | if (is_string($data)) {
200 |
201 | // Assume recipientlist name
202 |
203 | $data = $this->params()->newCreateParam()->setName($data);
204 |
205 | }
206 |
207 | if (is_array($data)) {
208 | $data = $this->params()->newCreateParam($data);
209 | }
210 |
211 | if (!$data instanceof RecipientlistCreateParam) {
212 |
213 | throw new InvalidArgumentException(
214 | 'Invalid filter provided. Must be an array or RecipientlistCreateParam'
215 | );
216 |
217 | }
218 |
219 | $response = $this->client->request(
220 | $method,
221 | $uri,
222 | [
223 | RequestOptions::JSON => $data->toArray()
224 | ]
225 |
226 | );
227 |
228 | return $this->responseFactory->newHalResponse($this->client, $response);
229 | }
230 |
231 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/TrxEmails/TrxEmail/Parameter/TrxEmailQueryParam.php:
--------------------------------------------------------------------------------
1 | setAttributeRaw('page', $page);
46 |
47 | return $this;
48 | }
49 |
50 | /**
51 | * Sets the from-date in Y-m-d format
52 | *
53 | * Should not be older than users subject retention date
54 | *
55 | * @param string|\DateTimeInterface $date
56 | * @return static
57 | */
58 | public function setDateFrom($date)
59 | {
60 | $this->setAttributeRaw('date_from', $this->stringifyDateTime($date, 'Y-m-d'));
61 |
62 | return $this;
63 | }
64 |
65 | /**
66 | * Sets the to-date in Y-m-d format
67 | *
68 | * Should not be older than users subject retention date or date_from
69 | *
70 | * @param string|\DateTimeInterface $date
71 | * @return static
72 | */
73 | public function setDateTo($date)
74 | {
75 | $this->setAttributeRaw('date_to', $this->stringifyDateTime($date, 'Y-m-d'));
76 |
77 | return $this;
78 | }
79 |
80 | /**
81 | * Filter for emails with(out) attachments
82 | *
83 | * @param mixed $flag
84 | * @return static
85 | */
86 | public function setHasAttachments($flag)
87 | {
88 | $this->setAttributeRaw('has_attachments', $this->convertBool($flag));
89 |
90 | return $this;
91 | }
92 |
93 | /**
94 | * Emails open count when tracking is enabled in transaction mail project settings
95 | *
96 | * Use in conjunction with setActivityOpenMin
97 | *
98 | * @param int $value
99 | * @return static
100 | */
101 | public function setActivityOpen($value)
102 | {
103 |
104 | $this->setAttributeRaw('activity_open', $value);
105 |
106 | return $this;
107 | }
108 |
109 | /**
110 | * Emails click count when tracking is enabled in transaction mail project settings
111 | *
112 | * Use in conjunction with setActivityClickMin
113 | *
114 | * @param int $value
115 | * @return static
116 | */
117 | public function setActivityClick($value)
118 | {
119 |
120 | $this->setAttributeRaw('activity_click', $value);
121 |
122 | return $this;
123 | }
124 |
125 | /**
126 | * Enables at least filtering for open count instead of filtering for the exact count
127 | *
128 | * Must be in conjunction with setActivityOpen
129 | *
130 | * @param mixed $flag
131 | * @return static
132 | */
133 | public function setActivityOpenMin($flag)
134 | {
135 |
136 | $this->setAttributeRaw('activity_open_min', $this->convertBool($flag));
137 |
138 | return $this;
139 | }
140 |
141 | /**
142 | * Enables at least filtering for click count instead of filtering for the exact count
143 | *
144 | * Must be in conjunction with setActivityClick
145 | *
146 | * @param mixed $flag
147 | * @return static
148 | */
149 | public function setActivityClickMin($flag)
150 | {
151 |
152 | $this->setAttributeRaw('activity_click_min', $this->convertBool($flag));
153 |
154 | return $this;
155 | }
156 |
157 | /**
158 | * Sets the status filter
159 | *
160 | * @param string|string[] $status Available values: queued, received, delivered, paused, bounced, abused, rejected, deleted
161 | * @return static
162 | */
163 | public function setStatus($status)
164 | {
165 |
166 | if (is_array($status)) {
167 | $status = implode(',', $status);
168 | }
169 |
170 | $this->setAttributeRaw('status', $status);
171 |
172 | return $this;
173 | }
174 |
175 | /**
176 | * Filter by one or more project ids
177 | *
178 | * Can contain multiple values in comma-separated list
179 | *
180 | * @param int|int[] $id
181 | * @return static
182 | */
183 | public function setProjectId($id)
184 | {
185 |
186 | if (is_array($id)) {
187 | $id = implode(',', $id);
188 | }
189 |
190 | $this->setAttributeRaw('project_id', $id);
191 |
192 | return $this;
193 | }
194 |
195 | /**
196 | * Sets the search query filter
197 | *
198 | * Has no effect when used in conjunction with any of these filters: from, to, subject, message
199 | *
200 | * @param string $search
201 | * @return static
202 | */
203 | public function setSearch($search)
204 | {
205 | $this->setAttributeRaw('search', $search);
206 |
207 | return $this;
208 | }
209 |
210 | /**
211 | * From name or email to filter list by
212 | *
213 | * Ignores search filter when set
214 | *
215 | * @param string $from
216 | * @return static
217 | */
218 | public function setFrom($from)
219 | {
220 | $this->setAttributeRaw('from', $from);
221 |
222 | return $this;
223 | }
224 |
225 | /**
226 | * To name or email to filter list by
227 | *
228 | * Ignores search filter when set
229 | *
230 | * @param string $to
231 | * @return static
232 | */
233 | public function setTo($to)
234 | {
235 | $this->setAttributeRaw('to', $to);
236 |
237 | return $this;
238 | }
239 |
240 | /**
241 | * Email subject to filter list by
242 | *
243 | * Ignores search filter when set
244 | *
245 | * @param string $subject
246 | * @return static
247 | */
248 | public function setSubject($subject)
249 | {
250 | $this->setAttributeRaw('subject', $subject);
251 |
252 | return $this;
253 | }
254 |
255 | /**
256 | * Message contents to filter list by
257 | *
258 | * Ignores search filter when set
259 | *
260 | * @param string $message
261 | * @return static
262 | */
263 | public function setMessage($message)
264 | {
265 | $this->setAttributeRaw('message', $message);
266 |
267 | return $this;
268 | }
269 |
270 | }
--------------------------------------------------------------------------------
/lib/rapidmail/src/Service/V1/Api/Recipients/Recipient/RecipientService.php:
--------------------------------------------------------------------------------
1 | parameterFactory = $parameterFactory;
45 | parent::__construct($client, $responseFactory);
46 | }
47 |
48 | /**
49 | * @inheritDoc
50 | */
51 | protected function getResourcePath()
52 | {
53 | return 'recipients';
54 | }
55 |
56 | /**
57 | * @return ParameterFactory
58 | */
59 | public function params()
60 | {
61 | return $this->parameterFactory;
62 | }
63 |
64 | /**
65 | * Load a single recipient by ID
66 | *
67 | * @param int $recipientId
68 | * @return HalResponse
69 | *
70 | * @throws ApiException
71 | */
72 | public function get($recipientId)
73 | {
74 |
75 | return $this->responseFactory->newHalResponse(
76 | $this->client,
77 | $this->_get($recipientId)
78 | );
79 |
80 | }
81 |
82 | /**
83 | * List all recipients
84 | *
85 | * @param int|array|RecipientQueryParam $filter
86 | * @return HalResponseResourceIterator
87 | *
88 | * @throws ApiException
89 | */
90 | public function query($filter = [])
91 | {
92 |
93 | if (is_numeric($filter)) {
94 |
95 | // Assume a recipient list ID was provided
96 |
97 | $filter = $this->parameterFactory->newQueryParam()->setRecipientlistId($filter);
98 |
99 | }
100 |
101 | if (is_array($filter)) {
102 | $filter = $this->params()->newQueryParam($filter);
103 | }
104 |
105 | if (!$filter instanceof RecipientQueryParam) {
106 |
107 | throw new InvalidArgumentException(
108 | 'Invalid filter provided. Must be an array or RecipientQueryParam'
109 | );
110 |
111 | }
112 |
113 | return $this->responseFactory->newHalResponseResourceIterator(
114 | $this->client,
115 | 'recipients',
116 | $this->_query(
117 | $filter->toArray()
118 | )
119 | );
120 |
121 | }
122 |
123 | /**
124 | * Create a new recipient
125 | *
126 | * @param array|RecipientCreateParam $data
127 | * @param array|RecipientCreateQueryParam $query Optional: Modify create behavior
128 | * @return HalResponse
129 | * @throws ApiException
130 | */
131 | public function create($data = [], $query = [])
132 | {
133 |
134 | $method = 'POST';
135 | $uri = $this->getResourcePath();
136 |
137 | return $this->upsert($method, $uri, $data, $query);
138 |
139 | }
140 |
141 | /**
142 | * Update a specific recipient allowing partial updates
143 | *
144 | * @param int $recipientId
145 | * @param string|array|RecipientCreateParam $data
146 | * @return HalResponse
147 | * @throws ApiException
148 | */
149 | public function update($recipientId, $data = [])
150 | {
151 |
152 | $method = 'PATCH';
153 | $uri = "{$this->getResourcePath()}/{$recipientId}";
154 |
155 | return $this->upsert($method, $uri, $data, []);
156 |
157 | }
158 |
159 | /**
160 | * Delete recipient by ID
161 | *
162 | * Please note that a recipient is only soft-deleted and marked as deleted
163 | * when calling this to mimic unsubscribe behavior.
164 | *
165 | * @param int $recipientId
166 | * @param array|RecipientDeleteQueryParam
167 | * @return bool
168 | * @throws ApiException
169 | */
170 | public function delete($recipientId, $query = [])
171 | {
172 |
173 | if (is_array($query)) {
174 | $query = $this->params()->newDeleteQueryParam($query);
175 | }
176 |
177 | if (!$query instanceof RecipientDeleteQueryParam) {
178 |
179 | throw new InvalidArgumentException(
180 | 'Invalid filter provided. Must be an array or RecipientDeleteQueryParam'
181 | );
182 |
183 | }
184 |
185 | return $this
186 | ->client
187 | ->request(
188 | 'DELETE',
189 | "{$this->getResourcePath()}/{$recipientId}",
190 | [
191 | RequestOptions::QUERY => $query->toArray()
192 | ]
193 | )
194 | ->getStatusCode() == 204;
195 |
196 | }
197 |
198 | /**
199 | * Creates or updates a recipient
200 | *
201 | * @param string $method
202 | * @param string $uri
203 | * @param array|RecipientCreateParam $data
204 | * @param array|RecipientCreateQueryParam $query
205 | * @return HalResponse
206 | * @throws ApiException
207 | */
208 | private function upsert($method, $uri, $data, $query)
209 | {
210 |
211 | if (is_array($data)) {
212 | $data = $this->params()->newCreateParam($data);
213 | }
214 |
215 | if (!$data instanceof RecipientCreateParam) {
216 |
217 | throw new InvalidArgumentException(
218 | 'Invalid filter provided. Must be an array or RecipientCreateParam'
219 | );
220 |
221 | }
222 |
223 | if (is_array($query)) {
224 | $query = $this->params()->newCreateQueryParam($query);
225 | }
226 |
227 | if (!$query instanceof RecipientCreateQueryParam) {
228 |
229 | throw new InvalidArgumentException(
230 | 'Invalid filter provided. Must be an array or RecipientCreateQueryParam'
231 | );
232 |
233 | }
234 |
235 | $response = $this->client->request(
236 | $method,
237 | $uri,
238 | [
239 | RequestOptions::JSON => $data->toArray(),
240 | RequestOptions::QUERY => $query->toArray()
241 | ]
242 | );
243 |
244 | return $this->responseFactory->newHalResponse($this->client, $response);
245 | }
246 |
247 | /**
248 | * Import a list of recipients into the recipientlist from a CSV file
249 | *
250 | * Multipart uploads are not supported. Please note that the import will not be instantaneous,
251 | * but will be queued in the jobqueue for processing, and a job entity response returned.
252 | * The Jobs api service can then be used to poll the job status.
253 | *
254 | * @param array|RecipientImportParam $data
255 | * @param array|RecipientImportQueryParam $query
256 | * @return HalResponse
257 | * @throws ApiException
258 | */
259 | public function import($data = [], $query = [])
260 | {
261 |
262 | if (is_array($data)) {
263 | $data = $this->params()->newImportParam($data);
264 | }
265 |
266 | if (!$data instanceof RecipientImportParam) {
267 |
268 | throw new InvalidArgumentException(
269 | 'Invalid filter provided. Must be an array or RecipientImportParam'
270 | );
271 |
272 | }
273 |
274 | if (is_array($query)) {
275 | $query = $this->params()->newImportQueryParam($query);
276 | }
277 |
278 | if (!$query instanceof RecipientImportQueryParam) {
279 |
280 | throw new InvalidArgumentException(
281 | 'Invalid filter provided. Must be an array or RecipientImportQueryParam'
282 | );
283 |
284 | }
285 |
286 | $response = $this->client->request(
287 | 'POST',
288 | "{$this->getResourcePath()}/import",
289 | [
290 | RequestOptions::JSON => $data->toArray(),
291 | RequestOptions::QUERY => $query->toArray()
292 | ]
293 | );
294 |
295 | return $this->responseFactory->newHalResponse($this->client, $response);
296 |
297 | }
298 |
299 | }
300 |
--------------------------------------------------------------------------------