diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index 609dda4..072868a 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -19,4 +19,7 @@ parameters: secret: ThisTokenIsNotSoSecretChangeIt # Brickset API key obtainable at http://brickset.com/tools/webservices/requestkey - brickset_apikey: ~ \ No newline at end of file + brickset_apikey: ~ + + # Rebrickable API key obtainable at http://rebrickable.com/api/ + rebrickable_apikey: ~ \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 0a3f1ab..1b24556 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -1,4 +1,7 @@ services: client.brickset: class: AppBundle\Client\Brickset\Brickset - arguments: ['%brickset_apikey%'] \ No newline at end of file + arguments: ['%brickset_apikey%'] + client.rebrickable: + class: AppBundle\Client\Rebrickable\Rebrickable + arguments: ['%rebrickable_apikey%'] \ No newline at end of file diff --git a/composer.json b/composer.json index 88499d0..c5e4989 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "symfony/polyfill-apcu": "^1.0", "sensio/distribution-bundle": "^5.0", "sensio/framework-extra-bundle": "^3.0.2", - "incenteev/composer-parameter-handler": "^2.0" + "incenteev/composer-parameter-handler": "^2.0", + "guzzlehttp/guzzle": "^6.2" }, "require-dev": { "sensio/generator-bundle": "^3.0", diff --git a/composer.lock b/composer.lock index 67b6e8b..9578e75 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "4be3c063eb6331a8a3de74d3393dee92", + "hash": "6a0a087c1e2fc52f43e0cdb32405a4f1", + "content-hash": "6931eab7f98ea98f61f97e66ceeed392", "packages": [ { "name": "doctrine/annotations", @@ -72,7 +73,7 @@ "docblock", "parser" ], - "time": "2015-08-31T12:32:49+00:00" + "time": "2015-08-31 12:32:49" }, { "name": "doctrine/cache", @@ -142,7 +143,7 @@ "cache", "caching" ], - "time": "2015-12-31T16:37:02+00:00" + "time": "2015-12-31 16:37:02" }, { "name": "doctrine/collections", @@ -208,7 +209,7 @@ "collections", "iterator" ], - "time": "2015-04-14T22:21:58+00:00" + "time": "2015-04-14 22:21:58" }, { "name": "doctrine/common", @@ -281,7 +282,7 @@ "persistence", "spl" ], - "time": "2015-12-25T13:18:31+00:00" + "time": "2015-12-25 13:18:31" }, { "name": "doctrine/dbal", @@ -352,7 +353,7 @@ "persistence", "queryobject" ], - "time": "2016-09-09T19:13:33+00:00" + "time": "2016-09-09 19:13:33" }, { "name": "doctrine/doctrine-bundle", @@ -433,7 +434,7 @@ "orm", "persistence" ], - "time": "2016-08-10T15:35:22+00:00" + "time": "2016-08-10 15:35:22" }, { "name": "doctrine/doctrine-cache-bundle", @@ -521,7 +522,7 @@ "cache", "caching" ], - "time": "2016-01-26T17:28:51+00:00" + "time": "2016-01-26 17:28:51" }, { "name": "doctrine/inflector", @@ -588,7 +589,7 @@ "singularize", "string" ], - "time": "2015-11-06T14:35:42+00:00" + "time": "2015-11-06 14:35:42" }, { "name": "doctrine/instantiator", @@ -642,7 +643,7 @@ "constructor", "instantiate" ], - "time": "2015-06-14T21:17:01+00:00" + "time": "2015-06-14 21:17:01" }, { "name": "doctrine/lexer", @@ -696,7 +697,7 @@ "lexer", "parser" ], - "time": "2014-09-09T13:34:57+00:00" + "time": "2014-09-09 13:34:57" }, { "name": "doctrine/orm", @@ -772,7 +773,178 @@ "database", "orm" ], - "time": "2016-09-10T18:51:13+00:00" + "time": "2016-09-10 18:51:13" + }, + { + "name": "guzzlehttp/guzzle", + "version": "6.2.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60", + "reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.3.1", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0", + "psr/log": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.2-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2016-10-08 15:01:37" + }, + { + "name": "guzzlehttp/promises", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/c10d860e2a9595f8883527fa0021c7da9e65f579", + "reference": "c10d860e2a9595f8883527fa0021c7da9e65f579", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-05-18 16:56:05" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2016-06-24 23:00:38" }, { "name": "incenteev/composer-parameter-handler", @@ -823,7 +995,7 @@ "keywords": [ "parameters management" ], - "time": "2015-11-10T17:04:01+00:00" + "time": "2015-11-10 17:04:01" }, { "name": "jdorn/sql-formatter", @@ -873,7 +1045,7 @@ "highlight", "sql" ], - "time": "2014-01-12T16:20:24+00:00" + "time": "2014-01-12 16:20:24" }, { "name": "monolog/monolog", @@ -951,7 +1123,7 @@ "logging", "psr-3" ], - "time": "2016-07-29T03:23:52+00:00" + "time": "2016-07-29 03:23:52" }, { "name": "paragonie/random_compat", @@ -999,7 +1171,7 @@ "pseudorandom", "random" ], - "time": "2016-10-17T15:23:22+00:00" + "time": "2016-10-17 15:23:22" }, { "name": "psr/cache", @@ -1045,7 +1217,57 @@ "psr", "psr-6" ], - "time": "2016-08-06T20:24:11+00:00" + "time": "2016-08-06 20:24:11" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06 14:39:51" }, { "name": "psr/log", @@ -1092,7 +1314,7 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2016-10-10 12:19:37" }, { "name": "sensio/distribution-bundle", @@ -1144,7 +1366,7 @@ "configuration", "distribution" ], - "time": "2016-10-08T18:50:33+00:00" + "time": "2016-10-08 18:50:33" }, { "name": "sensio/framework-extra-bundle", @@ -1206,7 +1428,7 @@ "annotations", "controllers" ], - "time": "2016-03-25T17:08:27+00:00" + "time": "2016-03-25 17:08:27" }, { "name": "sensiolabs/security-checker", @@ -1250,7 +1472,7 @@ } ], "description": "A security checker for your composer.lock", - "time": "2016-09-23T18:09:57+00:00" + "time": "2016-09-23 18:09:57" }, { "name": "swiftmailer/swiftmailer", @@ -1303,7 +1525,7 @@ "mail", "mailer" ], - "time": "2016-07-08T11:51:25+00:00" + "time": "2016-07-08 11:51:25" }, { "name": "symfony/monolog-bundle", @@ -1363,7 +1585,7 @@ "log", "logging" ], - "time": "2016-04-13T16:21:01+00:00" + "time": "2016-04-13 16:21:01" }, { "name": "symfony/polyfill-apcu", @@ -1416,7 +1638,7 @@ "portable", "shim" ], - "time": "2016-05-18T14:26:46+00:00" + "time": "2016-05-18 14:26:46" }, { "name": "symfony/polyfill-intl-icu", @@ -1474,7 +1696,7 @@ "portable", "shim" ], - "time": "2016-05-18T14:26:46+00:00" + "time": "2016-05-18 14:26:46" }, { "name": "symfony/polyfill-mbstring", @@ -1533,7 +1755,7 @@ "portable", "shim" ], - "time": "2016-05-18T14:26:46+00:00" + "time": "2016-05-18 14:26:46" }, { "name": "symfony/polyfill-php56", @@ -1589,7 +1811,7 @@ "portable", "shim" ], - "time": "2016-05-18T14:26:46+00:00" + "time": "2016-05-18 14:26:46" }, { "name": "symfony/polyfill-php70", @@ -1648,7 +1870,7 @@ "portable", "shim" ], - "time": "2016-05-18T14:26:46+00:00" + "time": "2016-05-18 14:26:46" }, { "name": "symfony/polyfill-util", @@ -1700,7 +1922,7 @@ "polyfill", "shim" ], - "time": "2016-05-18T14:26:46+00:00" + "time": "2016-05-18 14:26:46" }, { "name": "symfony/swiftmailer-bundle", @@ -1757,7 +1979,7 @@ ], "description": "Symfony SwiftmailerBundle", "homepage": "http://symfony.com", - "time": "2016-01-15T16:41:20+00:00" + "time": "2016-01-15 16:41:20" }, { "name": "symfony/symfony", @@ -1898,7 +2120,7 @@ "keywords": [ "framework" ], - "time": "2016-10-27T02:38:53+00:00" + "time": "2016-10-27 02:38:53" }, { "name": "twig/twig", @@ -1959,7 +2181,7 @@ "keywords": [ "templating" ], - "time": "2016-10-25T19:17:17+00:00" + "time": "2016-10-25 19:17:17" } ], "packages-dev": [ @@ -2013,7 +2235,7 @@ } ], "description": "This bundle generates code for you", - "time": "2016-10-10T14:17:42+00:00" + "time": "2016-10-10 14:17:42" }, { "name": "symfony/phpunit-bridge", @@ -2068,7 +2290,66 @@ ], "description": "Symfony PHPUnit Bridge", "homepage": "https://symfony.com", - "time": "2016-08-19T06:48:39+00:00" + "time": "2016-08-19 06:48:39" + }, + { + "name": "symfony/polyfill-iconv", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-iconv.git", + "reference": "b287e8554b1ffd9b5b20b5df940d906930ff4a10" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/b287e8554b1ffd9b5b20b5df940d906930ff4a10", + "reference": "b287e8554b1ffd9b5b20b5df940d906930ff4a10", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-iconv": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Iconv\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Iconv extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "iconv", + "polyfill", + "portable", + "shim" + ], + "time": "2016-05-18 14:26:46" } ], "aliases": [], diff --git a/src/AppBundle/Client/Rebrickable/Entity/Part.php b/src/AppBundle/Client/Rebrickable/Entity/Part.php new file mode 100644 index 0000000..7d172a7 --- /dev/null +++ b/src/AppBundle/Client/Rebrickable/Entity/Part.php @@ -0,0 +1,162 @@ +id = $part_id; + $this->name = $part_name; + $this->category = $category; + $this->typeId = $part_type_id; + $this->colors = $colors; + $this->external_part_ids = $external_part_ids; + $this->part_url = $part_url; + $this->part_img_url = $part_img_url; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @param mixed $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * @return mixed + */ + public function getCategory() + { + return $this->category; + } + + /** + * @param mixed $category + */ + public function setCategory($category) + { + $this->category = $category; + } + + /** + * @return mixed + */ + public function getTypeId() + { + return $this->typeId; + } + + /** + * @param mixed $typeId + */ + public function setTypeId($typeId) + { + $this->typeId = $typeId; + } + + /** + * @return mixed + */ + public function getColors() + { + return $this->colors; + } + + /** + * @param mixed $colors + */ + public function setColors($colors) + { + $this->colors = $colors; + } + + /** + * @return mixed + */ + public function getExternalPartIds() + { + return $this->external_part_ids; + } + + /** + * @param mixed $external_part_ids + */ + public function setExternalPartIds($external_part_ids) + { + $this->external_part_ids = $external_part_ids; + } + + /** + * @return mixed + */ + public function getPartUrl() + { + return $this->part_url; + } + + /** + * @param mixed $part_url + */ + public function setPartUrl($part_url) + { + $this->part_url = $part_url; + } + + /** + * @return mixed + */ + public function getPartImgUrl() + { + return $this->part_img_url; + } + + /** + * @param mixed $part_img_url + */ + public function setPartImgUrl($part_img_url) + { + $this->part_img_url = $part_img_url; + } +} \ No newline at end of file diff --git a/src/AppBundle/Client/Rebrickable/Rebrickable.php b/src/AppBundle/Client/Rebrickable/Rebrickable.php new file mode 100644 index 0000000..a9e312d --- /dev/null +++ b/src/AppBundle/Client/Rebrickable/Rebrickable.php @@ -0,0 +1,127 @@ +client = new Client(['base_uri' => self::BASE_URI]); + $this->apiKey = $apiKey; + } + + + private function call($method, $parameters) { + $parameters['query']['key'] = $this->apiKey; + $parameters['query']['format'] = self::FORMAT; + + try + { + $response = $this->client->request('GET', $method, $parameters); + + if ($response->getStatusCode() === 200) + { + $content = $response->getBody()->getContents(); + if($content === 'INVALIDKEY') { + //TODO + throw new LogicException("Invalid API Key"); + } else { + return $content; + } + } + else + { + //TODO + throw new LogicException($response->getStatusCode()); + } + } catch (ConnectException $e) { + //TODO + throw new LogicException($e->getMessage()); + } catch (ClientException $e) { + //TODO + throw new LogicException($e->getMessage()); + } + } + + /** + * Get a list of all parts (normal + spare) used in a set. + * + * @param string $setName unique rebrickable set name + * + * @return array + */ + public function getSetParts($setName) + { + $parameters = [ + 'query' => [ + 'set' => $setName, + ] + ]; + + return $this->call('get_set_parts', $parameters); + } + + /** + * Get details about a specific part. + * + * @param $partID + * + * @return + */ + public function getPart($partID) + { + $parameters = [ + 'query' => [ + 'part_id' => $partID, + 'inc_ext' => 1 + ] + ]; + + return $this->call('get_part',$parameters); + } + + /** + * Get the list of colors used by all parts. + * + * @return + */ + public function getColors() + { + return $this->call('get_colors', []); + } + + /** + * Get the list of sets that a specific part/color appears in. + * + * @param $partID + * @param $colorID + * + * @return + */ + public function getPartSets($partID, $colorID) + { + $parameters = [ + 'query' => [ + 'part_id' => $partID, + 'color_id' => $colorID + ] + ]; + + return $this->call('get_part_sets', $parameters); + } +}