gmail-filter-builder/src/Model/Filter.php

242 lines
3.9 KiB
PHP
Raw Normal View History

2017-11-03 11:23:22 +00:00
<?php
2018-01-10 17:39:50 +00:00
namespace Opdavies\GmailFilterBuilder\Model;
2017-11-03 11:23:22 +00:00
class Filter
{
2017-12-30 10:56:07 +00:00
/**
* @var array
*/
2017-11-03 23:22:13 +00:00
private $properties = [];
2017-12-30 18:22:12 +00:00
/**
* @return static
*/
public static function create()
{
return new static();
}
2017-12-30 10:56:07 +00:00
/**
* @param string $value
*
* @return $this
*/
2017-11-03 11:23:22 +00:00
public function has($value)
{
2017-11-03 23:22:13 +00:00
$this->properties['hasTheWord'] = $value;
return $this;
2017-11-03 11:23:22 +00:00
}
2017-12-30 10:56:07 +00:00
/**
* @param string $value
*
* @return $this
*/
2017-11-04 09:20:46 +00:00
public function hasNot($value)
{
$this->properties['doesNotHaveTheWord'] = $value;
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @param string|array $values
*
* @return $this
*/
public function from($values)
2017-11-03 11:23:22 +00:00
{
2017-12-30 10:56:07 +00:00
$this->properties['from'] = collect($values)->map(function ($value) {
return trim($value);
})->all();
2017-11-04 09:20:46 +00:00
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @param string|array $values
*
* @return $this
*/
public function to($values)
2017-11-04 09:20:46 +00:00
{
2017-12-30 10:56:07 +00:00
$this->properties['to'] = collect($values)->map(function ($value) {
return trim($value);
})->all();
2017-11-04 09:20:46 +00:00
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @param string $subject
*
* @return $this
*/
2017-11-04 09:20:46 +00:00
public function subject($subject)
{
$this->properties['subject'] = $subject;
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-04 09:20:46 +00:00
public function hasAttachment()
{
$this->properties['hasAttachment'] = 'true';
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-04 09:20:46 +00:00
public function excludeChats()
{
$this->properties['excludeChats'] = 'true';
2017-11-03 23:22:13 +00:00
return $this;
2017-11-03 11:23:22 +00:00
}
2017-12-30 10:56:07 +00:00
/**
* @param string $label
*
* @return $this
*/
2017-11-03 11:23:22 +00:00
public function label($label)
{
2017-11-03 23:22:13 +00:00
$this->properties['label'] = $label;
return $this;
2017-11-03 11:23:22 +00:00
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 11:23:22 +00:00
public function archive()
{
2017-11-03 23:22:13 +00:00
$this->properties['shouldArchive'] = 'true';
return $this;
2017-11-03 11:23:22 +00:00
}
2017-12-30 10:56:07 +00:00
/**
* @param string $label
*
* @return $this
*/
2017-11-03 11:23:22 +00:00
public function labelAndArchive($label)
{
2017-11-03 23:22:13 +00:00
$this->label($label)->archive();
return $this;
2017-11-03 11:23:22 +00:00
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 11:23:22 +00:00
public function spam()
{
2017-11-03 23:22:13 +00:00
$this->properties['shouldSpam'] = 'true';
$this->properties['shouldNeverSpam'] = 'false';
return $this;
2017-11-03 11:23:22 +00:00
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 11:23:22 +00:00
public function neverSpam()
{
2017-11-03 23:22:13 +00:00
$this->properties['shouldSpam'] = 'false';
$this->properties['shouldNeverSpam'] = 'true';
return $this;
2017-11-03 11:23:22 +00:00
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 11:23:22 +00:00
public function trash()
{
2017-11-03 23:22:13 +00:00
$this->properties['shouldTrash'] = 'true';
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 23:45:54 +00:00
public function read()
{
$this->properties['markAsRead'] = 'true';
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 23:45:54 +00:00
public function star()
{
$this->properties['shouldStar'] = 'true';
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @param string $to
*
* @return $this
*/
2017-11-03 23:45:54 +00:00
public function forward($to)
{
$this->properties['forwardTo'] = $to;
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 23:45:54 +00:00
public function important()
{
$this->properties['shouldAlwaysMarkAsImportant'] = 'true';
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @return $this
*/
2017-11-03 23:45:54 +00:00
public function notImportant()
{
$this->properties['shouldNeverMarkAsImportant'] = 'true';
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @param string $category
*
* @return $this
*/
2017-11-03 23:45:54 +00:00
public function categorise($category)
{
$this->properties['smartLabelToApply'] = $category;
return $this;
}
2017-12-30 10:56:07 +00:00
/**
* @return array
*/
2017-11-03 23:22:13 +00:00
public function getProperties()
{
return $this->properties;
2017-11-03 11:23:22 +00:00
}
}