Skip to content

Commit

Permalink
Merge pull request #3 from offline-agency/fix-tests
Browse files Browse the repository at this point in the history
Fix tests, CI and Readme
  • Loading branch information
Giacomo92 authored Jul 12, 2023
2 parents b6ff6af + 3e347a1 commit 5244b91
Show file tree
Hide file tree
Showing 28 changed files with 345 additions and 213 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#EMAIL CHEF
EMAIL_CHEF_USERNAME=
EMAIL_CHEF_PASSWORD=
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
tags:
pull_request:

jobs:
test:
Expand All @@ -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 }}

Expand Down
4 changes: 4 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
preset: laravel

disabled:
- single_class_element_per_statement
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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**!
68 changes: 64 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Laravel Email Chef API

[![Latest Version on Packagist](https://img.shields.io/packagist/v/offlineagency/laravel-email-chef.svg?style=flat-square)](https://packagist.org/packages/offlineagency/laravel-email-chef)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/offlineagency/laravel-email-chef/run-tests?label=tests)](https://github.com/offlineagency/laravel-email-chef/actions?query=workflow%3Arun-tests+branch%3Amain)
[![Github Action Status](https://github.com/offline-agency/laravel-email-chef/actions/workflows/main.yml/badge.svg)](https://github.com/offline-agency/laravel-email-chef/actions/workflows/main.yml)
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/offlineagency/laravel-email-chef/Check%20&%20fix%20styling?label=code%20style)](https://github.com/offlineagency/laravel-email-chef/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/offlineagency/laravel-email-chef.svg?style=flat-square)](https://packagist.org/packages/offlineagency/laravel-email-chef)
---
Expand All @@ -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:
Expand All @@ -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'
];
```

Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/email-chef.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
'password' => env('EMAIL_CHEF_PASSWORD'),

'list_id' => '97322',

'contact_id' => '656023',
];
19 changes: 5 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,12 @@
verbose="true"
>
<testsuites>
<testsuite name="OfflineAgency Test Suite">
<testsuite name="Laravel Email Chef Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_DEBUG" value="true"/>
</php>
</phpunit>
2 changes: 0 additions & 2 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ protected function post(

$response_status = $response->status();


// if ($response_status === 403 || $response_status === 429) {
// $this->waitThrottle($response_status);
//
Expand Down Expand Up @@ -97,7 +96,6 @@ protected function data(
return $parsed_data;
}


private function waitThrottle(
int $status
) {
Expand Down
68 changes: 33 additions & 35 deletions src/Api/Resources/ContactsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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()) {
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
Loading

0 comments on commit 5244b91

Please sign in to comment.