mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-03-13 05:26:57 +00:00
Add docblocks, small fixes
This commit is contained in:
parent
9097da2972
commit
728d284f09
|
@ -4,12 +4,21 @@ namespace Opdavies\GmailFilterBuilder;
|
|||
|
||||
class Builder
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $filters = [];
|
||||
|
||||
public function __construct(array $filters) {
|
||||
public function __construct(array $filters)
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build XML for a set of filters.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$prefix = "<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>";
|
||||
|
@ -23,6 +32,8 @@ class Builder
|
|||
}
|
||||
|
||||
/**
|
||||
* Build XML for an entry.
|
||||
*
|
||||
* @param array $items
|
||||
*
|
||||
* @return string
|
||||
|
|
|
@ -4,8 +4,16 @@ namespace Opdavies\GmailFilterBuilder;
|
|||
|
||||
class Filter
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $properties = [];
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function has($value)
|
||||
{
|
||||
$this->properties['hasTheWord'] = $value;
|
||||
|
@ -13,6 +21,11 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function hasNot($value)
|
||||
{
|
||||
$this->properties['doesNotHaveTheWord'] = $value;
|
||||
|
@ -20,26 +33,39 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $values
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function from($values)
|
||||
{
|
||||
$this->properties['from'] = collect($values)
|
||||
->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
$this->properties['from'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $values
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function to($values)
|
||||
{
|
||||
$this->properties['to'] = collect($values)
|
||||
->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
$this->properties['to'] = collect($values)->map(function ($value) {
|
||||
return trim($value);
|
||||
})->all();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $subject
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function subject($subject)
|
||||
{
|
||||
$this->properties['subject'] = $subject;
|
||||
|
@ -47,6 +73,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function hasAttachment()
|
||||
{
|
||||
$this->properties['hasAttachment'] = 'true';
|
||||
|
@ -54,6 +83,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function excludeChats()
|
||||
{
|
||||
$this->properties['excludeChats'] = 'true';
|
||||
|
@ -61,6 +93,11 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function label($label)
|
||||
{
|
||||
$this->properties['label'] = $label;
|
||||
|
@ -68,6 +105,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function archive()
|
||||
{
|
||||
$this->properties['shouldArchive'] = 'true';
|
||||
|
@ -75,6 +115,11 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $label
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function labelAndArchive($label)
|
||||
{
|
||||
$this->label($label)->archive();
|
||||
|
@ -82,6 +127,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function spam()
|
||||
{
|
||||
$this->properties['shouldSpam'] = 'true';
|
||||
|
@ -90,6 +138,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function neverSpam()
|
||||
{
|
||||
$this->properties['shouldSpam'] = 'false';
|
||||
|
@ -98,6 +149,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function trash()
|
||||
{
|
||||
$this->properties['shouldTrash'] = 'true';
|
||||
|
@ -105,6 +159,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
$this->properties['markAsRead'] = 'true';
|
||||
|
@ -112,6 +169,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function star()
|
||||
{
|
||||
$this->properties['shouldStar'] = 'true';
|
||||
|
@ -119,6 +179,11 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function forward($to)
|
||||
{
|
||||
$this->properties['forwardTo'] = $to;
|
||||
|
@ -126,6 +191,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function important()
|
||||
{
|
||||
$this->properties['shouldAlwaysMarkAsImportant'] = 'true';
|
||||
|
@ -133,6 +201,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function notImportant()
|
||||
{
|
||||
$this->properties['shouldNeverMarkAsImportant'] = 'true';
|
||||
|
@ -140,6 +211,11 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $category
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function categorise($category)
|
||||
{
|
||||
$this->properties['smartLabelToApply'] = $category;
|
||||
|
@ -147,6 +223,9 @@ class Filter
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
|
|
|
@ -55,8 +55,7 @@ class FilterTest extends TestCase
|
|||
// Ensure that we can set multiple from addresses.
|
||||
$this->assertEquals(
|
||||
['from' => ['foo@example.com', 'bar@example.com']],
|
||||
$this->filter->from(['foo@example.com', 'bar@example.com'])
|
||||
->getProperties()
|
||||
$this->filter->from(['foo@example.com', 'bar@example.com'])->getProperties()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -72,8 +71,7 @@ class FilterTest extends TestCase
|
|||
|
||||
$this->assertEquals(
|
||||
['to' => ['bar@example.com', 'baz@example.com']],
|
||||
$this->filter->to(['bar@example.com', 'baz@example.com'])
|
||||
->getProperties()
|
||||
$this->filter->to(['bar@example.com', 'baz@example.com'])->getProperties()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue