|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ZanySoft\LaravelSerpApi; |
|
4
|
|
|
|
|
5
|
|
|
use ZanySoft\LaravelSerpApi\Lib\BaiduSearch; |
|
6
|
|
|
use ZanySoft\LaravelSerpApi\Lib\BingSearch; |
|
7
|
|
|
use ZanySoft\LaravelSerpApi\Lib\DuckDuckgoSearch; |
|
8
|
|
|
use ZanySoft\LaravelSerpApi\Lib\EbaySearch; |
|
9
|
|
|
use ZanySoft\LaravelSerpApi\Lib\GoogleSearch; |
|
10
|
|
|
use ZanySoft\LaravelSerpApi\Lib\NaverSearch; |
|
11
|
|
|
use ZanySoft\LaravelSerpApi\Lib\SerpApiSearch as SerpApi; |
|
12
|
|
|
use ZanySoft\LaravelSerpApi\Lib\WalmartSearch; |
|
13
|
|
|
use ZanySoft\LaravelSerpApi\Lib\YahooSearch; |
|
14
|
|
|
use ZanySoft\LaravelSerpApi\Lib\YandexSearch; |
|
15
|
|
|
use ZanySoft\LaravelSerpApi\Lib\YelpSearch; |
|
16
|
|
|
use ZanySoft\LaravelSerpApi\Lib\YouTubeSearch; |
|
17
|
|
|
|
|
18
|
|
|
class SerpApiSearch |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
protected $api_key = null; |
|
22
|
|
|
|
|
23
|
|
|
protected $engine = null; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct($api_key, $engine = null) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->api_key = $api_key; |
|
28
|
|
|
$this->engine = $engine; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return GoogleSearch |
|
33
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
34
|
|
|
*/ |
|
35
|
|
|
public function GoogleSearch($api_key = null) |
|
36
|
|
|
{ |
|
37
|
|
|
return new GoogleSearch($api_key ?: $this->api_key); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return BaiduSearch |
|
42
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function BaiduSearch($api_key = null) |
|
45
|
|
|
{ |
|
46
|
|
|
return new BaiduSearch($api_key ?: $this->api_key); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return BingSearch |
|
51
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function BingSearch($api_key = null) |
|
54
|
|
|
{ |
|
55
|
|
|
return new BingSearch($api_key ?: $this->api_key); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return EbaySearch |
|
60
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
61
|
|
|
*/ |
|
62
|
|
|
public function EbaySearch($api_key = null) |
|
63
|
|
|
{ |
|
64
|
|
|
return new EbaySearch($api_key ?: $this->api_key); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return WalmartSearch |
|
69
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
70
|
|
|
*/ |
|
71
|
|
|
public function WalmartSearch($api_key = null) |
|
72
|
|
|
{ |
|
73
|
|
|
return new WalmartSearch($api_key ?: $this->api_key); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return YahooSearch |
|
78
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
79
|
|
|
*/ |
|
80
|
|
|
public function YahooSearch($api_key = null) |
|
81
|
|
|
{ |
|
82
|
|
|
return new YahooSearch($api_key ?: $this->api_key); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return YandexSearch |
|
87
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
88
|
|
|
*/ |
|
89
|
|
|
public function YandexSearch($api_key = null) |
|
90
|
|
|
{ |
|
91
|
|
|
return new YandexSearch($api_key ?: $this->api_key); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return YouTubeSearch |
|
96
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
97
|
|
|
*/ |
|
98
|
|
|
public function YouTubeSearch($api_key = null) |
|
99
|
|
|
{ |
|
100
|
|
|
return new YouTubeSearch($api_key ?: $this->api_key); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return DuckDuckgoSearch |
|
105
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
106
|
|
|
*/ |
|
107
|
|
|
public function DuckDuckgoSearch($api_key = null) |
|
108
|
|
|
{ |
|
109
|
|
|
return new DuckDuckgoSearch($api_key ?: $this->api_key); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @return NaverSearch |
|
114
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
115
|
|
|
*/ |
|
116
|
|
|
public function NaverSearch($api_key = null) |
|
117
|
|
|
{ |
|
118
|
|
|
return new NaverSearch($api_key ?: $this->api_key); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return YelpSearch |
|
123
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
124
|
|
|
*/ |
|
125
|
|
|
public function YelpSearch($api_key = null) |
|
126
|
|
|
{ |
|
127
|
|
|
return new YelpSearch($api_key ?: $this->api_key); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param $engine |
|
132
|
|
|
* @return SerpApi |
|
133
|
|
|
* @throws Exceptions\SerpApiSearchException |
|
134
|
|
|
*/ |
|
135
|
|
|
public function SerpApiSearch($engine = null) |
|
136
|
|
|
{ |
|
137
|
|
|
if (!$engine) { |
|
138
|
|
|
$engine = $this->engine; |
|
139
|
|
|
} |
|
140
|
|
|
return new SerpApi($this->api_key, $engine); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|