diff --git a/README.md b/README.md index d0140ee..3920313 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,19 @@ yo-php Send Yos from your PHP app with 2 lines of code. -## Example +## New in Version 0.3 + +Send your location! + +This only works when sending a Yo to an individual user, not to all your subscribers at once. Use method "userWithLocation". + +## New in Version 0.2 + +Send links with your Yos. + +When you send a link along with your Yo and the user taps on it, it'll open a browser to your link instead of opening the Yo app. + +## Examples ```php all(); +// Send a Yo with a link to all your subscribers +$link = 'http://www.mysuperawesomewebpage.com/'; +$yo->all($link); + // Send a Yo to one user $yo->user('USERNAME'); +// Send a Yo with a link to one user +$link = 'http://www.mysuperawesomewebpage.com/user/USERNAME/'; +$yo->user('USERNAME', $link); + +// Send a Yo with a location (format is a string like LAT;LNG) +$location = '-34.6158527;-58.4332985'; +$yo->userWithLocation('USERNAME', $location); + // Get number of subscribers $count = $yo->subscribers(); // returns an int or false ?> diff --git a/yo.php b/yo.php index fb3d282..827062a 100644 --- a/yo.php +++ b/yo.php @@ -14,14 +14,20 @@ public function __construct($apiKey) { $this->_apiKey = $apiKey; } - public function user($username) { + public function user($username, $link = null) { if ($username != '') { - $this->processRequest($username); + $this->processRequest($username, $link, null); } } - public function all() { - $this->processRequest(); + public function userWithLocation($username, $location = null) { + if ($username != '') { + $this->processRequest($username, null, $location); + } + } + + public function all($link = null) { + $this->processRequest($username = null, $link, null); } public function subscribers() { @@ -50,18 +56,26 @@ public function subscribers() { return false; } - private function processRequest($username = '') { + private function processRequest($username = null, $link = null, $location = null) { $postFields = array( 'api_token' => $this->_apiKey ); $url = $this->urls['all']; - if ($username != '') { + if ($username != null) { $postFields['username'] = $username; $url = $this->urls['user']; } + if ($link != null) { + $postFields['link'] = $link; + } + + if ($location != null) { + $postFields['location'] = $location; + } + $options = array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true,