1 | <?php |
||
8 | class LibraryBuilder |
||
9 | { |
||
10 | protected $data; |
||
11 | protected $client; |
||
12 | protected $chunk; |
||
13 | protected $query; |
||
14 | protected $limit; |
||
15 | |||
16 | /** |
||
17 | * Accepts a GoogleBooks dependency and sets it as a client property |
||
18 | * |
||
19 | * @param GoogleBooks $GoogleBooks |
||
20 | */ |
||
21 | public function __construct(GoogleBooks $GoogleBooks) |
||
25 | |||
26 | /** |
||
27 | * Limits the results. May be an integer between 1 and 40 |
||
28 | * |
||
29 | * @param int $limit |
||
30 | * @return self |
||
31 | */ |
||
32 | public function limit($limit) |
||
37 | |||
38 | /** |
||
39 | * Sets the query property |
||
40 | * |
||
41 | * @param string $query |
||
42 | * @return self |
||
43 | */ |
||
44 | public function search($query) |
||
49 | |||
50 | /** |
||
51 | * Fetches results from the Google API |
||
52 | * |
||
53 | * @param string $id |
||
54 | * @return array |
||
55 | */ |
||
56 | private function fetch($id = false) |
||
67 | |||
68 | /** |
||
69 | * Performs multiple searches in order to overcome Googles max of 40 results per request |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | private function fetchAll() |
||
77 | |||
78 | /** |
||
79 | * Finds and returns one result. Should accept a book ID (found on API responses) |
||
80 | * |
||
81 | * @param string $id |
||
82 | * @return Scriptotek\GoogleBooks\Volume |
||
83 | */ |
||
84 | public function find($id) |
||
88 | |||
89 | /** |
||
90 | * Retrieves the first result |
||
91 | * |
||
92 | * @return Scriptotek\GoogleBooks\Volume |
||
93 | */ |
||
94 | public function first() |
||
102 | |||
103 | /** |
||
104 | * Gets all the results from the query. Possibly chunks the results |
||
105 | * |
||
106 | * @return array |
||
107 | * @see chunk() |
||
108 | */ |
||
109 | public function all() |
||
117 | |||
118 | /** |
||
119 | * Sets the chunk property. Used as an alias for array chunking. Primarily for views |
||
120 | * |
||
121 | * @param int $chunk |
||
122 | * @return self |
||
123 | */ |
||
124 | public function chunk($chunk) |
||
129 | |||
130 | /** |
||
131 | * Gets the paramters to be passed to the API request. |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | private function getParams() |
||
143 | } |
||
144 |