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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: PHP Composer

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Initialise GitHub Actions env
uses: actions/checkout@v2

- name: Setup PHP with specific version (phpstan requires 7.2+)
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
extensions: ext-curl, ext-json

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
php-version: '7.2'
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

- name: Run test suite
run: composer run-script test
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### project/IDE files
.settings
.buildpath
.project
.DS_Store
*.tmp
.idea

### packages
/vendor*/

## phpstan
/src/phpstan.log
20 changes: 15 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "enormail/enormail-php-api",
"description" : "A PHP Library for the Enormail API",
"keywords": ["enormail"],
"description": "A PHP Library for the Enormail API",
"keywords": [
"enormail"
],
"homepage": "https://github.com/Enormail/enormail-php-api.git",
"authors": [
{
Expand All @@ -10,11 +12,19 @@
}
],
"license": "GNU2",
"minimum-stability": "dev",
"minimum-stability": "stable",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": { "Enormail": "src/" }
"psr-0": {
"Enormail": "src/"
}
},
"scripts": {
"test": "phpstan"
},
"require-dev": {
"phpstan/phpstan": "^1.10"
}
}
}
83 changes: 83 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 1
paths:
- src/
2 changes: 1 addition & 1 deletion src/Enormail/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ApiClient {
* The constructor
*
* @access public
* @return nill
* @return void
*/
public function __construct($key, $format = 'json')
{
Expand Down
4 changes: 3 additions & 1 deletion src/Enormail/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ abstract class Base {
* Default response format
*/
public $format = 'json';

protected $rest;

/**
* Constructor
*
* @access public
* @param object $rest em_rest object
* @return nill
* @return void
*/
public function __construct(Rest $rest)
{
Expand Down
42 changes: 31 additions & 11 deletions src/Enormail/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ public function details($listid, $email)
* @param string $email the contact's e-mail address
* @param array $fields an array with optional fields, example: array('lastname' => 'Contact lastname', 'city' => 'City name')
* @param integer $activate_autoresponder a flag to activate the autoresponder when the contact is added (1 or 0, default 1)
* @param array $tags an array with optional tags, example: array(0 => 'tag1', 1 => 'tag2')
* @return string results (json|xml)
*/
public function add($listid, $name, $email, array $fields = null, $activate_autoresponder = 1)
public function add($listid, $name, $email, array $fields = null, $activate_autoresponder = 1, array $tags = null)
{
return $this->rest->post("/contacts/{$listid}.{$this->format}", array(
$payload = array(
'name' => $name,
'email' => $email,
'fields' => $fields,
'fields' => $fields,
'activate_autoresponder' => $activate_autoresponder
));
);

if ($tags) {
$payload['tags'] = $tags;
} elseif (isset($payload['fields']['tags'])) {
$payload['tags'] = $payload['fields']['tags'];
}
unset($payload['fields']['tags']);

return $this->rest->post("/contacts/{$listid}.{$this->format}", $payload);
}

/**
Expand All @@ -67,20 +77,30 @@ public function add($listid, $name, $email, array $fields = null, $activate_auto
* @param array $fields an array with optional fields, example: array('lastname' => 'Contact lastname', 'city' => 'City name')
* @param string $new_email the contact's new e-email address (optional)
* @param string $move_to_listid the list of the list you want the contact to move to (optional)
* @param array $tags an array with optional tags, example: array(0 => 'tag1', 1 => 'tag2')
* @return string results (json|xml)
*/
public function update($listid, $name, $email, array $fields = null, $new_email = null, $move_to_listid = null)
public function update($listid, $name, $email, array $fields = null, $new_email = null, $move_to_listid = null, array $tags = null)
{
$aData['name'] = $name;
$aData['fields'] = $fields;

if (!is_null($new_email))
$aData['email'] = $new_email;

if (!is_null($move_to_listid))

if ($tags) {
$aData['tags'] = $tags;
} elseif (isset($aData['fields']['tags'])) {
$aData['tags'] = $aData['fields']['tags'];
}
unset($aData['fields']['tags']);

if (!is_null($new_email)) {
$aData['new_email'] = $new_email;
}

if (!is_null($move_to_listid)) {
$aData['listid'] = $move_to_listid;
}

return $this->rest->put("/contacts/{$listid}.{$this->format}?email={$email}", $aData);
return $this->rest->put("/contacts/{$listid}.{$this->format}?email=".urldecode(urlencode($email)), $aData);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Enormail/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ private function _prep_post_vars($vars, $sep = '&')
}

class Response {


protected $http_code, $http_response;

public function __construct($response)
{
// Set response
Expand Down