[OpenClassroomsBridge] add getURI() + code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-29 20:16:00 +02:00
parent 370530b5ef
commit 41dfc57103

View file

@ -10,6 +10,7 @@ class OpenClassroomsBridge extends BridgeAbstract{
'u'=>array( 'u'=>array(
'name'=>'Catégorie', 'name'=>'Catégorie',
'type'=>'list', 'type'=>'list',
'required'=>true,
'values'=>array( 'values'=>array(
'Arts & Culture'=>'arts', 'Arts & Culture'=>'arts',
'Code'=>'code', 'Code'=>'code',
@ -24,21 +25,18 @@ class OpenClassroomsBridge extends BridgeAbstract{
) )
)); ));
public function getURI(){
public function collectData(){ return $this->uri.'/courses?categories='.$this->getInput('u').'&'
if (empty($this->getInput('u'))) .'title=&sort=updatedAt+desc';
{
$this->returnServerError('Error: You must chose a category.');
} }
$html = ''; public function collectData(){
$link = 'https://openclassrooms.com/courses?categories='.$this->getInput('u').'&title=&sort=updatedAt+desc'; $html = $this->getSimpleHTMLDOM($this->getURI())
or $this->returnServerError('Could not request OpenClassrooms.');
$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request OpenClassrooms.');
foreach($html->find('.courseListItem') as $element) { foreach($html->find('.courseListItem') as $element) {
$item = array(); $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['title'] = $element->find('h3', 0)->plaintext;
$item['content'] = $element->find('slidingItem__descriptionContent', 0)->plaintext; $item['content'] = $element->find('slidingItem__descriptionContent', 0)->plaintext;
$this->items[] = $item; $this->items[] = $item;