1 | <?php namespace JobApis\Jobs\Client\Queries; |
||
3 | abstract class AbstractQuery |
||
4 | { |
||
5 | /** |
||
6 | * Create new query from parameters and defaults |
||
7 | * |
||
8 | * @param array $parameters |
||
9 | */ |
||
10 | 28 | public function __construct($parameters = []) |
|
11 | { |
||
12 | 28 | $parameters = array_merge($this->defaultAttributes(), $parameters); |
|
13 | |||
14 | 28 | foreach ($parameters as $key => $value) { |
|
15 | 28 | $this->set($key, $value); |
|
16 | 28 | } |
|
17 | 28 | } |
|
18 | |||
19 | /** |
||
20 | * Get baseUrl |
||
21 | * |
||
22 | * @return string Value of the base url to this api |
||
23 | */ |
||
24 | abstract public function getBaseUrl(); |
||
25 | |||
26 | /** |
||
27 | * Get keyword |
||
28 | * |
||
29 | * @return string Attribute being used as the search keyword |
||
30 | */ |
||
31 | abstract public function getKeyword(); |
||
32 | |||
33 | /** |
||
34 | * Attempts to get an attribute by key |
||
35 | * |
||
36 | * @param string $key |
||
37 | * |
||
38 | * @return AbstractQuery |
||
39 | */ |
||
40 | 14 | public function get($key) |
|
54 | |||
55 | /** |
||
56 | * Get http method options based on current client. Good for adding POST parameters. |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | 2 | public function getHttpMethodOptions() |
|
64 | |||
65 | /** |
||
66 | * Get query string for client based on properties |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | 4 | public function getQueryString() |
|
74 | |||
75 | /** |
||
76 | * Get url |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | 2 | public function getUrl() |
|
84 | |||
85 | /** |
||
86 | * Get http verb to use when making request |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | 2 | public function getVerb() |
|
94 | |||
95 | /** |
||
96 | * Attempts to update attribute with key/value pair |
||
97 | * |
||
98 | * @param string $key |
||
99 | * @param string $value |
||
100 | * |
||
101 | * @return AbstractQuery |
||
102 | */ |
||
103 | 28 | public function set($key, $value) |
|
119 | |||
120 | /** |
||
121 | * Determines whether the query is valid and ready to use |
||
122 | * |
||
123 | * @return bool Validity of the Query |
||
124 | */ |
||
125 | 4 | public function isValid() |
|
134 | |||
135 | /** |
||
136 | * Gets the attributes to use for this API's query |
||
137 | * |
||
138 | * @var array |
||
139 | */ |
||
140 | 4 | protected function getQueryAttributes() |
|
144 | |||
145 | /** |
||
146 | * Default parameters |
||
147 | * |
||
148 | * @var array |
||
149 | */ |
||
150 | 28 | protected function defaultAttributes() |
|
154 | |||
155 | /** |
||
156 | * Attempts to get an attribute by key |
||
157 | * |
||
158 | * @param string $key |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | 28 | protected function isValidParameter($key) |
|
169 | |||
170 | /** |
||
171 | * Required attributes for the query |
||
172 | * |
||
173 | * @var array |
||
174 | */ |
||
175 | 4 | protected function requiredAttributes() |
|
179 | |||
180 | /** |
||
181 | * Converts snake case or underscores to camelcase |
||
182 | * |
||
183 | * @param string |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | 28 | protected static function toStudlyCase($value) |
|
191 | } |
||
192 |