2017 © Pedro Peláez
 

library newsletter2go-api

Model based Newsletter2Go API implementation

image

richardhj/newsletter2go-api

Model based Newsletter2Go API implementation

  • Monday, May 28, 2018
  • by richardhj
  • Repository
  • 1 Watchers
  • 2 Stars
  • 105 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 81 % Grown

The README.md

Newsletter2Go model based API integration

Latest Version on Packagist ![Software License][ico-license] Dependency Status, (*1)

This package provides a model based implementation of the Newsletter2Go API. It aims to make complex documentations unnecessary. With its clear structure and extensive PHPDoc, it is really easy to use., (*2)

Install

Via Composer, (*3)

``` bash $ composer require richardhj/newsletter2go-api, (*4)


## Usage ### Fetch and alter If you want to fetch items via the API there might be a static function for. Example: ```php $users = Newsletter2Go\Api\Model\NewsletterUser::findAll(null, $apiCredentials); // Use a PHPDoc comment and profit from auto suggestion /** @var NewsletterUser $user */ foreach ($users as $user) { // What's about naming all users "Doe"? $user->setLastName('Doe'); // Save the user (via the API of course) $user->save(); // $data contains all data fetched for this item $data = $user->getData(); }

```php $recipients = Newsletter2Go\Api\Model\NewsletterRecipient::findByListAndGroup('abc123', 'xyz987', null, $apiCredentials); var_dump($recipients);, (*5)

foreach ($recipients as $recipient) { $recipient->addToGroup('xyz345'); $recipient->removeFromGroup('asdf12'); }, (*6)


#### Api Credentials ```ApiCredentials``` are mandatory for the api communication. First of all you need the ```auth_key``` that can be found in the Newsletter2Go back end. The ```auth_key``` is the same for all company's accounts. Furthermore you either need a user's ```username``` and ```password``` or a user's ```refresh_token```. If you rather want to use and save the ```refresh_token``` instead of username and password in your application, you have to make an initial api authorization call with the ```username``` and ```password``` anyway. Check the [manual of the corresponding OAuth provider](https://github.com/richardhj/oauth2-newsletter2go/blob/master/README.md) to get to know how to fetch a ```refresh_token```. ```php // Use the ApiCredentialsFactory $apiCredentials = ApiCredentialsFactory::createFromUsernameAndPassword('secret_auth_token', 'user@example.org', 'open_sesame'); $apiCredentials = ApiCredentialsFactory::createFromRefreshToken('secret_auth_token', 'secret_users_refresh_token'); // Or simply use ::create() $apiCredentials = ApiCredentialsFactory::create('secret_auth_token', 'secret_users_refresh_token');

Get parameters

When fetching a collection from the api, you can provide a GetParamters instance. Get parameters allow you to filter, limit etc. the item collection that will be returned. Example:, (*7)

$getParams = new Newsletter2Go\Api\Tool\GetParameters();
$getParams
    ->setExpand(true)
    ->setFilter('email=like="%@example.org"')
    ->setOffset(2)
    ->setLimit(1);

$recipients = Newsletter2Go\Api\Model\NewsletterRecipient::findByListAndGroup('abc123', 'xyz987', $getParams, $apiCredentials);
var_dump($recipients);

Create

If you want to create items via the API, this is how. Example:, (*8)

$recipient = new Newsletter2Go\Api\Model\NewsletterRecipient();
$recipient->setApiCredentials($apiCredentials);
$recipient
    ->setListId('abc123')
    ->setFirstName('John')
    ->setLastName('Doe')
    ->setEmail('doe@example.org')
    ->setGender('m');

// Good to have an id, otherwise the email address will be the primary key and you will not be able to change the email address of a recipient properly
$recipient->setId('xyz123');

// Update an existing recipient (when id given or email address known in Newsletter2Go) or create a new recipient
$recipient->save();

Delete

For models that implement Newsletter2Go\Api\Model\ModelDeletableInterface, delete() is available. Example:, (*9)

$groups = Newsletter2Go\Api\Model\NewsletterGroup::findByList('abc123', $getParams, $credentials);

/** @var NewsletterGroup $group */
foreach ($groups as $group) {
    $group->delete();
}

Official API documentation

Visit the official API documentation for reference., (*10)

License

The GNU Lesser General Public License (LGPL)., (*11)

The Versions

28/05 2018

v2.0.x-dev

2.0.9999999.9999999-dev

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0-or-later

The Requires

 

api newsletter2go

28/05 2018

v2.0.0

2.0.0.0

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0-or-later

The Requires

 

api newsletter2go

13/10 2017

dev-feature/v2.0.0

dev-feature/v2.0.0

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0+

The Requires

 

api newsletter2go

13/03 2017

dev-master

9999999-dev

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0+

The Requires

 

api newsletter2go

13/03 2017

v1.0.0-beta.4

1.0.0.0-beta4

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0+

The Requires

 

api newsletter2go

10/03 2017

v1.0.0-beta.3

1.0.0.0-beta3

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0+

The Requires

 

api newsletter2go

05/01 2017

v1.0.0-beta.2

1.0.0.0-beta2

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0+

The Requires

 

api newsletter2go

27/08 2016

v1.0.0-beta.1

1.0.0.0-beta1

Model based Newsletter2Go API implementation

  Sources   Download

LGPL-3.0+

The Requires

 

api newsletter2go