1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-18 05:10:07 -07:00

Update Brickset client + Fix coding style

This commit is contained in:
David Hübner 2016-11-20 23:57:38 +01:00
parent a2e270de14
commit f2f4e086e6
8 changed files with 849 additions and 536 deletions

View File

@ -6,12 +6,15 @@ use AppBundle\Client\Brickset\Entity\AdditionalImage;
use AppBundle\Client\Brickset\Entity\Instructions;
use AppBundle\Client\Brickset\Entity\Review;
use AppBundle\Client\Brickset\Entity\Set;
use AppBundle\Client\Brickset\Entity\Subtheme;
use AppBundle\Client\Brickset\Entity\Theme;
use AppBundle\Client\Brickset\Entity\Year;
use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Debug\Exception\ContextErrorException;
class Brickset extends \SoapClient
{
const WSDL = 'http://brickset.com/api/v2.asmx?WSDL';
const WSDL = 'http://brickset.com/api/v2.asmx?WSDL';
private $apiKey = '';
private $userHash = '';
@ -24,6 +27,9 @@ class Brickset extends \SoapClient
'additionalImages' => AdditionalImage::class,
'instructions' => Instructions::class,
'reviews' => Review::class,
'themes' => Theme::class,
'subthemes' => Subtheme::class,
'years' => Year::class,
);
/**
@ -54,49 +60,46 @@ class Brickset extends \SoapClient
$this->apiKey = $apiKey;
}
/**
* @param $query
* @param $theme
* @param $subtheme
* @param $setNumber
* @param $year
* @param $owned
* @param $wanted
* @param $orderBy
* @param $pageSize
* @param $pageNumber
* @param $userName
*
* @return Set[]
*/
public function getSets($query, $theme, $subtheme, $setNumber, $year, $owned, $wanted, $orderBy, $pageSize, $pageNumber, $userName)
private function call($method, $parameters)
{
$parameters = [
'apiKey' => $this->apiKey,
'userHash' => $this->userHash,
'query' => $query,
'theme' => $theme,
'subtheme' => $subtheme,
'setNumber' => $setNumber,
'year' => $year,
'owned' => $owned,
'wanted' => $wanted,
'orderBy' => $orderBy,
'pageSize' => $pageSize,
'pageNumber' => $pageNumber,
'userName' => $userName,
];
$parameters['apiKey'] = $this->apiKey;
try {
return $this->__soapCall('getSets', [$parameters])->getSetsResult->sets;
} catch (ContextErrorException $e) {
return [];
return $this->__soapCall($method, [$parameters]);
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
}
/**
* Retrieve a list of sets.
*
* @param array $parameters
*
* @return Set[]
*/
public function getSets($parameters)
{
$parameters['userHash'] = $this->userHash;
// Add blank required parameters to api call in order to recieve response
$required_keys = ['query', 'theme', 'subtheme', 'setNumber', 'year', 'owned', 'wanted', 'orderBy', 'pageSize', 'pageNumber', 'userName'];
foreach ($required_keys as $key) {
if (!array_key_exists($key, $parameters)) {
$parameters[$key] = '';
}
}
try {
$response = $this->call('getSets', $parameters)->getSetsResult->sets;
return is_array($response) ? $response : [$response];
} catch (ContextErrorException $e) {
return [];
}
}
/**
* @param $SetID
*
@ -104,139 +107,180 @@ class Brickset extends \SoapClient
*/
public function getSet($SetID)
{
$parameters = [
'apiKey' => $this->apiKey,
'userHash' => $this->userHash,
'SetID' => $SetID,
];
$parameters = ['userHash' => $this->userHash, 'SetID' => $SetID];
try {
return $this->__soapCall('getSet', [$parameters])->getSetResult->sets[0];
return $this->call('getSet', $parameters)->getSetResult->sets;
} catch (ContextErrorException $e) {
return null;
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
}
/**
* Get a list of sets that have changed in the last {minutesAgo} minutes.
*
* @param int $minutesAgo
*
* @return Set[]
*/
public function getRecentlyUpdatedSets($minutesAgo)
{
$parameters = [
'apiKey' => $this->apiKey,
'minutesAgo' => $minutesAgo,
];
$parameters = ['minutesAgo' => $minutesAgo];
try {
return $this->__soapCall('getRecentlyUpdatedSets', [$parameters])->getRecentlyUpdatedSetsResult->sets;
$response = $this->call('getRecentlyUpdatedSets', $parameters)->getRecentlyUpdatedSetsResult->sets;
return is_array($response) ? $response : [$response];
} catch (ContextErrorException $e) {
return [];
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
}
/**
* @param $setID
* Get a list of URLs of additional set images for the specified set.
*
* @param int $setID Brickset unique id of set
*
* @return AdditionalImage[]
*/
public function getAdditionalImages($setID)
{
$parameters = [
'apiKey' => $this->apiKey,
'setID' => $setID,
];
$parameters = ['setID' => $setID];
try {
return $this->__soapCall('getAdditionalImages', [$parameters])->getAdditionalImagesResult->additionalImages;
$response = $this->call('getAdditionalImages', $parameters)->getAdditionalImagesResult->additionalImages;
return is_array($response) ? $response : [$response];
} catch (ContextErrorException $e) {
return [];
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
}
public function getReviews($setID)
{
$parameters = [
'apiKey' => $this->apiKey,
'setID' => $setID,
];
try {
return $this->__soapCall('getReviews', [$parameters])->getReviewsResult->reviews;
} catch (ContextErrorException $e) {
return [];
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
}
public function getInstructions($setID)
{
$parameters = [
'apiKey' => $this->apiKey,
'setID' => $setID,
];
try {
return $this->__soapCall('getInstructions', [$parameters])->getInstructionsResult->instructions;
} catch (ContextErrorException $e) {
return [];
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
}
public function login($username, $password)
{
$parameters = [
'apiKey' => $this->apiKey,
'username' => $username,
'password' => $password,
];
try {
$response = $this->__soapCall('login', [$parameters])->loginResult;
if ($response == 'INVALIDKEY') {
return false;
} elseif (strpos($response, 'ERROR:') === 0) {
return false;
} else {
$this->userHash = $response;
return true;
}
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
}
/**
* @return mixed
* Get the reviews for the specified set.
*
* @param int $setID Brickset unique id of set
*
* @return Review[]
*/
public function getReviews($setID)
{
$parameters = ['setID' => $setID];
try {
$response = $this->call('getReviews', $parameters)->getReviewsResult->reviews;
return is_array($response) ? $response : [$response];
} catch (ContextErrorException $e) {
return [];
}
}
/**
* Get a list of instructions for the specified set.
*
* @param int $setID Brickset unique id of set
*
* @return Instructions[]
*/
public function getInstructions($setID)
{
$parameters = ['setID' => $setID];
try {
$response = $this->call('getInstructions', $parameters)->getInstructionsResult->instructions;
return is_array($response) ? $response : [$response];
} catch (ContextErrorException $e) {
return null;
}
}
/**
* Get a list of themes, with the total number of sets in each.
*
* @return Theme[]
*/
public function getThemes()
{
try {
return $this->call('getThemes', [])->getThemesResult->themes;
} catch (ContextErrorException $e) {
return [];
}
}
/**
* Get a list of subthemes for a given theme, with the total number of sets in each.
*
* @param string $theme Name of theme
*
* @return Subtheme[]
*/
public function getSubthemes($theme)
{
$parameters = ['theme' => $theme];
try {
$response = $this->call('getSubthemes', $parameters)->getSubthemesResult->subthemes;
return is_array($response) ? $response : [$response];
} catch (ContextErrorException $e) {
return [];
}
}
/**
* Get a list of years for a given theme, with the total number of sets in each.
*
* @param string $theme Name of theme
*
* @return Year[]
*/
public function getYears($theme)
{
$parameters = ['theme' => $theme];
try {
$response = $this->call('getYears', $parameters)->getYearsResult->years;
return is_array($response) ? $response : [$response];
} catch (ContextErrorException $e) {
return [];
}
}
/**
* Log in as a user and retrieve a token that can be used in subsequent API calls.
*
* @param string $username
* @param string $password
*
* @return bool True if successful
*/
public function login($username, $password)
{
$parameters = ['username' => $username, 'password' => $password];
$response = $this->call('login', $parameters)->loginResult;
if ($response == 'INVALIDKEY') {
return false;
} elseif (strpos($response, 'ERROR:') === 0) {
return false;
} else {
$this->userHash = $response;
return true;
}
}
/**
* Check if an API key is valid.
*
* @return bool
*/
public function checkKey()
{
$parameters = [
'apiKey' => $this->apiKey,
];
try {
return ($this->__soapCall('checkKey', [$parameters])->checkKeyResult) == 'OK' ? true : false;
} catch (\SoapFault $e) {
//TODO
throw new LogicException($e->getCode().' - '.$e->getMessage());
}
return ($this->call('checkKey', [])->checkKeyResult) == 'OK' ? true : false;
}
}

View File

@ -4,26 +4,23 @@ namespace AppBundle\Client\Brickset\Entity;
class AdditionalImage
{
/**
* @var string $thumbnailURL
* @var string
*/
protected $thumbnailURL = null;
/**
* @var string $largeThumbnailURL
* @var string
*/
protected $largeThumbnailURL = null;
/**
* @var string $imageURL
* @var string
*/
protected $imageURL = null;
public function __construct()
{
}
/**
@ -31,17 +28,19 @@ class AdditionalImage
*/
public function getThumbnailURL()
{
return $this->thumbnailURL;
return $this->thumbnailURL;
}
/**
* @param string $thumbnailURL
*
* @return AdditionalImage
*/
public function setThumbnailURL($thumbnailURL)
{
$this->thumbnailURL = $thumbnailURL;
return $this;
$this->thumbnailURL = $thumbnailURL;
return $this;
}
/**
@ -49,17 +48,19 @@ class AdditionalImage
*/
public function getLargeThumbnailURL()
{
return $this->largeThumbnailURL;
return $this->largeThumbnailURL;
}
/**
* @param string $largeThumbnailURL
*
* @return AdditionalImage
*/
public function setLargeThumbnailURL($largeThumbnailURL)
{
$this->largeThumbnailURL = $largeThumbnailURL;
return $this;
$this->largeThumbnailURL = $largeThumbnailURL;
return $this;
}
/**
@ -67,17 +68,18 @@ class AdditionalImage
*/
public function getImageURL()
{
return $this->imageURL;
return $this->imageURL;
}
/**
* @param string $imageURL
*
* @return AdditionalImage
*/
public function setImageURL($imageURL)
{
$this->imageURL = $imageURL;
return $this;
}
$this->imageURL = $imageURL;
return $this;
}
}

View File

@ -5,19 +5,17 @@ namespace AppBundle\Client\Brickset\Entity;
class Instructions
{
/**
* @var string $URL
* @var string
*/
protected $URL = null;
/**
* @var string $description
* @var string
*/
protected $description = null;
public function __construct()
{
}
/**
@ -25,17 +23,19 @@ class Instructions
*/
public function getURL()
{
return $this->URL;
return $this->URL;
}
/**
* @param string $URL
*
* @return Instructions
*/
public function setURL($URL)
{
$this->URL = $URL;
return $this;
$this->URL = $URL;
return $this;
}
/**
@ -43,17 +43,18 @@ class Instructions
*/
public function getDescription()
{
return $this->description;
return $this->description;
}
/**
* @param string $description
*
* @return Instructions
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
$this->description = $description;
return $this;
}
}

View File

@ -4,75 +4,74 @@ namespace AppBundle\Client\Brickset\Entity;
class Review
{
/**
* @var string $author
* @var string
*/
protected $author = null;
/**
* @var \DateTime $datePosted
* @var \DateTime
*/
protected $datePosted = null;
/**
* @var int $overallRating
* @var int
*/
protected $overallRating = null;
/**
* @var int $parts
* @var int
*/
protected $parts = null;
/**
* @var int $buildingExperience
* @var int
*/
protected $buildingExperience = null;
/**
* @var int $playability
* @var int
*/
protected $playability = null;
/**
* @var int $valueForMoney
* @var int
*/
protected $valueForMoney = null;
/**
* @var string $title
* @var string
*/
protected $title = null;
/**
* @var string $review
* @var string
*/
protected $review = null;
/**
* @var boolean $HTML
* @var bool
*/
protected $HTML = null;
/**
* @param \DateTime $datePosted
* @param int $overallRating
* @param int $parts
* @param int $buildingExperience
* @param int $playability
* @param int $valueForMoney
* @param boolean $HTML
* @param int $overallRating
* @param int $parts
* @param int $buildingExperience
* @param int $playability
* @param int $valueForMoney
* @param bool $HTML
*/
public function __construct(\DateTime $datePosted, $overallRating, $parts, $buildingExperience, $playability, $valueForMoney, $HTML)
{
$this->datePosted = $datePosted->format(\DateTime::ATOM);
$this->overallRating = $overallRating;
$this->parts = $parts;
$this->buildingExperience = $buildingExperience;
$this->playability = $playability;
$this->valueForMoney = $valueForMoney;
$this->HTML = $HTML;
$this->datePosted = $datePosted->format(\DateTime::ATOM);
$this->overallRating = $overallRating;
$this->parts = $parts;
$this->buildingExperience = $buildingExperience;
$this->playability = $playability;
$this->valueForMoney = $valueForMoney;
$this->HTML = $HTML;
}
/**
@ -80,17 +79,19 @@ class Review
*/
public function getAuthor()
{
return $this->author;
return $this->author;
}
/**
* @param string $author
*
* @return Review
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
$this->author = $author;
return $this;
}
/**
@ -98,25 +99,27 @@ class Review
*/
public function getDatePosted()
{
if ($this->datePosted == null) {
return null;
} else {
try {
return new \DateTime($this->datePosted);
} catch (\Exception $e) {
return null;
if ($this->datePosted == null) {
return null;
} else {
try {
return new \DateTime($this->datePosted);
} catch (\Exception $e) {
return null;
}
}
}
}
/**
* @param \DateTime $datePosted
*
* @return Review
*/
public function setDatePosted(\DateTime $datePosted)
{
$this->datePosted = $datePosted->format(\DateTime::ATOM);
return $this;
$this->datePosted = $datePosted->format(\DateTime::ATOM);
return $this;
}
/**
@ -124,17 +127,19 @@ class Review
*/
public function getOverallRating()
{
return $this->overallRating;
return $this->overallRating;
}
/**
* @param int $overallRating
*
* @return Review
*/
public function setOverallRating($overallRating)
{
$this->overallRating = $overallRating;
return $this;
$this->overallRating = $overallRating;
return $this;
}
/**
@ -142,17 +147,19 @@ class Review
*/
public function getParts()
{
return $this->parts;
return $this->parts;
}
/**
* @param int $parts
*
* @return Review
*/
public function setParts($parts)
{
$this->parts = $parts;
return $this;
$this->parts = $parts;
return $this;
}
/**
@ -160,17 +167,19 @@ class Review
*/
public function getBuildingExperience()
{
return $this->buildingExperience;
return $this->buildingExperience;
}
/**
* @param int $buildingExperience
*
* @return Review
*/
public function setBuildingExperience($buildingExperience)
{
$this->buildingExperience = $buildingExperience;
return $this;
$this->buildingExperience = $buildingExperience;
return $this;
}
/**
@ -178,17 +187,19 @@ class Review
*/
public function getPlayability()
{
return $this->playability;
return $this->playability;
}
/**
* @param int $playability
*
* @return Review
*/
public function setPlayability($playability)
{
$this->playability = $playability;
return $this;
$this->playability = $playability;
return $this;
}
/**
@ -196,17 +207,19 @@ class Review
*/
public function getValueForMoney()
{
return $this->valueForMoney;
return $this->valueForMoney;
}
/**
* @param int $valueForMoney
*
* @return Review
*/
public function setValueForMoney($valueForMoney)
{
$this->valueForMoney = $valueForMoney;
return $this;
$this->valueForMoney = $valueForMoney;
return $this;
}
/**
@ -214,17 +227,19 @@ class Review
*/
public function getTitle()
{
return $this->title;
return $this->title;
}
/**
* @param string $title
*
* @return Review
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
$this->title = $title;
return $this;
}
/**
@ -232,35 +247,38 @@ class Review
*/
public function getReview()
{
return $this->review;
return $this->review;
}
/**
* @param string $review
*
* @return Review
*/
public function setReview($review)
{
$this->review = $review;
return $this;
$this->review = $review;
return $this;
}
/**
* @return boolean
* @return bool
*/
public function getHTML()
{
return $this->HTML;
return $this->HTML;
}
/**
* @param boolean $HTML
* @param bool $HTML
*
* @return Review
*/
public function setHTML($HTML)
{
$this->HTML = $HTML;
return $this;
}
$this->HTML = $HTML;
return $this;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,119 @@
<?php
/**
* Created by PhpStorm.
* User: hubnedav
* Date: 11/11/16
* Time: 7:13 PM.
*/
namespace AppBundle\Client\Brickset\Entity;
class Subtheme
{
/**
* @var string
*/
protected $theme;
/**
* @var string
*/
protected $subtheme;
/**
* @var
*/
protected $setCount;
/**
* @var int
*/
protected $yearFrom;
/**
* @var int
*/
protected $yearTo;
public function __construct()
{
}
/**
* @return mixed
*/
public function getTheme()
{
return $this->theme;
}
/**
* @param mixed $theme
*/
public function setTheme($theme)
{
$this->theme = $theme;
}
/**
* @return mixed
*/
public function getSetCount()
{
return $this->setCount;
}
/**
* @param mixed $setCount
*/
public function setSetCount($setCount)
{
$this->setCount = $setCount;
}
/**
* @return string
*/
public function getSubtheme()
{
return $this->subtheme;
}
/**
* @param string $subtheme
*/
public function setSubtheme($subtheme)
{
$this->subtheme = $subtheme;
}
/**
* @return mixed
*/
public function getYearFrom()
{
return $this->yearFrom;
}
/**
* @param mixed $yearFrom
*/
public function setYearFrom($yearFrom)
{
$this->yearFrom = $yearFrom;
}
/**
* @return mixed
*/
public function getYearTo()
{
return $this->yearTo;
}
/**
* @param mixed $yearTo
*/
public function setYearTo($yearTo)
{
$this->yearTo = $yearTo;
}
}

View File

@ -0,0 +1,117 @@
<?php
/**
* Created by PhpStorm.
* User: hubnedav
* Date: 11/11/16
* Time: 7:13 PM.
*/
namespace AppBundle\Client\Brickset\Entity;
class Theme
{
/**
* @var string
*/
protected $theme;
/**
* @var int
*/
protected $setCount;
/**
* @var int
*/
protected $subthemeCount;
/**
* @var int
*/
protected $yearFrom;
/**
* @var int
*/
protected $yearTo;
public function __construct()
{
}
/**
* @return mixed
*/
public function getTheme()
{
return $this->theme;
}
/**
* @param mixed $theme
*/
public function setTheme($theme)
{
$this->theme = $theme;
}
/**
* @return mixed
*/
public function getSetCount()
{
return $this->setCount;
}
/**
* @param mixed $setCount
*/
public function setSetCount($setCount)
{
$this->setCount = $setCount;
}
/**
* @return mixed
*/
public function getSubthemeCount()
{
return $this->subthemeCount;
}
/**
* @param mixed $subthemeCount
*/
public function setSubthemeCount($subthemeCount)
{
$this->subthemeCount = $subthemeCount;
}
/**
* @return mixed
*/
public function getYearFrom()
{
return $this->yearFrom;
}
/**
* @param mixed $yearFrom
*/
public function setYearFrom($yearFrom)
{
$this->yearFrom = $yearFrom;
}
/**
* @return mixed
*/
public function getYearTo()
{
return $this->yearTo;
}
/**
* @param mixed $yearTo
*/
public function setYearTo($yearTo)
{
$this->yearTo = $yearTo;
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* Created by PhpStorm.
* User: hubnedav
* Date: 11/20/16
* Time: 11:17 PM.
*/
namespace AppBundle\Client\Brickset\Entity;
class Year
{
protected $theme;
protected $year;
protected $setCount;
/**
* Year constructor.
*
* @param $theme
* @param $year
* @param $setCount
*/
public function __construct($theme, $year, $setCount)
{
$this->theme = $theme;
$this->year = $year;
$this->setCount = $setCount;
}
/**
* @return mixed
*/
public function getTheme()
{
return $this->theme;
}
/**
* @param mixed $theme
*/
public function setTheme($theme)
{
$this->theme = $theme;
}
/**
* @return mixed
*/
public function getYear()
{
return $this->year;
}
/**
* @param mixed $year
*/
public function setYear($year)
{
$this->year = $year;
}
/**
* @return mixed
*/
public function getSetCount()
{
return $this->setCount;
}
/**
* @param mixed $setCount
*/
public function setSetCount($setCount)
{
$this->setCount = $setCount;
}
}