|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* You are hereby granted a non-exclusive, worldwide, royalty-free license to |
|
6
|
|
|
* use, copy, modify, and distribute this software in source code or binary |
|
7
|
|
|
* form for use in connection with the web services and APIs provided by |
|
8
|
|
|
* Facebook. |
|
9
|
|
|
* |
|
10
|
|
|
* As with any software that integrates with the Facebook platform, your use |
|
11
|
|
|
* of this software is subject to the Facebook Developer Principles and |
|
12
|
|
|
* Policies [http://developers.facebook.com/policy/]. This copyright notice |
|
13
|
|
|
* shall be included in all copies or substantial portions of the software. |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
18
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
20
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
21
|
|
|
* DEALINGS IN THE SOFTWARE. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace FacebookAds\Object; |
|
26
|
|
|
|
|
27
|
|
|
use FacebookAds\Api; |
|
28
|
|
|
use FacebookAds\Cursor; |
|
29
|
|
|
use FacebookAds\Http\RequestInterface; |
|
30
|
|
|
|
|
31
|
|
|
class TargetingSearch extends AbstractObject |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $query |
|
35
|
|
|
* @param string $type |
|
36
|
|
|
* @param string $class |
|
37
|
|
|
* @param array $params |
|
38
|
|
|
* @param Api $api |
|
39
|
|
|
* @return Cursor |
|
40
|
|
|
* @throws \InvalidArgumentException |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function search( |
|
43
|
|
|
$type, |
|
44
|
|
|
$class=null, |
|
45
|
|
|
$query=null, |
|
46
|
|
|
array $params = array(), |
|
47
|
|
|
Api $api = null |
|
48
|
|
|
) { |
|
49
|
|
|
$api = $api ?: Api::instance(); |
|
50
|
|
|
if (!$api) { |
|
51
|
|
|
throw new \InvalidArgumentException( |
|
52
|
|
|
'An Api instance must be provided as argument or '. |
|
53
|
|
|
'set as instance in the \FacebookAds\Api' |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$params['type'] = $type; |
|
58
|
|
|
$params = array_merge($params, array_filter(array( |
|
59
|
|
|
'class' => $class, |
|
60
|
|
|
'q' => $query, |
|
61
|
|
|
))); |
|
62
|
|
|
|
|
63
|
|
|
$response = $api->call('/search', RequestInterface::METHOD_GET, $params); |
|
64
|
|
|
return new Cursor($response, new TargetingSearch()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|