From 615d55e1f409ff6c5ca07a808b4224b95b40b727 Mon Sep 17 00:00:00 2001 From: Leonardo Branco Shinagawa Date: Tue, 25 Feb 2014 23:24:53 -0300 Subject: [PATCH] added multiCall method for batch requests --- .gitignore | 2 +- composer.json | 9 +- composer.lock | 695 ++++++++++++++++++++ src/Rezzza/Flickr/ApiFactory.php | 70 +- src/Rezzza/Flickr/Http/AdapterInterface.php | 9 + src/Rezzza/Flickr/Http/GuzzleAdapter.php | 29 + test/ApiFactoryTest.php | 43 ++ test/GuzzleAdapterTest.php | 32 + test/bootstrap.php | 9 + test/config.php.dist | 14 + 10 files changed, 887 insertions(+), 25 deletions(-) create mode 100644 composer.lock create mode 100644 test/ApiFactoryTest.php create mode 100644 test/GuzzleAdapterTest.php create mode 100644 test/bootstrap.php create mode 100644 test/config.php.dist diff --git a/.gitignore b/.gitignore index 7d7bef3..92a4b83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ bin -composer.lock vendor +test/config.php \ No newline at end of file diff --git a/composer.json b/composer.json index f8fc7a2..a9f8ae7 100644 --- a/composer.json +++ b/composer.json @@ -13,13 +13,12 @@ "php": ">=5.3.2" }, "suggest": { - "guzzle/guzzle": "HTTP wrapper" + "guzzle/guzzle": "HTTP wrapper", + "guzzle/http": "Guzzle Adapter for http requests" }, "require-dev": { - "guzzle/http": "3.*" - }, - "suggest": { - "guzzle/http": "Guzzle Adapter for http requests" + "guzzle/http": "3.*", + "phpunit/phpunit": "3.7.32" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..40a6931 --- /dev/null +++ b/composer.lock @@ -0,0 +1,695 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "50908c0348bd3bdf395fa0030579e6a5", + "packages": [ + + ], + "packages-dev": [ + { + "name": "guzzle/common", + "version": "v3.8.1", + "target-dir": "Guzzle/Common", + "source": { + "type": "git", + "url": "https://github.com/guzzle/common.git", + "reference": "67f6c3fd04bae387d47c2a673fa623ed8f4189bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/common/zipball/67f6c3fd04bae387d47c2a673fa623ed8f4189bb", + "reference": "67f6c3fd04bae387d47c2a673fa623ed8f4189bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "symfony/event-dispatcher": ">=2.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Common": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Common libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "collection", + "common", + "event", + "exception" + ], + "time": "2014-01-28 22:29:15" + }, + { + "name": "guzzle/http", + "version": "v3.8.1", + "target-dir": "Guzzle/Http", + "source": { + "type": "git", + "url": "https://github.com/guzzle/http.git", + "reference": "565fd64be16d91c840f497c5de76f86d54a822d8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/http/zipball/565fd64be16d91c840f497c5de76f86d54a822d8", + "reference": "565fd64be16d91c840f497c5de76f86d54a822d8", + "shasum": "" + }, + "require": { + "guzzle/common": "self.version", + "guzzle/parser": "self.version", + "guzzle/stream": "self.version", + "php": ">=5.3.2" + }, + "suggest": { + "ext-curl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Http": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "HTTP libraries used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "client", + "curl", + "http", + "http client" + ], + "time": "2014-01-23 18:23:29" + }, + { + "name": "guzzle/parser", + "version": "v3.8.1", + "target-dir": "Guzzle/Parser", + "source": { + "type": "git", + "url": "https://github.com/guzzle/parser.git", + "reference": "3f52387052f2e4ef083145a0f73c3654aa14e086" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/parser/zipball/3f52387052f2e4ef083145a0f73c3654aa14e086", + "reference": "3f52387052f2e4ef083145a0f73c3654aa14e086", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Parser": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Interchangeable parsers used by Guzzle", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "URI Template", + "cookie", + "http", + "message", + "url" + ], + "time": "2013-10-24 00:04:09" + }, + { + "name": "guzzle/stream", + "version": "v3.8.1", + "target-dir": "Guzzle/Stream", + "source": { + "type": "git", + "url": "https://github.com/guzzle/stream.git", + "reference": "fa8af730ca714861c0001cfba64aaecc5f21bb96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/stream/zipball/fa8af730ca714861c0001cfba64aaecc5f21bb96", + "reference": "fa8af730ca714861c0001cfba64aaecc5f21bb96", + "shasum": "" + }, + "require": { + "guzzle/common": "self.version", + "php": ">=5.3.2" + }, + "suggest": { + "guzzle/http": "To convert Guzzle request objects to PHP streams" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle\\Stream": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle stream wrapper component", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "component", + "stream" + ], + "time": "2014-01-28 22:14:17" + }, + { + "name": "phpunit/php-code-coverage", + "version": "1.2.16", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "69e55e68481cf708a6db43aff0b504e31402fe27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/69e55e68481cf708a6db43aff0b504e31402fe27", + "reference": "69e55e68481cf708a6db43aff0b504e31402fe27", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": ">=1.3.0@stable", + "phpunit/php-text-template": ">=1.2.0@stable", + "phpunit/php-token-stream": ">=1.1.3@stable" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*@dev" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.0.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2014-02-25 03:34:05" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2013-10-10 15:34:57" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/5220af2a7929aa35cf663d97c89ad3d50cf5fa3e", + "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2013-09-13 04:58:23" + }, + { + "name": "phpunit/phpunit", + "version": "3.7.32", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "2752cbb9ea5bd84c2811b34b6953f76965ec7a2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2752cbb9ea5bd84c2811b34b6953f76965ec7a2f", + "reference": "2752cbb9ea5bd84c2811b34b6953f76965ec7a2f", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpunit/php-code-coverage": "~1.2.1", + "phpunit/php-file-iterator": ">=1.3.1", + "phpunit/php-text-template": ">=1.1.1", + "phpunit/php-timer": ">=1.0.4", + "phpunit/phpunit-mock-objects": "~1.2.0", + "symfony/yaml": "~2.0" + }, + "require-dev": { + "pear-pear.php.net/pear": "1.9.4" + }, + "suggest": { + "ext-json": "*", + "ext-simplexml": "*", + "ext-tokenizer": "*", + "phpunit/php-invoker": ">=1.1.0,<1.2.0" + }, + "bin": [ + "composer/bin/phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPUnit/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "", + "../../symfony/yaml/" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2014-02-25 03:47:29" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5794e3c5c5ba0fb037b11d8151add2a07fa82875", + "reference": "5794e3c5c5ba0fb037b11d8151add2a07fa82875", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-text-template": ">=1.1.1@stable" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHPUnit/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2013-01-13 10:24:48" + }, + { + "name": "symfony/event-dispatcher", + "version": "v2.4.2", + "target-dir": "Symfony/Component/EventDispatcher", + "source": { + "type": "git", + "url": "https://github.com/symfony/EventDispatcher.git", + "reference": "4708b8cd41984a5ba29fe7dd40716f7f761ac501" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/4708b8cd41984a5ba29fe7dd40716f7f761ac501", + "reference": "4708b8cd41984a5ba29fe7dd40716f7f761ac501", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/dependency-injection": "~2.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\EventDispatcher\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "http://symfony.com", + "time": "2014-02-11 13:52:09" + }, + { + "name": "symfony/yaml", + "version": "v2.4.2", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "bb6ddaf8956139d1b8c360b4b713ed0138e876b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/bb6ddaf8956139d1b8c360b4b713ed0138e876b3", + "reference": "bb6ddaf8956139d1b8c360b4b713ed0138e876b3", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2014-01-07 13:28:54" + } + ], + "aliases": [ + + ], + "minimum-stability": "stable", + "stability-flags": [ + + ], + "platform": { + "php": ">=5.3.2" + }, + "platform-dev": [ + + ] +} diff --git a/src/Rezzza/Flickr/ApiFactory.php b/src/Rezzza/Flickr/ApiFactory.php index 72fd588..7186d48 100644 --- a/src/Rezzza/Flickr/ApiFactory.php +++ b/src/Rezzza/Flickr/ApiFactory.php @@ -55,29 +55,27 @@ public function getMetadata() */ public function call($service = null, array $parameters = array(), $endpoint = null) { - if (null === $endpoint) { - $endpoint = $this->metadata->getEndpoint(); - } + $parameters = $this->buildParams($service, $parameters, $endpoint); - $default = array( - 'api_key' => $this->metadata->getApiKey(), - 'format' => 'rest', - ); + return $this->http->post($endpoint, $parameters); + } - if ($service) { - $default['method'] = $service; + /** + * @param array $calls + * An array of Calls + * Each call is an array with keys: service, parameters and endpoint + * + * @return \SimpleXMLElement[] + */ + public function multiCall(array $calls) + { + $requests = array(); + foreach ($calls as $call) { + $parameters = $this->buildParams($call['service'], $call['parameters'], $call['endpoint']); + $requests[] = array('url' => $call['endpoint'], 'data' => $parameters, 'headers' => array()); } - $parameters = array_merge($default, $parameters); - $parameters = array_filter($parameters, function($value) { - return null !== $value; - }); - - $parameters['api_sig'] = $this->buildSignature($parameters); - - $this->addOAuthParameters($endpoint, $parameters); - - return $this->http->post($endpoint, $parameters); + return $this->http->multiPost($requests); } /** @@ -211,4 +209,38 @@ protected function buildSignature(array $parameters) return md5($sigUnhashed); } + + /** + * @param string $service + * @param array $parameters + * @param string $endpoint + * + * @return array + */ + private function buildParams($service, array $parameters, &$endpoint) + { + if (null === $endpoint) { + $endpoint = $this->metadata->getEndpoint(); + } + + $default = array( + 'api_key' => $this->metadata->getApiKey(), + 'format' => 'rest', + ); + + if ($service) { + $default['method'] = $service; + } + + $parameters = array_merge($default, $parameters); + $parameters = array_filter($parameters, function ($value) { + return null !== $value; + }); + + $parameters['api_sig'] = $this->buildSignature($parameters); + + $this->addOAuthParameters($endpoint, $parameters); + + return $parameters; + } } diff --git a/src/Rezzza/Flickr/Http/AdapterInterface.php b/src/Rezzza/Flickr/Http/AdapterInterface.php index 05c7e39..e18e301 100644 --- a/src/Rezzza/Flickr/Http/AdapterInterface.php +++ b/src/Rezzza/Flickr/Http/AdapterInterface.php @@ -17,4 +17,13 @@ interface AdapterInterface * @return \SimpleXMLElement */ public function post($url, array $data = array(), array $headers = array()); + + /** + * @param array $requests + * An array of Requests + * Each Request is an array with $url, $data and $headers + * + * @return \SimpleXMLElement[] + */ + public function multiPost(array $requests); } diff --git a/src/Rezzza/Flickr/Http/GuzzleAdapter.php b/src/Rezzza/Flickr/Http/GuzzleAdapter.php index 566b27b..c3b8189 100644 --- a/src/Rezzza/Flickr/Http/GuzzleAdapter.php +++ b/src/Rezzza/Flickr/Http/GuzzleAdapter.php @@ -3,6 +3,7 @@ namespace Rezzza\Flickr\Http; use Guzzle\Http\Client; +use Guzzle\Http\Message\RequestInterface; /** * GuzzleAdapter @@ -36,6 +37,33 @@ public function post($url, array $data = array(), array $headers = array()) return $request->send() ->xml(); } + + /** + * @param array $requests + * An array of Requests + * Each Request is an array with keys: url, data and headers + * + * @return \SimpleXMLElement[] + */ + public function multiPost(array $requests) + { + $multi_request = $this->client->getCurlMulti(); + foreach ($requests as &$request) { + $request = $this->client->post($request['url'], $request['headers'], $request['data']); + $multi_request->add($request); + } + unset($request); + + $multi_request->send(); + + $responses = array(); + /** @var RequestInterface[] $requests */ + foreach ($requests as $request) { + $responses[] = $request->getResponse()->xml(); + } + + return $responses; + } /** * @return $client @@ -44,4 +72,5 @@ public function getClient() { return $this->client; } + } diff --git a/test/ApiFactoryTest.php b/test/ApiFactoryTest.php new file mode 100644 index 0000000..5d330e1 --- /dev/null +++ b/test/ApiFactoryTest.php @@ -0,0 +1,43 @@ +setOauthAccess($config['access_token'], $config['secret_access_token']); + + $this->api = new \Rezzza\Flickr\ApiFactory($metadata, new \Rezzza\Flickr\Http\GuzzleAdapter()); + } + + public function testMultiCall() + { + $recents_xml = $this->api->call('flickr.photos.getRecent'); + + $calls = array(); + foreach ($recents_xml->photos->photo as $photo_metadata_xml) { + $photo_id = (string)$photo_metadata_xml['id']; + $calls[] = array('service' => 'flickr.photos.getSizes', 'parameters' => array('photo_id' => $photo_id), 'endpoint' => null); + } + + $photos_xml = $this->api->multiCall($calls); + foreach ($photos_xml as $photo_xml) { + $this->assertInstanceOf('\SimpleXMLElement', $photo_xml); + $this->assertObjectNotHasAttribute('err', $photo_xml); + } + } + +} \ No newline at end of file diff --git a/test/GuzzleAdapterTest.php b/test/GuzzleAdapterTest.php new file mode 100644 index 0000000..12e4aa1 --- /dev/null +++ b/test/GuzzleAdapterTest.php @@ -0,0 +1,32 @@ +guzzle_adapter = new \Rezzza\Flickr\Http\GuzzleAdapter(); + } + + public function testMultiPost() { + $responses = $this->guzzle_adapter->multiPost(array( + array('url' => 'http://www.ebussola.com', 'data' => array(), 'headers' => array()), + array('url' => 'http://posttestserver.com', 'data' => array(), 'headers' => array()) + )); + $this->assertCount(2, $responses); + + foreach ($responses as $response) { + $this->assertInstanceOf('\SimpleXMLElement', $response); + } + } + +} \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..fbd1db8 --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,9 @@ + '', + 'secret' => '', + 'access_token' => '', + 'secret_access_token' => '' +); \ No newline at end of file