2017 © Pedro Peláez
 

library yo-php

A Yo! client for PHP

image

black/yo-php

A Yo! client for PHP

  • Saturday, April 25, 2015
  • by pocky
  • Repository
  • 3 Watchers
  • 20 Stars
  • 32 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

Yo PHP

Yo PHP is a Yo client written in PHP. This library is still a work in progress., (*1)

Build Status HHVM Status Scrutinizer Code Quality SensioLabsInsight, (*2)

Installation

The recomanded way to install Yo PHP is through Composer:, (*3)

{
    "require": {
        "black/yo-php": "@stable"
    }
}

Protip: You should browse the black/yo-php page to choose a stable version to use, avoid the @stable meta constraint., (*4)

Yotip: You want to know when yo-php is updated? Add YOPHPCLIENT \o/!, (*5)

Usage

yoAll nutshell:

The yoAll method will send a yo to all your friends., (*6)


<?php $yo = new \Yo\Yo(['token' => 'yourtoken']); $send = new \Yo\Service\SendYoService($yo->getHttpClient(), $yo->getOptions()); $send->yoAll();

yo nutshell:

The yo method will send a yo to a dedicated username. This username MUST be in uppercase and this is your responsibility., (*7)


<?php $yo = new \Yo\Yo(['token' => 'yourtoken']); $send = new \Yo\Service\SendYoService($yo->getHttpClient(), $yo->getOptions()); $send->yo('USERNAME');

subscribers_count nutshell:

The subscribersCount method will retrieve the number of your subscribers. This is just a GET request with a json response., (*8)


<?php $yo = new \Yo\Yo(['token' => 'yourtoken']); $status = new \Yo\Service\StatusService($yo->getHttpClient(), $yo->getOptions()); $subscribers = $status->subscribersCount();

If you want to convert the json to an array just replace $status->subscribersCount() by $status->subscribersCount()->json(), (*9)

Send a link:

It is possible to send a link through Yo since 08/15/2014. Just add a link key to the constructor of new Yo() or use $yo->addLink('url://myurl.com');., (*10)

<?php

$yo   = new \Yo\Yo(['token' => 'yourtoken', 'link' => 'http://www.desicomments.com/dc/21/50927/50927.gif']);
$send = new \Yo\Service\SendYoService($yo->getHttpClient(), $yo->getOptions());
$send->yoAll();
<?php

$yo   = new \Yo\Yo(['token' => 'yourtoken');
$yo->addLink('http://www.desicomments.com/dc/21/50927/50927.gif');

$send = new \Yo\Service\SendYoService($yo->getHttpClient(), $yo->getOptions());
$send->yoAll();

Send a location:

It is possible to send your location since 10/07/2014. Just add a location key to the constructor of new Yo() or use this code., (*11)


$coordinates = new Geo\Coordinates(latitude, longitude); $yo->addLocation($coordinates);

Warning 1 It is not possible to receive or send link and location at the same time. When you construct a Yo with link and location, link is always overrided to null., (*12)

If you use ->add(Location|Link) function, the class will set the other parameter to null. The code is very simple so take your time and look at the src/spec/Yo/YoSpec.php., (*13)

Warning 2 Yo api not using a valid format for coordinates. They use ";" instead of "," so be aware of this and don't forget to explode/convert your values (see example below)., (*14)

Receive a yo:

During the registration process, Yo will ask to if you want to know when an Yo user Yo you. This pingback send you a GET request with the Yo username and location query parameters., (*15)

So... You need to create a dedicated controller. For example:, (*16)


<?php namespace Yo\Controller; class YoController { public function yoAction($username, $location = null) { $yoUser = new \Yo\Model\YoUser($username); if (null !== $location) { $location = explode(";", $location); $coordinates = new Geo\Coordinates($location[0], $location[1]); $yoUser->addLocation($location); } $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new YourSubscriber()); $yo = new \Yo\Service\ReceiveYoService($dispatcher); $yo->receive($yoUser); } }

As you can see, the ReceiveYoService will dispatch an event named yo.receive and getting his information from a YoUser., (*17)

I made the choice of create a true model because you maybe want to persist all your Yo friends in a database or anything you want., (*18)

A "default" subscriber is located in Yo/Event directory. This YoSubscriber will add a new line in your Monolog logs. If you want to use it, use this sample code (or see the ./tests/Yo/ReceiveYoServiceTest:, (*19)


<?php namespace Yo\Controller; class YoController { public function yoAction($username) { $yoUser = new \Yo\Model\YoUser($username); $logger = new Monolog\Logger(); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new \Yo\Event\YoSubscriber($logger)); $yo = new \Yo\Service\ReceiveYoService($dispatcher); $yo->receive($yoUser); } }

Running the tests

There is no development key for Yo so the only way to pass the tests suite is to replace the fake token and run the tests., (*20)

Contributing

See CONTRIBUTING file., (*21)

Credits

This README is heavily inspired by Hateoas library by the great @willdurand. This guy needs your PR for the sake of the REST in PHP., (*22)

Alexandre "pocky" Balmes alexandre@lablackroom.com. Send me Flattrs if you love my work, [buy me gift][9] or hire me!, (*23)

License

Yo PHP is released under the MIT License. See the bundled LICENSE file for details., (*24)

The Versions

15/08 2014

v0.5.0

0.5.0.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

10/07 2014

v0.4.1

0.4.1.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

10/07 2014

v0.4.0

0.4.0.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

08/07 2014

v0.3.0

0.3.0.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

05/07 2014

v0.2.3

0.2.3.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

05/07 2014

v0.2.2

0.2.2.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

05/07 2014

v0.2.1

0.2.1.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

05/07 2014

v0.2.0

0.2.0.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black

04/07 2014

v0.1.0

0.1.0.0

A Yo! client for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

yo black