-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ea2206
commit 3048db8
Showing
4 changed files
with
88 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
require_once(dirname(__FILE__) . '/BooksCollection.php'); | ||
require_once(dirname(__FILE__) . '/Book.php'); | ||
require_once(dirname(__FILE__) . '/../vendors/parse.php'); | ||
|
||
/* | ||
* This file is part of the Instabook package. | ||
* | ||
* Description of BooksService | ||
* | ||
* @author Daniel Gonzalez <daniel.gonzalez@freelancemadrid.es> | ||
* @file BooksService.php | ||
* @date 28 - Apr - 2012 | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
class BooksParseService | ||
{ | ||
|
||
private static $instances = array(); | ||
private $parse = null; | ||
|
||
protected function initialize() | ||
{ | ||
$this->parse = new parseRestClient(array( | ||
'appid' => 'u5H31glPx0jAhIpud6NhnEMzCQhEEIPgH5yk10fm', | ||
'restkey' => 'sBPGrYzBu2HKwZ6bCsg2HAGwBlj5rRDpjzXuuAwo' | ||
)); | ||
} | ||
|
||
final public static function getInstance() | ||
{ | ||
|
||
$class = get_called_class(); | ||
if (!isset(self::$instances[$class])) | ||
{ | ||
self::$instances[$class] = new $class(); | ||
} | ||
|
||
return self::$instances[$class]; | ||
} | ||
|
||
public function __construct() | ||
{ | ||
if (isset(self::$instances[get_called_class()])) | ||
{ | ||
throw new Exception(" A " . get_called_class() . " instance already exist"); | ||
} | ||
$this->initialize(); | ||
} | ||
|
||
public function search($query) | ||
{ | ||
|
||
} | ||
|
||
public function save(Book $book) | ||
{ | ||
$params = array( | ||
'className' => 'Books', | ||
'object' => array( | ||
'hash' => md5($book->link), | ||
'link' => $book->link, | ||
'title' => $book->title, | ||
//'author' => $book->author, | ||
'description' => $book->description, | ||
) | ||
); | ||
$response = $this->parse->create($params); | ||
|
||
die(var_dump($response)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<?php | ||
|
||
require_once(dirname(__FILE__) . '/../../models/BooksService.php'); | ||
require_once(dirname(__FILE__) . '/../../models/BooksParseService.php'); | ||
|
||
$query = "el señor de los anillos"; | ||
|
||
$service = BooksService::getInstance(); | ||
$books = $service->search($query); | ||
$books = BooksService::getInstance()->search($query); | ||
$books = $books->toArray(); | ||
|
||
|
||
$response = BooksParseService::getInstance()->save($books[0]); | ||
die(var_dump($books)); |