Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
Expand All @@ -20,9 +32,21 @@ $yo = new Yo($apiKey);
// Send a Yo to all your subscribers
$yo->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
?>
Expand Down
26 changes: 20 additions & 6 deletions yo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down