Merged in feature_point_api_service (pull request #1) Test implementation of Point API services. Login field added to the User entity.

This commit is contained in:
Alexey Skobkin 2015-03-27 21:49:10 +03:00
commit c5dceb9a6f
7 changed files with 316 additions and 5 deletions

View file

@ -16,6 +16,7 @@ class AppKernel extends Kernel
new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Misd\GuzzleBundle\MisdGuzzleBundle(),
new Skobkin\Bundle\PointToolsBundle\SkobkinPointToolsBundle(), new Skobkin\Bundle\PointToolsBundle\SkobkinPointToolsBundle(),
); );

View file

@ -18,7 +18,8 @@
"symfony/monolog-bundle": "~2.4", "symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0,>=3.0.12", "sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2", "sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0" "incenteev/composer-parameter-handler": "~2.0",
"misd/guzzle-bundle": "~1.0"
}, },
"require-dev": { "require-dev": {
"sensio/generator-bundle": "~2.3" "sensio/generator-bundle": "~2.3"

169
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "73f15ad91f600008506b4294b7b7d01c", "hash": "9b2a01fca6691fa7cf3a44dba320f9a9",
"packages": [ "packages": [
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
@ -708,6 +708,101 @@
], ],
"time": "2014-12-16 13:45:01" "time": "2014-12-16 13:45:01"
}, },
{
"name": "guzzle/guzzle",
"version": "v3.9.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle3.git",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
"reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
"shasum": ""
},
"require": {
"ext-curl": "*",
"php": ">=5.3.3",
"symfony/event-dispatcher": "~2.1"
},
"replace": {
"guzzle/batch": "self.version",
"guzzle/cache": "self.version",
"guzzle/common": "self.version",
"guzzle/http": "self.version",
"guzzle/inflection": "self.version",
"guzzle/iterator": "self.version",
"guzzle/log": "self.version",
"guzzle/parser": "self.version",
"guzzle/plugin": "self.version",
"guzzle/plugin-async": "self.version",
"guzzle/plugin-backoff": "self.version",
"guzzle/plugin-cache": "self.version",
"guzzle/plugin-cookie": "self.version",
"guzzle/plugin-curlauth": "self.version",
"guzzle/plugin-error-response": "self.version",
"guzzle/plugin-history": "self.version",
"guzzle/plugin-log": "self.version",
"guzzle/plugin-md5": "self.version",
"guzzle/plugin-mock": "self.version",
"guzzle/plugin-oauth": "self.version",
"guzzle/service": "self.version",
"guzzle/stream": "self.version"
},
"require-dev": {
"doctrine/cache": "~1.3",
"monolog/monolog": "~1.0",
"phpunit/phpunit": "3.7.*",
"psr/log": "~1.0",
"symfony/class-loader": "~2.1",
"zendframework/zend-cache": "2.*,<2.3",
"zendframework/zend-log": "2.*,<2.3"
},
"suggest": {
"guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.9-dev"
}
},
"autoload": {
"psr-0": {
"Guzzle": "src/",
"Guzzle\\Tests": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Guzzle Community",
"homepage": "https://github.com/guzzle/guzzle/contributors"
}
],
"description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2015-03-18 18:23:50"
},
{ {
"name": "incenteev/composer-parameter-handler", "name": "incenteev/composer-parameter-handler",
"version": "v2.1.0", "version": "v2.1.0",
@ -884,6 +979,78 @@
], ],
"time": "2014-12-12 05:04:05" "time": "2014-12-12 05:04:05"
}, },
{
"name": "misd/guzzle-bundle",
"version": "v1.1.5",
"source": {
"type": "git",
"url": "https://github.com/misd-service-development/guzzle-bundle.git",
"reference": "555c105ef4ac66597a029fe634dee0fe4f9cb084"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/misd-service-development/guzzle-bundle/zipball/555c105ef4ac66597a029fe634dee0fe4f9cb084",
"reference": "555c105ef4ac66597a029fe634dee0fe4f9cb084",
"shasum": ""
},
"require": {
"guzzle/guzzle": "~3.0",
"php": ">=5.3.3",
"symfony/framework-bundle": "~2.2"
},
"conflict": {
"jms/serializer-bundle": "<0.11-dev",
"sensio/framework-extra-bundle": ">=4.0-dev"
},
"require-dev": {
"doctrine/cache": "~1.0",
"jms/serializer-bundle": "~0.11",
"phpunit/phpunit": "~4.3",
"sensio/framework-extra-bundle": "~2.2",
"symfony/monolog-bundle": "~2.2",
"symfony/yaml": "~2.2"
},
"suggest": {
"jms/serializer-bundle": "Serialize/deserialize objects to/from XML, JSON and YAML",
"sensio/framework-extra-bundle": "Provides a parameter converter",
"symfony/monolog-bundle": "Log requests"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"Misd\\GuzzleBundle\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Chris Wilkinson",
"email": "chris.wilkinson@admin.cam.ac.uk"
}
],
"description": "Integrates Guzzle into your Symfony2 application",
"homepage": "https://github.com/misd-service-development/guzzle-bundle",
"keywords": [
"Guzzle",
"api",
"bundle",
"client",
"curl",
"http",
"http client",
"rest",
"web service"
],
"time": "2014-12-01 08:29:51"
},
{ {
"name": "monolog/monolog", "name": "monolog/monolog",
"version": "1.12.0", "version": "1.12.0",

View file

@ -24,6 +24,13 @@ class User
*/ */
private $id; private $id;
/**
* @var string
*
* @ORM\Column(name="login", type="string", length=255)
*/
private $login;
/** /**
* @var string * @var string
* *
@ -77,6 +84,42 @@ class User
return $this->id; return $this->id;
} }
/**
* Set id of user (for API services only)
*
* @param integer $id
* @return User
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Set login
*
* @param string $login
* @return User
*/
public function setLogin($login)
{
$this->login = $login;
return $this;
}
/**
* Get login
*
* @return string
*/
public function getLogin()
{
return $this->login;
}
/** /**
* Set name * Set name
* *

View file

@ -1,4 +1,10 @@
services: services:
# skobkin_point_tools.example: skobkin_point_tools.http_client:
# class: Skobkin\Bundle\PointToolsBundle\Example class: %guzzle.client.class%
# arguments: [@service_id, "plain_value", %parameter%] arguments: [ "http://point.im/" ]
tags:
- { name: guzzle.client }
skobkin_point_tools.api_user:
class: Skobkin\Bundle\PointToolsBundle\UserApi
arguments: [ @skobkin_point_tools.http_client ]

View file

@ -0,0 +1,37 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\Service;
use Guzzle\Service\Client;
use Guzzle\Http\Message\Request as GuzzleRequest;
use Guzzle\Http\Message\Response as GuzzleResponse;
// @todo Implement commands: https://github.com/misd-service-development/guzzle-bundle/blob/master/Resources/doc/serialization.md
class AbstractApi
{
/**
* @var Client HTTP-client from Guzzle
*/
protected $client;
public function __construct($httpClient)
{
$this->client = $httpClient;
}
/**
* Make GET request and return Response object
*
* @param string $pathTemplate
* @param array $parameters
* @return GuzzleResponse
*/
public function sendGetRequest($pathTemplate, array $parameters = [])
{
$path = vsprintf($pathTemplate, $parameters);
$request = $this->client->get($path);
return $request->send();
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace Skobkin\Bundle\PointToolsBundle\Service;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
/**
* Basic Point.im user API functions from /api/user/*
*/
class UserApi extends AbstractApi
{
const PATH_USER_INFO = '/api/user/%s';
const PATH_USER_SUBSCRIPTIONS = '/api/user/%s/subscriptions';
const PATH_USER_SUBSCRIBERS = '/api/user/%s/subscribers';
/**
* @var string Base URL for user avatars
*/
protected $avatarsBaseUrl = '//i.point.im/a/';
public function getName()
{
return 'skobkin_point_tools_api_user';
}
/**
* Get user subscribers by his/her name
*
* @param string $login
* @return User[]
*/
public function getUserSubscribersByLogin($login)
{
$response = $this->sendGetRequest(self::PATH_USER_SUBSCRIBERS, [$login]);
$body = $response->getBody(true);
// @todo use JMSSerializer
$data = json_decode($body);
$users = [];
if (is_array($data)) {
foreach ($data as $apiUser) {
$user = new User();
$user->setId($apiUser->id);
$user->setLogin($apiUser->login);
$user->setName($apiUser->name);
$users[] = $user;
}
}
return $users;
}
}