Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refs singleton

  • Loading branch information...
commit 3048db8e1270fc005bc92b4a15f89224a178c459 1 parent 7ea2206
@desarrolla2 desarrolla2 authored
View
15 yii-app/protected/models/Book.php
@@ -16,18 +16,15 @@
class Book
{
- public $google_link = null;
+ public $link = null;
public $title = null;
- public $description = null;
public $author = null;
+ public $description = null;
public $category = null;
-
-
- public function save(){
- $parse = new parseRestClient(array(
- 'appid' => 'YOUR APPLICATION ID',
- 'restkey' => 'YOUR REST KEY ID'
-));
+
+ public function save()
+ {
+ // ..
}
}
View
77 yii-app/protected/models/BooksParseService.php
@@ -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));
+ }
+
+}
View
18 yii-app/protected/models/BooksService.php
@@ -29,11 +29,6 @@ protected function initialize()
{
$this->goole_rest_api_search = 'https://www.googleapis.com/books/v1/volumes';
$this->collection = new BooksCollection();
-
- $this->parse = new parseRestClient(array(
- 'appid' => 'u5H31glPx0jAhIpud6NhnEMzCQhEEIPgH5yk10fm',
- 'restkey' => 'sBPGrYzBu2HKwZ6bCsg2HAGwBlj5rRDpjzXuuAwo'
- ));
}
final public static function getInstance()
@@ -93,17 +88,4 @@ public function search($query)
return $this->collection;
}
- public function save(Book $book)
- {
- $params = array(
- 'className' => 'Books',
- 'object' => array(
- 'title' => $book->title,
- 'author' => $book->author,
- ''
- )
- );
- $request = $parse->create($params);
- }
-
}
View
7 yii-app/protected/tests/books/service.php
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.