From 290c8eb38bffb88ede48bb092e3d877eab351622 Mon Sep 17 00:00:00 2001 From: AxorPL <1163219+AxorPL@users.noreply.github.com> Date: Fri, 4 Sep 2020 09:54:41 +0200 Subject: [PATCH 1/2] [WorldCosplayBridge] Add new bridge --- bridges/WorldCosplayBridge.php | 138 +++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 bridges/WorldCosplayBridge.php diff --git a/bridges/WorldCosplayBridge.php b/bridges/WorldCosplayBridge.php new file mode 100644 index 00000000000..ebb2e619825 --- /dev/null +++ b/bridges/WorldCosplayBridge.php @@ -0,0 +1,138 @@ +%s'; + + const ERR_CONTEXT = 'No context provided'; + const ERR_QUERY = 'Unable to query: %s'; + + const LIMIT_MIN = 1; + const LIMIT_MAX = 24; + + const PARAMETERS = array( + 'Character' => array( + 'cid' => array( + 'name' => 'Character ID', + 'type' => 'number', + 'required' => true, + 'title' => 'WorldCosplay character ID' + ) + ), + 'Cosplayer' => array( + 'uid' => array( + 'name' => 'Cosplayer ID', + 'type' => 'number', + 'required' => true, + 'title' => 'Cosplayer\'s WorldCosplay profile ID' + ) + ), + 'Series' => array( + 'sid' => array( + 'name' => 'Series ID', + 'type' => 'number', + 'required' => true, + 'title' => 'WorldCosplay series ID' + ) + ), + 'Tag' => array( + 'tid' => array( + 'name' => 'Tag ID', + 'type' => 'number', + 'required' => true, + 'title' => 'WorldCosplay tag ID' + ) + ), + 'global' => array( + 'limit' => array( + 'name' => 'Limit', + 'type' => 'number', + 'required' => false, + 'title' => 'Maximum number of photos to return', + 'defaultValue' => 5 + ) + ) + ); + + public function collectData() { + $limit = $this->getInput('limit'); + $limit = min(self::LIMIT_MAX, max(self::LIMIT_MIN, $limit)); + switch($this->queriedContext) { + case 'Character': + $id = $this->getInput('cid'); + $url = self::API_CHARACTER; + break; + case 'Cosplayer': + $id = $this->getInput('uid'); + $url = self::API_COSPLAYER; + break; + case 'Series': + $id = $this->getInput('sid'); + $url = self::API_SERIES; + break; + case 'Tag': + $id = $this->getInput('tid'); + $url = self::API_TAG; + break; + default: + returnClientError(self::ERR_CONTEXT); + } + $url = self::URI . sprintf($url, $id, $limit); + + $json = json_decode(getContents($url)) + or returnServerError(sprintf(self::ERR_QUERY, $url)); + if($json->has_error) + { + returnServerError($json->message); + } + $list = $json->list; + + foreach($list as $img) + { + $item = array(); + $item['uri'] = self::URI . substr($img->photo->url, 1); + $item['title'] = $img->photo->subject; + $item['timestamp'] = $img->photo->created_at; + $item['author'] = $img->member->global_name; + $item['enclosures'] = array($img->photo->large_url); + $item['uid'] = $img->photo->id; + $item['content'] = sprintf( + self::CONTENT_HTML, + $item['uri'], + $item['enclosures'][0], + $item['title'], + $item['title'] + ); + $this->items[] = $item; + } + } + + public function getName() { + switch($this->queriedContext) { + case 'Character': + $id = $this->getInput('cid'); + break; + case 'Cosplayer': + $id = $this->getInput('uid'); + break; + case 'Series': + $id = $this->getInput('sid'); + break; + case 'Tag': + $id = $this->getInput('tid'); + break; + default: + return parent::getName(); + } + return sprintf('%s %u - ', $this->queriedContext, $id) . self::NAME; + } +} From 3463ab077f42f5d8b27ef2d95de157aa45ad6405 Mon Sep 17 00:00:00 2001 From: AxorPL <1163219+AxorPL@users.noreply.github.com> Date: Wed, 9 Sep 2020 13:44:11 +0200 Subject: [PATCH 2/2] [WorldCosplayBridge] Provided example values --- bridges/WorldCosplayBridge.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bridges/WorldCosplayBridge.php b/bridges/WorldCosplayBridge.php index ebb2e619825..4fc31e67428 100644 --- a/bridges/WorldCosplayBridge.php +++ b/bridges/WorldCosplayBridge.php @@ -25,7 +25,8 @@ class WorldCosplayBridge extends BridgeAbstract { 'name' => 'Character ID', 'type' => 'number', 'required' => true, - 'title' => 'WorldCosplay character ID' + 'title' => 'WorldCosplay character ID', + 'exampleValue' => 18204 ) ), 'Cosplayer' => array( @@ -33,7 +34,8 @@ class WorldCosplayBridge extends BridgeAbstract { 'name' => 'Cosplayer ID', 'type' => 'number', 'required' => true, - 'title' => 'Cosplayer\'s WorldCosplay profile ID' + 'title' => 'Cosplayer\'s WorldCosplay profile ID', + 'exampleValue' => 406782 ) ), 'Series' => array( @@ -41,7 +43,8 @@ class WorldCosplayBridge extends BridgeAbstract { 'name' => 'Series ID', 'type' => 'number', 'required' => true, - 'title' => 'WorldCosplay series ID' + 'title' => 'WorldCosplay series ID', + 'exampleValue' => 3139 ) ), 'Tag' => array( @@ -49,7 +52,8 @@ class WorldCosplayBridge extends BridgeAbstract { 'name' => 'Tag ID', 'type' => 'number', 'required' => true, - 'title' => 'WorldCosplay tag ID' + 'title' => 'WorldCosplay tag ID', + 'exampleValue' => 33643 ) ), 'global' => array( @@ -58,6 +62,7 @@ class WorldCosplayBridge extends BridgeAbstract { 'type' => 'number', 'required' => false, 'title' => 'Maximum number of photos to return', + 'exampleValue' => 5, 'defaultValue' => 5 ) )