From 7b1b5c0b46fd58a1b0ae73821d6fddcd203c8ebe Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 3 Oct 2021 01:59:59 +0200 Subject: [PATCH 1/6] [LegoIdeasBridge] Add bridge --- README.md | 1 + bridges/LegoIdeasBridge.php | 107 ++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 bridges/LegoIdeasBridge.php diff --git a/README.md b/README.md index 25857a1f1e8..9c69080bd9f 100644 --- a/README.md +++ b/README.md @@ -253,6 +253,7 @@ https://gist.github.com/LogMANOriginal/da00cd1e5f0ca31cef8e193509b17fd8 * [Roliga](https://github.com/Roliga) * [ronansalmon](https://github.com/ronansalmon) * [rremizov](https://github.com/rremizov) +* [sal0max](https://github.com/sal0max) * [sebsauvage](https://github.com/sebsauvage) * [shutosg](https://github.com/shutosg) * [simon816](https://github.com/simon816) diff --git a/bridges/LegoIdeasBridge.php b/bridges/LegoIdeasBridge.php new file mode 100644 index 00000000000..619a5d475e3 --- /dev/null +++ b/bridges/LegoIdeasBridge.php @@ -0,0 +1,107 @@ + array( + 'name' => 'Minimum Supporters', + 'title' => 'The number of people that need to have supported a project at minimum. +Once a project reaches 10,000 supporters, it gets reviewed by the lego experts.', + 'type' => 'number', + 'defaultValue' => 1000 + ), + 'idea_phase' => array( + 'name' => 'Idea Phase', + 'type' => 'list', + 'values' => array( + 'Gathering Support' => 'idea_gathering_support', + 'Achieved Support' => 'idea_achieved_support', + 'In Review' => 'idea_in_review', + 'Approved Ideas' => 'idea_approved_ideas', + 'Not Approved Ideas' => 'idea_not_approved_ideas', + 'On Shelves' => 'idea_on_shelves', + 'Expired Ideas' => 'idea_expired_ideas', + ), + 'required' => true, + 'defaultValue' => 'idea_gathering_support' + ) + ) + ); + + public function getURI() { + // link to the corresponding page on the website, not the api endpoint + return self::URI . 'search/global_search/ideas' + . "?support_value={$this->getInput('support_value_min')}" + . '&support_value=10000' + . "&idea_phase={$this->getInput('idea_phase')}" + . '&sort=most_recent'; + } + + public function getIcon(){ + $html = getSimpleHTMLDOM(self::URI); + return $html->find('link[rel=icon]', 3)->attr['href']; + } + + public function collectData() { + $header = array( + 'Content-Type: application/json', + 'Accept: application/json' + ); + $opts = array( + CURLOPT_POST => 1, + CURLOPT_POSTFIELDS => $this->getHttpPostData() + ); + $responseData = getContents($this->getHttpPostURI(), $header, $opts) or + returnServerError('Unable to query Lego Ideas API.'); + + foreach (json_decode($responseData)->results as $project) { + preg_match('/datetime=\"(\S+)\"/', $project->entity->published_at, $date_matches); + $datetime = $date_matches[1]; + $link = self::URI . $project->entity->view_url; + $title = $project->entity->title; + $desc = $project->entity->content; + $imageUrl = $project->entity->image_url; + $creator = $project->entity->creator->alias; + $uuid = $project->entity->uuid; + + $item = array( + 'uri' => $link, + 'title' => $title, + 'timestamp' => strtotime($datetime), + 'author' => $creator, + 'content' => <<{$title}

+

{$desc}

