mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 04:40:08 -07:00
Update Rebrickable client
This commit is contained in:
parent
2d57bc8ed3
commit
a2e270de14
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AppBundle\Client\Rebrickable\Converter;
|
||||||
|
|
||||||
|
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
|
||||||
|
|
||||||
|
class PartPropertyNameConverter implements NameConverterInterface
|
||||||
|
{
|
||||||
|
public function normalize($propertyName)
|
||||||
|
{
|
||||||
|
return $propertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function denormalize($propertyName)
|
||||||
|
{
|
||||||
|
switch ($propertyName) {
|
||||||
|
case 'part_name': return 'name';
|
||||||
|
case 'part_id': return 'id';
|
||||||
|
case 'part_type_id': return 'typeId';
|
||||||
|
case 'rb_color_id': return 'colorId';
|
||||||
|
default: return $propertyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
233
src/AppBundle/Client/Rebrickable/Entity/Color.php
Normal file
233
src/AppBundle/Client/Rebrickable/Entity/Color.php
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: hubnedav
|
||||||
|
* Date: 11/18/16
|
||||||
|
* Time: 1:45 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace AppBundle\Client\Rebrickable\Entity;
|
||||||
|
|
||||||
|
|
||||||
|
class Color
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Internal Rebrickable color ID used
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $rb_color_id;
|
||||||
|
/**
|
||||||
|
* Array of mapped LDraw colors
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $ldraw_color_id;
|
||||||
|
/**
|
||||||
|
* Array of mapped BrickLink colors
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $bricklink_color_id;
|
||||||
|
/**
|
||||||
|
* Array of mapped BrickOwl colors
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $brickowl_color_id;
|
||||||
|
/**
|
||||||
|
* Color name
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $color_name;
|
||||||
|
/**
|
||||||
|
* Number of parts the color appears in.
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $num_parts;
|
||||||
|
/**
|
||||||
|
* Number of sets the color appears in.
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $num_sets;
|
||||||
|
/**
|
||||||
|
* First year it was used.
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $year1;
|
||||||
|
/**
|
||||||
|
* Last year it was used.
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $year2;
|
||||||
|
/**
|
||||||
|
* Hex codes for the RGB value of this color: RRGGBB
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $rgb;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getRbColorId()
|
||||||
|
{
|
||||||
|
return $this->rb_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $rb_color_id
|
||||||
|
*/
|
||||||
|
public function setRbColorId($rb_color_id)
|
||||||
|
{
|
||||||
|
$this->rb_color_id = $rb_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getLdrawColorId()
|
||||||
|
{
|
||||||
|
return $this->ldraw_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $ldraw_color_id
|
||||||
|
*/
|
||||||
|
public function setLdrawColorId($ldraw_color_id)
|
||||||
|
{
|
||||||
|
$this->ldraw_color_id = $ldraw_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getBricklinkColorId()
|
||||||
|
{
|
||||||
|
return $this->bricklink_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $bricklink_color_id
|
||||||
|
*/
|
||||||
|
public function setBricklinkColorId($bricklink_color_id)
|
||||||
|
{
|
||||||
|
$this->bricklink_color_id = $bricklink_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getBrickowlColorId()
|
||||||
|
{
|
||||||
|
return $this->brickowl_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $brickowl_color_id
|
||||||
|
*/
|
||||||
|
public function setBrickowlColorId($brickowl_color_id)
|
||||||
|
{
|
||||||
|
$this->brickowl_color_id = $brickowl_color_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getColorName()
|
||||||
|
{
|
||||||
|
return $this->color_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $color_name
|
||||||
|
*/
|
||||||
|
public function setColorName($color_name)
|
||||||
|
{
|
||||||
|
$this->color_name = $color_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getNumParts()
|
||||||
|
{
|
||||||
|
return $this->num_parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $num_parts
|
||||||
|
*/
|
||||||
|
public function setNumParts($num_parts)
|
||||||
|
{
|
||||||
|
$this->num_parts = $num_parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getNumSets()
|
||||||
|
{
|
||||||
|
return $this->num_sets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $num_sets
|
||||||
|
*/
|
||||||
|
public function setNumSets($num_sets)
|
||||||
|
{
|
||||||
|
$this->num_sets = $num_sets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getYear1()
|
||||||
|
{
|
||||||
|
return $this->year1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $year1
|
||||||
|
*/
|
||||||
|
public function setYear1($year1)
|
||||||
|
{
|
||||||
|
$this->year1 = $year1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getYear2()
|
||||||
|
{
|
||||||
|
return $this->year2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $year2
|
||||||
|
*/
|
||||||
|
public function setYear2($year2)
|
||||||
|
{
|
||||||
|
$this->year2 = $year2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRgb()
|
||||||
|
{
|
||||||
|
return $this->rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $rgbl
|
||||||
|
*/
|
||||||
|
public function setRgb($rgb)
|
||||||
|
{
|
||||||
|
$this->rgb = $rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -3,160 +3,242 @@
|
|||||||
* Created by PhpStorm.
|
* Created by PhpStorm.
|
||||||
* User: hubnedav
|
* User: hubnedav
|
||||||
* Date: 11/11/16
|
* Date: 11/11/16
|
||||||
* Time: 12:45 AM
|
* Time: 12:45 AM.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace AppBundle\Client\Rebrickable\Entity;
|
namespace AppBundle\Client\Rebrickable\Entity;
|
||||||
|
|
||||||
|
|
||||||
class Part
|
class Part
|
||||||
{
|
{
|
||||||
protected $id;
|
/**
|
||||||
protected $name;
|
* Part ID.
|
||||||
protected $category;
|
*
|
||||||
protected $typeId;
|
* @var int
|
||||||
protected $colors;
|
*/
|
||||||
protected $external_part_ids;
|
private $id;
|
||||||
protected $part_url;
|
/**
|
||||||
protected $part_img_url;
|
* Quantity of part in set returned from getSetParts.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $qty;
|
||||||
|
/**
|
||||||
|
* Part Name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
/**
|
||||||
|
* Year the part first appeared in sets.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $year1;
|
||||||
|
/**
|
||||||
|
* Year the part was last seen in sets.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $year2;
|
||||||
|
/**
|
||||||
|
* Part category/type description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $category;
|
||||||
|
|
||||||
public function __construct($part_id, $part_name, $category, $part_type_id, $colors, $external_part_ids, $part_url, $part_img_url)
|
private $typeId;
|
||||||
{
|
|
||||||
$this->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
|
* Array of colors the part appears in.
|
||||||
*/
|
*
|
||||||
public function getId()
|
* @var array
|
||||||
{
|
*/
|
||||||
return $this->id;
|
private $colors;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private $colorId;
|
||||||
* @param mixed $id
|
|
||||||
*/
|
|
||||||
public function setId($id)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* Array of related Part IDs used by external systems.
|
||||||
*/
|
*
|
||||||
public function getName()
|
* @var array
|
||||||
{
|
*/
|
||||||
return $this->name;
|
private $external_part_ids;
|
||||||
}
|
/**
|
||||||
|
* Rebrickable URL to the Part Details page.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $part_url;
|
||||||
|
/**
|
||||||
|
* Rebrickable URL of the main part image (tries to use most common color).
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $part_img_url;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $name
|
|
||||||
*/
|
|
||||||
public function setName($name)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public function __construct()
|
||||||
* @return mixed
|
{
|
||||||
*/
|
}
|
||||||
public function getCategory()
|
|
||||||
{
|
|
||||||
return $this->category;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $category
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function setCategory($category)
|
public function getId()
|
||||||
{
|
{
|
||||||
$this->category = $category;
|
return $this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @param $part_id
|
||||||
*/
|
*/
|
||||||
public function getTypeId()
|
public function setId($id)
|
||||||
{
|
{
|
||||||
return $this->typeId;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $typeId
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function setTypeId($typeId)
|
public function getQty()
|
||||||
{
|
{
|
||||||
$this->typeId = $typeId;
|
return $this->qty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @param $qty
|
||||||
*/
|
*/
|
||||||
public function getColors()
|
public function setQty($qty)
|
||||||
{
|
{
|
||||||
return $this->colors;
|
$this->qty = $qty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $colors
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function setColors($colors)
|
public function getName()
|
||||||
{
|
{
|
||||||
$this->colors = $colors;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @param mixed $name
|
||||||
*/
|
*/
|
||||||
public function getExternalPartIds()
|
public function setName($name)
|
||||||
{
|
{
|
||||||
return $this->external_part_ids;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $external_part_ids
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function setExternalPartIds($external_part_ids)
|
public function getYear1()
|
||||||
{
|
{
|
||||||
$this->external_part_ids = $external_part_ids;
|
return $this->year1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @param mixed $year1
|
||||||
*/
|
*/
|
||||||
public function getPartUrl()
|
public function setYear1($year1)
|
||||||
{
|
{
|
||||||
return $this->part_url;
|
$this->year1 = $year1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $part_url
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function setPartUrl($part_url)
|
public function getYear2()
|
||||||
{
|
{
|
||||||
$this->part_url = $part_url;
|
return $this->year2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @param mixed $year2
|
||||||
*/
|
*/
|
||||||
public function getPartImgUrl()
|
public function setYear2($year2)
|
||||||
{
|
{
|
||||||
return $this->part_img_url;
|
$this->year2 = $year2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $part_img_url
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function setPartImgUrl($part_img_url)
|
public function getCategory()
|
||||||
{
|
{
|
||||||
$this->part_img_url = $part_img_url;
|
return $this->category;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $category
|
||||||
|
*/
|
||||||
|
public function setCategory($category)
|
||||||
|
{
|
||||||
|
$this->category = $category;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 $part_img_url
|
||||||
|
*/
|
||||||
|
public function setPartImgUrl($part_img_url)
|
||||||
|
{
|
||||||
|
$this->part_img_url = $part_img_url;
|
||||||
|
}
|
||||||
}
|
}
|
80
src/AppBundle/Client/Rebrickable/Entity/Set.php
Normal file
80
src/AppBundle/Client/Rebrickable/Entity/Set.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AppBundle\Client\Rebrickable\Entity;
|
||||||
|
|
||||||
|
class Set
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Set ID if relevan to type.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $set_id;
|
||||||
|
/**
|
||||||
|
* Set description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $name;
|
||||||
|
/**
|
||||||
|
* Number of sets the part appears in.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $num_parts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getSetId()
|
||||||
|
{
|
||||||
|
return $this->set_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $set_id
|
||||||
|
*/
|
||||||
|
public function setSetId($set_id)
|
||||||
|
{
|
||||||
|
$this->set_id = $set_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getNumParts()
|
||||||
|
{
|
||||||
|
return $this->num_parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $num_parts
|
||||||
|
*/
|
||||||
|
public function setNumParts($num_parts)
|
||||||
|
{
|
||||||
|
$this->num_parts = $num_parts;
|
||||||
|
}
|
||||||
|
}
|
@ -2,126 +2,188 @@
|
|||||||
|
|
||||||
namespace AppBundle\Client\Rebrickable;
|
namespace AppBundle\Client\Rebrickable;
|
||||||
|
|
||||||
|
use AppBundle\Client\Rebrickable\Entity\Color;
|
||||||
|
use AppBundle\Client\Rebrickable\Entity\Part;
|
||||||
|
use AppBundle\Client\Rebrickable\Entity\Set;
|
||||||
|
use AppBundle\Client\Rebrickable\Converter\PartPropertyNameConverter;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\ClientException;
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use GuzzleHttp\Exception\ConnectException;
|
use GuzzleHttp\Exception\ConnectException;
|
||||||
use Symfony\Component\Asset\Exception\LogicException;
|
use Symfony\Component\Asset\Exception\LogicException;
|
||||||
|
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||||
|
use Symfony\Component\Serializer\Serializer;
|
||||||
|
|
||||||
class Rebrickable
|
class Rebrickable
|
||||||
{
|
{
|
||||||
const BASE_URI = 'https://rebrickable.com/api/';
|
const BASE_URI = 'https://rebrickable.com/api/';
|
||||||
const FORMAT = 'json';
|
const FORMAT = 'json';
|
||||||
|
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
private $apiKey;
|
private $apiKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RebrickableAPI constructor.
|
* RebrickableAPI constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct($apiKey)
|
public function __construct($apiKey)
|
||||||
{
|
{
|
||||||
$this->client = new Client(['base_uri' => self::BASE_URI]);
|
$this->client = new Client(['base_uri' => self::BASE_URI]);
|
||||||
$this->apiKey = $apiKey;
|
$this->apiKey = $apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $method
|
||||||
|
* @param $parameters
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
private function call($method, $parameters = [])
|
||||||
|
{
|
||||||
|
$parameters['query']['key'] = $this->apiKey;
|
||||||
|
$parameters['query']['format'] = self::FORMAT;
|
||||||
|
|
||||||
private function call($method, $parameters) {
|
try {
|
||||||
$parameters['query']['key'] = $this->apiKey;
|
$response = $this->client->request('GET', $method, $parameters);
|
||||||
$parameters['query']['format'] = self::FORMAT;
|
|
||||||
|
|
||||||
try
|
if ($response->getStatusCode() === 200) {
|
||||||
{
|
$content = $response->getBody()->getContents();
|
||||||
$response = $this->client->request('GET', $method, $parameters);
|
if ($content === 'INVALIDKEY') {
|
||||||
|
//TODO
|
||||||
|
throw new LogicException('Invalid API Key');
|
||||||
|
} elseif ($content === 'NOSET' || $content === 'NOPART') {
|
||||||
|
return null;
|
||||||
|
} 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($response->getStatusCode() === 200)
|
private function getSerializer()
|
||||||
{
|
{
|
||||||
$content = $response->getBody()->getContents();
|
$encoders = array(new JsonEncoder());
|
||||||
if($content === 'INVALIDKEY') {
|
$nameConverter = new PartPropertyNameConverter();
|
||||||
//TODO
|
$normalizers = array(new ObjectNormalizer(null,$nameConverter), new ArrayDenormalizer());
|
||||||
throw new LogicException("Invalid API Key");
|
$serializer = new Serializer($normalizers, $encoders);
|
||||||
} 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return $serializer;
|
||||||
* 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 a list of all parts (normal + spare) used in a set.
|
||||||
|
*
|
||||||
|
* @param string $setName unique rebrickable set name
|
||||||
|
*
|
||||||
|
* @return Part[]|null
|
||||||
|
*/
|
||||||
|
public function getSetParts($setName)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'query' => [
|
||||||
|
'set' => $setName,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
$data = $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);
|
$serializer = $this->getSerializer();
|
||||||
}
|
$partsSTD = json_decode($data, true)[0]['parts'];
|
||||||
|
|
||||||
/**
|
return $data ? $serializer->denormalize($partsSTD, Part::class.'[]', self::FORMAT) : null;
|
||||||
* 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.
|
* Get details about a specific part.
|
||||||
*
|
*
|
||||||
* @param $partID
|
* @param $partID
|
||||||
* @param $colorID
|
*
|
||||||
*
|
* @return Part|null
|
||||||
* @return
|
*/
|
||||||
*/
|
public function getPart($partID)
|
||||||
public function getPartSets($partID, $colorID)
|
{
|
||||||
{
|
$parameters = [
|
||||||
$parameters = [
|
'query' => [
|
||||||
'query' => [
|
'part_id' => $partID,
|
||||||
'part_id' => $partID,
|
'inc_ext' => 1,
|
||||||
'color_id' => $colorID
|
],
|
||||||
]
|
];
|
||||||
];
|
|
||||||
|
|
||||||
return $this->call('get_part_sets', $parameters);
|
$data = $this->call('get_part', $parameters);
|
||||||
}
|
$serializer = $this->getSerializer();
|
||||||
|
|
||||||
|
return $data ? $serializer->deserialize($data, Part::class, self::FORMAT) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get associative array of colors used by all parts where key == rb_color_id
|
||||||
|
*
|
||||||
|
* @return Color[]|null
|
||||||
|
*/
|
||||||
|
public function getColors()
|
||||||
|
{
|
||||||
|
$data = json_decode($this->call('get_colors'), true);
|
||||||
|
|
||||||
|
$serializer = $this->getSerializer();
|
||||||
|
|
||||||
|
$colors = [];
|
||||||
|
|
||||||
|
foreach ($data as $item) {
|
||||||
|
$color = $serializer->denormalize($item, Color::class, self::FORMAT);
|
||||||
|
$colors[$color->getRbColorId()] = $color;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data ? $colors : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get associative array of themes used by all parts where key == part_type_id
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getPartTypes()
|
||||||
|
{
|
||||||
|
$data = json_decode($this->call('get_part_types'), true)['part_types'];
|
||||||
|
|
||||||
|
$types = [];
|
||||||
|
foreach ($data as $item) {
|
||||||
|
$types[$item['part_type_id']] = $item['desc'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data ? $types : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of sets that a specific part/color appears in.
|
||||||
|
*
|
||||||
|
* @param $partID
|
||||||
|
* @param $colorID
|
||||||
|
*
|
||||||
|
* @return Set[]
|
||||||
|
*/
|
||||||
|
public function getPartSets($partID, $colorID)
|
||||||
|
{
|
||||||
|
$parameters = [
|
||||||
|
'query' => [
|
||||||
|
'part_id' => $partID,
|
||||||
|
'color_id' => $colorID,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$serializer = $this->getSerializer();
|
||||||
|
|
||||||
|
$data = json_decode($this->call('get_part_sets', $parameters), true)[0]['sets'];
|
||||||
|
|
||||||
|
return $data ? $serializer->denormalize($data, Set::class.'[]', self::FORMAT) : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user