Skip to content

Commit

Permalink
Added isSubscribed method (#96)
Browse files Browse the repository at this point in the history
* Added isSubscribed method

Takes a users email, uses the getMember method, and checks if firstly
the user exists in the list, and then if that users status is subscribed

* Code Cleanup

* Updated README.md to incorporate changes

* Small change on README
  • Loading branch information
Luke Curtis authored and freekmurze committed Jul 12, 2017
1 parent a7dad91 commit a6210e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -36,6 +36,9 @@ Newsletter::getMemberActivity('lord.vetinari@discworld.com');
//Get the members for a given list, optionally filtered by passing a second array of parameters
Newsletter::getMembers();

//Check if a member is subscribed to a list
Newsletter::isSubscribed('rincewind@discworld.com');

//Returns a boolean
Newsletter::hasMember('greebo@discworld.com');

Expand Down Expand Up @@ -210,6 +213,12 @@ There's also a convenience method to check if someone is already subscribed:
Newsletter::hasMember('nanny.ogg@discworld.com'); //returns a bool
```

In addition to this you can also check if a user is subscribed to your list:

```php
Newsletter::isSubscribed('lord.vetinari@discworld.com'); //returns a bool
```

### Creating a campaign

This is how you create a campaign:
Expand Down
21 changes: 21 additions & 0 deletions src/Newsletter.php
Expand Up @@ -137,6 +137,27 @@ public function hasMember($email, $listName = '')
return true;
}

/**
* @param string $email
* @param string $listName
*
* @return bool
*/
public function isSubscribed($email, $listName = '')
{
$response = $this->getMember($email, $listName);

if (! isset($response)) {
return false;
}

if ($response['status'] != 'subscribed') {
return false;
}

return true;
}

/**
* @param $email
* @param string $listName
Expand Down

0 comments on commit a6210e0

Please sign in to comment.