From 41dfc571037f6966548f534a609e8b7aae59b417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 20:16:00 +0200 Subject: [PATCH] [OpenClassroomsBridge] add getURI() + code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/OpenClassroomsBridge.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/bridges/OpenClassroomsBridge.php b/bridges/OpenClassroomsBridge.php index 9e560f9..39fc87b 100644 --- a/bridges/OpenClassroomsBridge.php +++ b/bridges/OpenClassroomsBridge.php @@ -10,6 +10,7 @@ class OpenClassroomsBridge extends BridgeAbstract{ 'u'=>array( 'name'=>'Catégorie', 'type'=>'list', + 'required'=>true, 'values'=>array( 'Arts & Culture'=>'arts', 'Code'=>'code', @@ -24,21 +25,18 @@ class OpenClassroomsBridge extends BridgeAbstract{ ) )); + public function getURI(){ + return $this->uri.'/courses?categories='.$this->getInput('u').'&' + .'title=&sort=updatedAt+desc'; + } public function collectData(){ - if (empty($this->getInput('u'))) - { - $this->returnServerError('Error: You must chose a category.'); - } - - $html = ''; - $link = 'https://openclassrooms.com/courses?categories='.$this->getInput('u').'&title=&sort=updatedAt+desc'; - - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request OpenClassrooms.'); + $html = $this->getSimpleHTMLDOM($this->getURI()) + or $this->returnServerError('Could not request OpenClassrooms.'); foreach($html->find('.courseListItem') as $element) { $item = array(); - $item['uri'] = 'https://openclassrooms.com'.$element->find('a', 0)->href; + $item['uri'] = $this->uri.$element->find('a', 0)->href; $item['title'] = $element->find('h3', 0)->plaintext; $item['content'] = $element->find('slidingItem__descriptionContent', 0)->plaintext; $this->items[] = $item;