+EOD + ); + $this->items[] = $item; + } + } + + /** + * Returns the API endpoint + */ + private function getHttpPostURI() { + return self::URI . '/search/global_search/ideas'; + } + + /** + * Returns the API query + */ + private function getHttpPostData() { + $phase = $this->getInput('idea_phase'); + $minSupporters = $this->getInput('support_value_min'); + + return << Date: Sun, 3 Oct 2021 02:09:16 +0200 Subject: [PATCH 2/6] Remove unsupported 'required' attribute --- bridges/LegoIdeasBridge.php | 1 - 1 file changed, 1 deletion(-) diff --git a/bridges/LegoIdeasBridge.php b/bridges/LegoIdeasBridge.php index 619a5d475e3..d355aa439fd 100644 --- a/bridges/LegoIdeasBridge.php +++ b/bridges/LegoIdeasBridge.php @@ -25,7 +25,6 @@ class LegoIdeasBridge extends BridgeAbstract { 'On Shelves' => 'idea_on_shelves', 'Expired Ideas' => 'idea_expired_ideas', ), - 'required' => true, 'defaultValue' => 'idea_gathering_support' ) ) From a2ed0a9e1f3cacc2cfccf059b514efe4ff0a8cd5 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 3 Oct 2021 02:30:30 +0200 Subject: [PATCH 3/6] fix queries --- bridges/LegoIdeasBridge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridges/LegoIdeasBridge.php b/bridges/LegoIdeasBridge.php index d355aa439fd..8cedaad4127 100644 --- a/bridges/LegoIdeasBridge.php +++ b/bridges/LegoIdeasBridge.php @@ -20,8 +20,8 @@ class LegoIdeasBridge extends BridgeAbstract { 'Gathering Support' => 'idea_gathering_support', 'Achieved Support' => 'idea_achieved_support', 'In Review' => 'idea_in_review', - 'Approved Ideas' => 'idea_approved_ideas', - 'Not Approved Ideas' => 'idea_not_approved_ideas', + 'Approved Ideas' => 'idea_idea_approved', + 'Not Approved Ideas' => 'idea_idea_not_approved', 'On Shelves' => 'idea_on_shelves', 'Expired Ideas' => 'idea_expired_ideas', ), From d5d0a8011c92d4ad1796a5ca1b7dfa04b6d140f6 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 4 Oct 2021 00:25:10 +0200 Subject: [PATCH 4/6] revert modified readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9c69080bd9f..25857a1f1e8 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,6 @@ https://gist.github.com/LogMANOriginal/da00cd1e5f0ca31cef8e193509b17fd8 * [Roliga](https://github.com/Roliga) * [ronansalmon](https://github.com/ronansalmon) * [rremizov](https://github.com/rremizov) -* [sal0max](https://github.com/sal0max) * [sebsauvage](https://github.com/sebsauvage) * [shutosg](https://github.com/shutosg) * [simon816](https://github.com/simon816) From 554821c4bf1df678e99b9fe3101180fb99c743ab Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 4 Oct 2021 00:36:27 +0200 Subject: [PATCH 5/6] fix lint --- bridges/LegoIdeasBridge.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bridges/LegoIdeasBridge.php b/bridges/LegoIdeasBridge.php index 8cedaad4127..7d8272fcf05 100644 --- a/bridges/LegoIdeasBridge.php +++ b/bridges/LegoIdeasBridge.php @@ -91,16 +91,17 @@ private function getHttpPostURI() { * Returns the API query */ private function getHttpPostData() { + $phase = $this->getInput('idea_phase'); $minSupporters = $this->getInput('support_value_min'); return << Date: Thu, 14 Oct 2021 21:06:56 +0200 Subject: [PATCH 6/6] remove icon and see if this solves the test errors --- bridges/LegoIdeasBridge.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bridges/LegoIdeasBridge.php b/bridges/LegoIdeasBridge.php index 7d8272fcf05..442aba646a6 100644 --- a/bridges/LegoIdeasBridge.php +++ b/bridges/LegoIdeasBridge.php @@ -39,11 +39,6 @@ public function getURI() { . '&sort=most_recent'; } - public function getIcon(){ - $html = getSimpleHTMLDOM(self::URI); - return $html->find('link[rel=icon]', 3)->attr['href']; - } - public function collectData() { $header = array( 'Content-Type: application/json',