Download the PHP package getanewsletter/api-php without Composer
On this page you can find all versions of the php package getanewsletter/api-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package api-php
API-PHP
The API-PHP library presents a simple and easy to use interface to the Get a Newsletter's REST API.
Requirements
- PHP 5.5.* or greater
- Httpful 0.2.*
Installation
If your project is supporting Composer you may use the following in your composer.json file:
Usage
Start by creating an instance of the object:
Here variable must contain a valid API token string.
The contact object
The instances of the \Gan\Contact class represent the contact entities in the API. They have the following fields:
Required fields
-
- contact's email. It's also a lookup field - required when updating or deleting the contact.
Optional fields
-
- list of the contact's attributes.
-
- list of the newsletters for which this contact is subscribed to.
Read-only fields
-
- the contact's resource URL.
-
- true if the contact is active and can receive mails, false otherwise.
-
- the date of the last change.
-
- the date of creation.
Retreiving a contact
You have to create an instance of the class and then use it's method to retrieve the contact you need.
The manager methods will throw an in case of HTTP error from the API, so it's a good idea to catch it.
Creating a contact
This will create a new contact and save it. Again, it'll be a good idea to catch exceptions when calling the method. The API will respond with an error if the contact already exists. One way to avoid it is to force the creation of the contact, overwriting the existing one:
Both and will return the same contact object with it's read-only fields updated (e.g. , ).
Updating an existing contact
You can avoid making two calls to the API by forcing a partial update.
Calling on the contact object marks it like it's already existing and coming from the API. The calls to the method when a contact is maked as existing will do only a partial update, i.e. update only the supplied fields and skipping all the fields. Do not forget that is a lookup field and required when updating or deleting the contact.
Deleting a contact
The newsletter object
The instances of the \Gan\Newsletter class represent the lists in the API. They have the following structure:
Required fields
-
- sender's email.
-
- name of the list.
-
- sender's name.
-
Optional fields
Lookup field
-
- the list's unique hash.
Read-only fields
Retreiving, creating, updating and deleting a list
The CRUD operations on lists are no different from the operations on contacts:
Subscribing a contact to a list
You can also create a new contact automatically subscribed.