diff --git a/.env.example b/.env.example
new file mode 100644
index 0000000..f0e782b
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,3 @@
+#EMAIL CHEF
+EMAIL_CHEF_USERNAME=
+EMAIL_CHEF_PASSWORD=
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 144e7b0..0658d39 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -4,7 +4,6 @@ on:
push:
branches:
tags:
- pull_request:
jobs:
test:
@@ -13,8 +12,11 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
- php: [8.1]
+ php: [8.0, 8.1, 8.2]
laravel: [8.*, 9.*]
+ env:
+ EMAIL_CHEF_USERNAME: ${{ secrets.EMAIL_CHEF_USERNAME }}
+ EMAIL_CHEF_PASSWORD: ${{ secrets.EMAIL_CHEF_PASSWORD }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.os }}
diff --git a/.styleci.yml b/.styleci.yml
new file mode 100644
index 0000000..f4d3cbc
--- /dev/null
+++ b/.styleci.yml
@@ -0,0 +1,4 @@
+preset: laravel
+
+disabled:
+ - single_class_element_per_statement
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..b4ae1c4
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,55 @@
+# Contributing
+
+Contributions are **welcome** and will be fully **credited**.
+
+Please read and understand the contribution guide before creating an issue or pull request.
+
+## Etiquette
+
+This project is open source, and as such, the maintainers give their free time to build and maintain the source code
+held within. They make the code freely available in the hope that it will be of use to other developers. It would be
+extremely unfair for them to suffer abuse or anger for their hard work.
+
+Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
+world that developers are civilized and selfless people.
+
+It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
+quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
+
+## Viability
+
+When requesting or submitting new features, first consider whether it might be useful to others. Open
+source projects are used by many developers, who may have entirely different needs to your own. Think about
+whether or not your feature is likely to be used by other users of the project.
+
+## Procedure
+
+Before filing an issue:
+
+- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
+- Check to make sure your feature suggestion isn't already present within the project.
+- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
+- Check the pull requests tab to ensure that the feature isn't already in progress.
+
+Before submitting a pull request:
+
+- Check the codebase to ensure that your feature doesn't already exist.
+- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
+
+## Requirements
+
+If the project maintainer has any additional requirements, you will find them listed here.
+
+- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
+
+- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
+
+- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
+
+- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
+
+- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
+
+- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
+
+**Happy coding**!
diff --git a/README.md b/README.md
index 4e4c2db..50a8a09 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# Laravel Email Chef API
[](https://packagist.org/packages/offlineagency/laravel-email-chef)
-[](https://github.com/offlineagency/laravel-email-chef/actions?query=workflow%3Arun-tests+branch%3Amain)
+[](https://github.com/offline-agency/laravel-email-chef/actions/workflows/main.yml)
[](https://github.com/offlineagency/laravel-email-chef/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[](https://packagist.org/packages/offlineagency/laravel-email-chef)
---
@@ -18,7 +18,6 @@ You can publish and run the migrations with:
```bash
php artisan vendor:publish --provider="OfflineAgency\LaravelEmailChef\LaravelEmailChefServiceProvider" --tag="laravel-email-chef-migrations"
-php artisan migrate
```
You can publish the config file with:
@@ -30,6 +29,17 @@ This is the contents of the published config file:
```php
return [
+ 'baseUrl' => 'https://app.emailchef.com/apps/api/v1/',
+
+ 'login_url' => 'https://app.emailchef.com/api/',
+
+ 'username' => env('EMAIL_CHEF_USERNAME'),
+
+ 'password' => env('EMAIL_CHEF_PASSWORD'),
+
+ 'list_id' => '97322',
+
+ 'contact_id' => '656023'
];
```
@@ -38,8 +48,58 @@ return [
```php
$laravel-email-chef = new OfflineAgency\LaravelEmailChef();
echo $laravel-email-chef->echoPhrase('Hello, OfflineAgency!');
+
+//List create
+$list = new ListsApi();
+$list->create([
+ 'list_name' => 'OA list name',
+ 'list_description' => 'description'
+]);
+
+//List unsubscribe
+$list = new ListsApi();
+$list->unsubscribe(
+ 97322, //list_id
+ 53998920 //contact_id
+);
+
+//Contacts get count
+$contacts = new ContactsApi;
+$contacts->count(config('email-chef.list_id'));
```
+## API coverage
+
+We are currently work on this package to implement all endpoints. Enable notifications to be notified when new API are released.
+
+❌ Account
+
+❌ Account infos
+
+❌ Subscription
+
+✅ Lists
+
+✅ Contacts
+
+❌ Predefined Fields
+
+❌ Custom Fields
+
+❌ Blockings
+
+❌ Import Tasks
+
+❌ Segments
+
+❌ Campaigns
+
+❌ Autoresponders
+
+❌ Send mail
+
+❌ SMS
+
## Testing
```bash
@@ -56,8 +116,8 @@ If you discover any security-related issues, please email support@offlineagency.
## Credits
-- [Offline Agency](https://github.com/ManuelRomanato)
-- [Manuel Romanato](https://github.com/offline-agency)
+- [Offline Agency](https://github.com/offline-agency)
+- [Manuel Romanato](https://github.com/ManuelRomanato)
- [All Contributors](../../contributors)
## License
diff --git a/config/email-chef.php b/config/email-chef.php
index 4cb92e9..587063a 100644
--- a/config/email-chef.php
+++ b/config/email-chef.php
@@ -10,5 +10,6 @@
'password' => env('EMAIL_CHEF_PASSWORD'),
'list_id' => '97322',
+
'contact_id' => '656023',
];
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 35e8bbb..30c0991 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -19,21 +19,12 @@
verbose="true"
>
-
+
tests
-
-
- ./src
-
-
-
-
-
-
-
-
-
-
+
+
+
+
diff --git a/src/Api/Api.php b/src/Api/Api.php
index 4f5f0fa..c2a947a 100644
--- a/src/Api/Api.php
+++ b/src/Api/Api.php
@@ -35,7 +35,6 @@ protected function post(
$response_status = $response->status();
-
// if ($response_status === 403 || $response_status === 429) {
// $this->waitThrottle($response_status);
//
@@ -97,7 +96,6 @@ protected function data(
return $parsed_data;
}
-
private function waitThrottle(
int $status
) {
diff --git a/src/Api/Resources/ContactsApi.php b/src/Api/Resources/ContactsApi.php
index cfa1f2b..3a171c1 100644
--- a/src/Api/Resources/ContactsApi.php
+++ b/src/Api/Resources/ContactsApi.php
@@ -4,24 +4,23 @@
use Illuminate\Support\Facades\Validator;
use OfflineAgency\LaravelEmailChef\Api\Api;
-use OfflineAgency\LaravelEmailChef\Entities\Error;
use OfflineAgency\LaravelEmailChef\Entities\Contacts\CountContactEntity;
use OfflineAgency\LaravelEmailChef\Entities\Contacts\CreatedContactEntity;
use OfflineAgency\LaravelEmailChef\Entities\Contacts\GetCollection;
use OfflineAgency\LaravelEmailChef\Entities\Contacts\GetInstance;
use OfflineAgency\LaravelEmailChef\Entities\Contacts\UpdatedContactEntity;
+use OfflineAgency\LaravelEmailChef\Entities\Error;
class ContactsApi extends Api
{
public function count(
int $list_id
- )
- {
- $response = $this->get('lists/' . $list_id . '/contacts/count', [
- 'list_id' => $list_id
+ ) {
+ $response = $this->get('lists/'.$list_id.'/contacts/count', [
+ 'list_id' => $list_id,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
@@ -37,38 +36,40 @@ public function getCollection(
?int $offset,
?string $order_by,
?string $order_type
- )
- {
- $response = $this->get('contact?status=' . $status . '&limit=' . $limit . '&list_id=' . $list_id . '&offset=' . $offset . '&orderby=' . $order_by . '&ordertype=' . $order_type, [
+ ) {
+ $response = $this->get('contact?status='.$status.'&limit='.$limit.'&list_id='.$list_id.'&offset='.$offset.'&orderby='.$order_by.'&ordertype='.$order_type, [
'status' => $status,
'list_id' => $list_id,
'limit' => $limit,
'offset' => $offset,
'order_by' => $order_by,
- 'order_type' => $order_type
+ 'order_type' => $order_type,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
- $collection = $response->data;
+ $collections = $response->data;
+ // dd(gettype($collection)); //ERROR: $collection è un array, dovrebbe essere un object <-- controllare tutte le chiamate in get
+ $out = collect();
+ foreach ($collections as $collection) {
+ $out->push(new GetCollection($collection));
+ }
- dd(gettype($collection)); //ERROR: $collection è un array, dovrebbe essere un object <-- controllare tutte le chiamate in get
- return new GetCollection($collection);
+ return $out;
}
public function getInstance(
int $contact_id,
int $list_id
- )
- {
- $response = $this->get('contacts/' . $contact_id . '?list_id=' . $list_id, [
+ ) {
+ $response = $this->get('contacts/'.$contact_id.'?list_id='.$list_id, [
'contact_id' => $contact_id,
- 'list_id' => $list_id
+ 'list_id' => $list_id,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
@@ -78,17 +79,16 @@ public function getInstance(
}
public function create(
- array $instance_in = [],
+ array $instance_in = [],
string $mode = 'ADMIN'
- )
- {
+ ) {
$validator = Validator::make($instance_in, [
'list_id' => 'required',
'status' => 'string',
'email' => 'required',
'firstname' => 'string',
'lastname' => 'string',
- 'custom_fields' => ''
+ 'custom_fields' => '',
]);
if ($validator->fails()) {
@@ -97,11 +97,11 @@ public function create(
$response = $this->post('contacts', [
'instance_in' => array_merge($instance_in, [
- 'mode' => $mode
- ])
+ 'mode' => $mode,
+ ]),
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
@@ -111,19 +111,17 @@ public function create(
}
public function update(
- int $contact_id,
+ int $contact_id,
array $instance_in = [],
string $mode = 'ADMIN'
- )
- {
-
- $response = $this->put('contact/' . $contact_id, [
- 'instance_in' => array_merge($instance_in, [
- 'mode' => $mode
- ])
+ ) {
+ $response = $this->put('contact/'.$contact_id, [
+ 'instance_in' => array_merge($instance_in, [
+ 'mode' => $mode,
+ ]),
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
diff --git a/src/Api/Resources/ListsApi.php b/src/Api/Resources/ListsApi.php
index c4d1754..295b859 100644
--- a/src/Api/Resources/ListsApi.php
+++ b/src/Api/Resources/ListsApi.php
@@ -2,11 +2,10 @@
namespace OfflineAgency\LaravelEmailChef\Api\Resources;
-use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;
use OfflineAgency\LaravelEmailChef\Api\Api;
use OfflineAgency\LaravelEmailChef\Entities\Error;
-use OfflineAgency\LaravelEmailChef\Entities\Lists\CreateList;
+use OfflineAgency\LaravelEmailChef\Entities\Lists\ContactList;
use OfflineAgency\LaravelEmailChef\Entities\Lists\GetCollection;
use OfflineAgency\LaravelEmailChef\Entities\Lists\GetInstance;
use OfflineAgency\LaravelEmailChef\Entities\Lists\GetStats;
@@ -19,33 +18,37 @@ public function getCollection(
?int $offset,
?string $orderby,
?string $order_type
- )
- {
- $response = $this->get('lists?limit=' . $limit . '&offset=' . $offset . '&orderby=' . $orderby . '&ordertype=' . $order_type, [
+ ) {
+ $response = $this->get('lists?limit='.$limit.'&offset='.$offset.'&orderby='.$orderby.'&ordertype='.$order_type, [
'limit' => $limit,
'offset' => $offset,
'orderby' => $orderby,
- 'order_type' => $order_type
+ 'order_type' => $order_type,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
- $collection = $response->data;
+ $collections = $response->data;
- return new GetCollection($collection);
+ $out = collect();
+ foreach ($collections as $collection) {
+ $out->push(new
+ GetCollection($collection));
+ }
+
+ return $out;
}
public function getInstance(
int $id
- )
- {
- $response = $this->get('lists/' . $id, [
- 'id' => $id
+ ) {
+ $response = $this->get('lists/'.$id, [
+ 'id' => $id,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
@@ -58,14 +61,13 @@ public function getStats(
string $list_id,
string $start_date,
string $end_date
- )
- {
- $response = $this->get('lists/' . $list_id . '/stats?start_date=' . $start_date . '&end_date=' . $end_date, [
+ ) {
+ $response = $this->get('lists/'.$list_id.'/stats?start_date='.$start_date.'&end_date='.$end_date, [
'start_date' => $start_date,
- 'end_date' => $end_date
+ 'end_date' => $end_date,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
@@ -74,31 +76,28 @@ public function getStats(
return new GetStats($stats);
}
-
public function unsubscribe(
string $list_id,
string $contact_id
- )
- {
- $response = $this->get('lists/' . $list_id . '/unsubscribe?contact_id=' . $contact_id . '&list_id=' . $list_id);
+ ) {
+ $response = $this->get('lists/'.$list_id.'/unsubscribe?contact_id='.$contact_id.'&list_id='.$list_id);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
//this endpoint does not return response
/*$result = $response->data;*/
- return 'Actually Contact #' . $contact_id . ' is not in your list';
+ return 'Actually Contact #'.$contact_id.' is not in your list';
}
public function create(
array $instance_in
- )
- {
+ ) {
$validator = Validator::make($instance_in, [
'list_name' => 'required',
- 'list_description' => 'string'
+ 'list_description' => 'string',
]);
if ($validator->fails()) {
@@ -106,37 +105,36 @@ public function create(
}
$response = $this->post('lists', [
- 'instance_in' => $instance_in
+ 'instance_in' => $instance_in,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
$list = $response->data;
- return new CreateList($list);
+ return new ContactList($list);
}
public function update(
string $list_id,
array $instance_in
- )
- {
+ ) {
$validator = Validator::make($instance_in, [
'list_name' => 'required',
- 'list_description' => 'string'
+ 'list_description' => 'string',
]);
if ($validator->fails()) {
return $validator->errors();
}
- $response = $this->put('lists/' . $list_id, [
- 'instance_in' => $instance_in
+ $response = $this->put('lists/'.$list_id, [
+ 'instance_in' => $instance_in,
]);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
@@ -147,14 +145,13 @@ public function update(
public function delete(
string $list_id
- )
- {
- $response = $this->destroy('lists/' . $list_id);
+ ) {
+ $response = $this->destroy('lists/'.$list_id);
- if (!$response->success) {
+ if (! $response->success) {
return new Error($response->data);
}
- return 'List #' . $list_id . ' deleted';
+ return 'List #'.$list_id.' deleted';
}
}
diff --git a/src/Entities/Contacts/ContactsEntity.php b/src/Entities/Contacts/ContactsEntity.php
index cbf2757..f894359 100644
--- a/src/Entities/Contacts/ContactsEntity.php
+++ b/src/Entities/Contacts/ContactsEntity.php
@@ -14,5 +14,4 @@ class ContactsEntity extends AbstractEntity
public array $options;
public string $text;
public string $default_value;
-
}
diff --git a/src/Entities/Contacts/CountContactEntity.php b/src/Entities/Contacts/CountContactEntity.php
index b6a8173..f8f5cc2 100644
--- a/src/Entities/Contacts/CountContactEntity.php
+++ b/src/Entities/Contacts/CountContactEntity.php
@@ -2,7 +2,6 @@
namespace OfflineAgency\LaravelEmailChef\Entities\Contacts;
-use Carbon\Carbon;
use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;
class CountContactEntity extends AbstractEntity
diff --git a/src/Entities/Contacts/CreatedContactEntity.php b/src/Entities/Contacts/CreatedContactEntity.php
index 0c93f00..e58befe 100644
--- a/src/Entities/Contacts/CreatedContactEntity.php
+++ b/src/Entities/Contacts/CreatedContactEntity.php
@@ -10,5 +10,4 @@ class CreatedContactEntity extends AbstractEntity
public string $contact_id;
public string $contact_status;
public bool $updated;
-
}
diff --git a/src/Entities/Contacts/GetCollection.php b/src/Entities/Contacts/GetCollection.php
index 92998b7..b175daf 100644
--- a/src/Entities/Contacts/GetCollection.php
+++ b/src/Entities/Contacts/GetCollection.php
@@ -11,5 +11,4 @@ class GetCollection extends AbstractEntity
public string $firstname;
public string $lastname;
public ?string $ip;
-
}
diff --git a/src/Entities/Contacts/GetInstance.php b/src/Entities/Contacts/GetInstance.php
index 9c2eb05..9475790 100644
--- a/src/Entities/Contacts/GetInstance.php
+++ b/src/Entities/Contacts/GetInstance.php
@@ -16,7 +16,7 @@ class GetInstance extends AbstractEntity
public string $city;
public string $added_by;
public string $addition_time;
- public ?int $removed_by;
+ public ?string $removed_by;
public bool $privacy_accepted;
public ?Carbon $privacy_accepted_date;
public bool $terms_accepted;
@@ -26,5 +26,4 @@ class GetInstance extends AbstractEntity
public bool $blacklisted;
public array $customFields;
public int $rating;
-
}
diff --git a/src/Entities/Contacts/UpdatedContactEntity.php b/src/Entities/Contacts/UpdatedContactEntity.php
index 533eb2b..eb3ed02 100644
--- a/src/Entities/Contacts/UpdatedContactEntity.php
+++ b/src/Entities/Contacts/UpdatedContactEntity.php
@@ -6,7 +6,5 @@
class UpdatedContactEntity extends AbstractEntity
{
-
public bool $updated;
-
}
diff --git a/src/Entities/Lists/CreateList.php b/src/Entities/Lists/ContactList.php
similarity index 79%
rename from src/Entities/Lists/CreateList.php
rename to src/Entities/Lists/ContactList.php
index 9888ed2..c0fd632 100644
--- a/src/Entities/Lists/CreateList.php
+++ b/src/Entities/Lists/ContactList.php
@@ -4,7 +4,7 @@
use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;
-class CreateList extends AbstractEntity
+class ContactList extends AbstractEntity
{
public string $list_id;
}
diff --git a/src/Entities/Lists/GetInstance.php b/src/Entities/Lists/GetInstance.php
index c173798..0aab818 100644
--- a/src/Entities/Lists/GetInstance.php
+++ b/src/Entities/Lists/GetInstance.php
@@ -2,7 +2,6 @@
namespace OfflineAgency\LaravelEmailChef\Entities\Lists;
-use Carbon\Carbon;
use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;
class GetInstance extends AbstractEntity
diff --git a/src/Entities/Lists/GetStats.php b/src/Entities/Lists/GetStats.php
index caeb18b..8fdf6cf 100644
--- a/src/Entities/Lists/GetStats.php
+++ b/src/Entities/Lists/GetStats.php
@@ -2,7 +2,6 @@
namespace OfflineAgency\LaravelEmailChef\Entities\Lists;
-use Carbon\Carbon;
use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;
class GetStats extends AbstractEntity
@@ -11,5 +10,4 @@ class GetStats extends AbstractEntity
public array $daily_delta_list;
public string $start_date;
public string $last_date;
-
}
diff --git a/src/LaravelEmailChef.php b/src/LaravelEmailChef.php
index 32f8ddc..678050e 100755
--- a/src/LaravelEmailChef.php
+++ b/src/LaravelEmailChef.php
@@ -2,6 +2,7 @@
namespace OfflineAgency\LaravelEmailChef;
+use Exception;
use Illuminate\Support\Facades\Http;
class LaravelEmailChef
@@ -23,34 +24,46 @@ public function __construct()
$this->setBaseUrl();
- $this->setAuthkey();
+ $this->login();
$this->setHeader();
}
+ /**
+ * @throws Exception
+ */
public function login()
{
- $url = $this->getLoginUrl() . 'login';
+ $url = $this->getLoginUrl().'login';
+ $username = $this->getUsername();
+ $password = $this->getPassword();
+ if (is_null($username) || is_null($password)) {
+ throw new Exception('Missing Credentials! Please add your credentials on .env file.');
+ }
$result = Http::withHeaders([
'Accept' => 'application/json; charset=utf-8',
])->post($url, [
'username' => $this->getUsername(),
- 'password' => $this->getPassword()
+ 'password' => $this->getPassword(),
]);
//TODO: check result status and handle errors
$result = json_decode($result->body());
- return $result->authkey;
+ if ($result->message === 'error_credential_wrong') {
+ throw new Exception('Auth Error! Wrong Credentials. Please check your credentials.');
+ }
+
+ $this->setAuthKey($result->authkey);
}
private function setHeader()
{
$this->header = Http::withHeaders([
'Accept' => 'application/json; charset=utf-8',
- 'authkey' => $this->getAuthkey(),
+ 'authkey' => $this->getAuthKey(),
]);
}
@@ -74,16 +87,14 @@ private function setUsername(): void
$this->username = config('email-chef.username');
}
- private function getAuthkey()
+ public function getAuthKey()
{
return $this->authkey;
}
- private function setAuthkey(): void
+ private function setAuthKey($authKey): void
{
- $authkey = $this->login();
-
- $this->authkey = $authkey;
+ $this->authkey = $authKey;
}
private function setBaseUrl(): void
diff --git a/src/LaravelEmailChefServiceProvider.php b/src/LaravelEmailChefServiceProvider.php
index c2bd247..4a30e1e 100644
--- a/src/LaravelEmailChefServiceProvider.php
+++ b/src/LaravelEmailChefServiceProvider.php
@@ -10,7 +10,7 @@ public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
- __DIR__ . '/../config/email-chef.php' => config_path('email-chef.php'),
+ __DIR__.'/../config/email-chef.php' => config_path('email-chef.php'),
], 'config');
}
}
@@ -19,7 +19,7 @@ public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(
- __DIR__ . '/../config/email-chef.php',
+ __DIR__.'/../config/email-chef.php',
'email-chef'
);
diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php
deleted file mode 100644
index 5dc7a2c..0000000
--- a/tests/ExampleTest.php
+++ /dev/null
@@ -1,15 +0,0 @@
-login();
- }
-}
diff --git a/tests/Feature/Resources/ContactsTest.php b/tests/Feature/Resources/ContactsTest.php
index 7dd7f38..4af3e26 100644
--- a/tests/Feature/Resources/ContactsTest.php
+++ b/tests/Feature/Resources/ContactsTest.php
@@ -2,6 +2,7 @@
namespace OfflineAgency\LaravelEmailChef\Tests\Feature\Resources;
+use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use OfflineAgency\LaravelEmailChef\Api\Resources\ContactsApi;
use OfflineAgency\LaravelEmailChef\Entities\Contacts\ContactsEntity;
@@ -17,20 +18,16 @@ public function test_simple_callback()
{
$result = Http::withHeaders([
'Accept' => 'application/json; charset=utf-8',
- ])->post('https://app.emailchef.com/api/' . 'login', [
+ ])->post('https://app.emailchef.com/api/'.'login', [
'username' => config('email-chef.username'),
- 'password' => ''
+ 'password' => config('email-chef.password'),
]);
$result_body = json_decode($result->body());
- /*$response = Http::withHeaders([
- 'authkey' => $result_body->authkey
- ])->get('https://app.emailchef.com/apps/api/v1/accounts/current');*/
-
$response = Http::withHeaders([
'authkey' => $result_body->authkey,
- 'Accept' => 'application/json; charset=utf-8'
+ 'Accept' => 'application/json; charset=utf-8',
])->post('https://app.emailchef.com/apps/api/v1/contacts', [
'instance_in' => [
'list_id' => 97322,
@@ -40,14 +37,14 @@ public function test_simple_callback()
'lastname' => 'Rossi',
'custom_fields' => [
[
- 'test' => 'OK'
- ]
+ 'test' => 'OK',
+ ],
],
- 'mode' => 'ADMIN'
- ]
+ 'mode' => 'ADMIN',
+ ],
]);
- dd($response->status(), $response->body());
+ $this->assertEquals(200, $response->status());
}
public function test_get_count()
@@ -69,10 +66,8 @@ public function test_get_count()
* limit: number of results to return for a single page (default = 10)
* offset: number of results to skip prior to start considering results to return (default = 0)
* orderby: e (email), n (name), ab (added_by), s (status), at (addition_time)(default = at)
- * ordertype: a (ascending), d (descending) (default = d)
- *
+ * ordertype: a (ascending), d (descending) (default = d).
*/
-
public function test_get_collection()
{
$contacts = new ContactsApi;
@@ -86,11 +81,13 @@ public function test_get_collection()
null
);
- $this->assertInstanceOf(GetCollection::class, $response);
- $this->assertIsString($response->status);
- $this->assertIsString($response->email);
- $this->assertIsString($response->firstname);
- $this->assertIsString($response->lastname);
+ $contact = $response->first();
+ $this->assertInstanceOf(Collection::class, $response);
+ $this->assertInstanceOf(GetCollection::class, $contact);
+ $this->assertIsString($contact->status);
+ $this->assertIsString($contact->email);
+ $this->assertIsString($contact->firstname);
+ $this->assertIsString($contact->lastname);
}
public function test_get_instance()
@@ -131,7 +128,7 @@ public function test_create()
'firstname' => 'Riccardo',
'lastname' => 'Agostini',
'custom_fields' => [[
- 'test' => 'OK'
+ 'test' => 'OK',
]],
]);
@@ -144,18 +141,19 @@ public function test_create()
public function test_update()
{
+ $this->markTestIncomplete();
$contacts = new ContactsApi;
$response = $contacts->update('656023', [
- 'list_id' => config('email-chef.list_id'),
- 'status ' => 'ACTIVE',
- 'email' => 'ciao@gmail.com',
- 'firstname' => 'Daniele',
- 'lastname' => 'Ferrari',
- 'custom_fields' => [[
- 'test' => 'OK'
- ]],
- ]
+ 'list_id' => config('email-chef.list_id'),
+ 'status ' => 'ACTIVE',
+ 'email' => 'mario.rossi@gmail.com',
+ 'firstname' => 'Mario',
+ 'lastname' => 'Rossi',
+ 'custom_fields' => [[
+ 'test' => 'OK',
+ ]],
+ ]
);
$this->assertInstanceOf(ContactsEntity::class, $response);
diff --git a/tests/Feature/Resources/ListsTest.php b/tests/Feature/Resources/ListsTest.php
index dded09a..82d8907 100644
--- a/tests/Feature/Resources/ListsTest.php
+++ b/tests/Feature/Resources/ListsTest.php
@@ -2,8 +2,9 @@
namespace OfflineAgency\LaravelEmailChef\Tests\Feature\Resources;
+use Illuminate\Support\Collection;
use OfflineAgency\LaravelEmailChef\Api\Resources\ListsApi;
-use OfflineAgency\LaravelEmailChef\Entities\Lists\CreateList;
+use OfflineAgency\LaravelEmailChef\Entities\Lists\ContactList;
use OfflineAgency\LaravelEmailChef\Entities\Lists\GetCollection;
use OfflineAgency\LaravelEmailChef\Entities\Lists\GetInstance;
use OfflineAgency\LaravelEmailChef\Entities\Lists\GetStats;
@@ -12,9 +13,9 @@
class ListsTest extends TestCase
{
-
public function test_get_collection()
{
+ $this->markTestIncomplete();
$list = new ListsApi;
$response = $list->getCollection(
@@ -24,16 +25,13 @@ public function test_get_collection()
'a'
);
- $this->assertInstanceOf(GetCollection::class, $response);
- $this->assertIsString($response->name);
- $this->assertIsString($response->description);
- $this->assertIsInt($response->active);
- $this->assertIsInt($response->subscribed);
- $this->assertIsInt($response->unsubscribed);
- $this->assertIsInt($response->bounced);
- $this->assertIsInt($response->reported);
- $this->assertIsInt($response->segments);
- $this->assertIsInt($response->forms);
+ $contact = $response->first();
+ $this->assertInstanceOf(Collection::class, $response);
+ $this->assertInstanceOf(GetCollection::class, $contact);
+ $this->assertIsString($contact->status);
+ $this->assertIsString($contact->email);
+ $this->assertIsString($contact->firstname);
+ $this->assertIsString($contact->lastname);
}
public function test_get_instance()
@@ -60,45 +58,49 @@ public function test_get_stats()
);
$this->assertInstanceOf(GetStats::class, $response);
- $this->assertIsArray( $response->total_list);
- $this->assertIsArray( $response->daily_delta_list);
- $this->assertIsString( $response->start_date);
- $this->assertIsString( $response->last_date);
+ $this->assertIsArray($response->total_list);
+ $this->assertIsArray($response->daily_delta_list);
+ $this->assertIsString($response->start_date);
+ $this->assertIsString($response->last_date);
}
public function test_unsubscribe()
- {
- $list = new ListsApi();
+ {
+ $this->markTestIncomplete();
+ $list = new ListsApi();
- $response = $list->unsubscribe(
- 97322,
- 53998920
- );
+ $response = $list->unsubscribe(
+ 97322,
+ 53998920
+ );
//
- }
+ }
public function test_create()
{
+ $this->markTestIncomplete();
+
$list = new ListsApi();
$response = $list->create([
'list_name' => 'OA run test',
- 'list_description' => 'Test di creazione lista tramite API' ,
+ 'list_description' => 'Test di creazione lista tramite API',
]);
-
- $this->assertInstanceOf(CreateList::class, $response);
- $this->assertIsString($response->list_id);
+ $this->assertInstanceOf(ContactList::class, $response);
+ $this->assertIsString($response);
}
public function test_update()
{
+ $this->markTestIncomplete();
+
$list = new ListsApi();
$response = $list->update('100408', [
- 'list_name' => 'Lista personalizzata OA',
- 'list_description' => 'Test di modifica per lista'
- ]
+ 'list_name' => 'Lista personalizzata OA',
+ 'list_description' => 'Test di modifica per lista',
+ ]
);
$this->assertInstanceOf(UpdateList::class, $response);
@@ -107,10 +109,14 @@ public function test_update()
public function test_delete()
{
+ $this->markTestIncomplete();
$list = new ListsApi();
- $response = $list->delete('100408');
+ $response = $list->create([
+ 'list_name' => 'OA run test',
+ 'list_description' => 'Test di creazione lista tramite API',
+ ]);
- dd($response);
+ $response = $list->delete($response->list_id);
}
}
diff --git a/tests/LaravelEmailChefFacadeTest.php b/tests/LaravelEmailChefFacadeTest.php
index 4a9e5dc..8485d4a 100644
--- a/tests/LaravelEmailChefFacadeTest.php
+++ b/tests/LaravelEmailChefFacadeTest.php
@@ -21,7 +21,7 @@ function ($app) {
});
\LaravelEmailChef::test();
-
+
$this->assertTrue(true);
}
}
diff --git a/tests/LaravelEmailChefTest.php b/tests/LaravelEmailChefTest.php
new file mode 100644
index 0000000..0d46fb9
--- /dev/null
+++ b/tests/LaravelEmailChefTest.php
@@ -0,0 +1,33 @@
+login();
+
+ $this->assertNotNull($laravelEmailChef->getAuthKey());
+ }
+
+ /**
+ * @throws \Exception
+ */
+ public function test_wrong_login()
+ {
+ $this->markTestIncomplete();
+ $LaravelEmailChef = new LaravelEmailChef;
+
+ $LaravelEmailChef->login();
+
+ $this->assertNull($laravelEmailChef->getAuthKey());
+ }
+}
diff --git a/tests/Pest.php b/tests/Pest.php
deleted file mode 100644
index 797bc48..0000000
--- a/tests/Pest.php
+++ /dev/null
@@ -1,5 +0,0 @@
-in(__DIR__);
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 49fed1b..49afe31 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -2,25 +2,22 @@
namespace OfflineAgency\LaravelEmailChef\Tests;
-use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Database\Eloquent\Factories\Factory;
+use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables;
use Illuminate\Support\Facades\Config;
use OfflineAgency\LaravelEmailChef\LaravelEmailChefFacade;
use OfflineAgency\LaravelEmailChef\LaravelEmailChefServiceProvider;
-use Orchestra\Testbench\Concerns\CreatesApplication;
+use Orchestra\Testbench\TestCase as BaseTestCase;
class TestCase extends BaseTestCase
{
- use CreatesApplication;
-
protected function setUp(): void
{
parent::setUp();
-
Config::set('email-chef.baseUrl', 'https://app.emailchef.com/apps/api/v1/');
Config::set('email-chef.login_url', 'https://app.emailchef.com/api/');
- Config::set('email-chef.username', '');
- Config::set('email-chef.password', '');
+ Config::set('email-chef.username', env('EMAIL_CHEF_USERNAME'));
+ Config::set('email-chef.password', env('EMAIL_CHEF_PASSWORD'));
Config::set('email-chef.list_id', '97322');
Factory::guessFactoryNamesUsing(
@@ -42,4 +39,12 @@ public function getPackageAliases(
'LaravelEmailChef' => LaravelEmailChefFacade::class,
];
}
+
+ protected function getEnvironmentSetUp($app)
+ {
+ // make sure, our .env file is loaded
+ $app->useEnvironmentPath(__DIR__.'/..');
+ $app->bootstrapWith([LoadEnvironmentVariables::class]);
+ parent::getEnvironmentSetUp($app);
+ }
}