|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* MyPoseo API Bundle |
|
7
|
|
|
* |
|
8
|
|
|
* @author Tristan Bessoussa <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Tristanbes\MyPoseoBundle\Api; |
|
12
|
|
|
|
|
13
|
|
|
use Tristanbes\MyPoseoBundle\Connection\RestClient; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @see http://fr.myposeo.com/nos-api/api-search/ |
|
17
|
|
|
*/ |
|
18
|
|
|
class Search implements SearchInterface |
|
19
|
|
|
{ |
|
20
|
|
|
private $client; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(RestClient $client) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->client = $client; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getSearchEngineExtensions(string $searchEngine, ?int $ttl = null): array |
|
28
|
|
|
{ |
|
29
|
|
|
$cacheKey = sprintf('%s_locations', $searchEngine); |
|
30
|
|
|
|
|
31
|
|
|
$data = $this->client->get('tool/json', [ |
|
32
|
|
|
'method' => 'getLocations', |
|
33
|
|
|
'searchEngine' => $searchEngine, |
|
34
|
|
|
], $cacheKey, $ttl); |
|
35
|
|
|
|
|
36
|
|
|
return $data; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getTownCode(string $name, string $country = 'FR'): array |
|
40
|
|
|
{ |
|
41
|
|
|
$data = $this->client->get('tool/json', [ |
|
42
|
|
|
'method' => 'getGeoloc', |
|
43
|
|
|
'country' => $country, |
|
44
|
|
|
'city' => $name, |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
return $data; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getUrlRankByKeyword(string $keyword, string $url, string $searchEngine = 'google', ?string $callbackUrl = null, ?int $geolocId = null, int $location = 13, ?int $maxPage = null): array |
|
51
|
|
|
{ |
|
52
|
|
|
$options = []; |
|
53
|
|
|
|
|
54
|
|
|
if (null !== $callbackUrl) { |
|
55
|
|
|
$options['callback'] = $callbackUrl; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (null !== $geolocId) { |
|
59
|
|
|
$options['geolocId'] = $geolocId; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (null !== $maxPage) { |
|
63
|
|
|
$options['maxPage'] = $maxPage; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$data = $this->client->get('tool/json', array_merge([ |
|
67
|
|
|
'method' => 'getPosition', |
|
68
|
|
|
'keyword' => $keyword, |
|
69
|
|
|
'url' => $url, |
|
70
|
|
|
'searchEngine' => $searchEngine, |
|
71
|
|
|
'location' => $location, |
|
72
|
|
|
], $options)); |
|
73
|
|
|
|
|
74
|
|
|
return $data; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getNaturalSeoResult() |
|
78
|
|
|
{ |
|
79
|
|
|
throw new \RuntimeException(sprintf('Method "%s" is not implemented.', __METHOD__)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getSemResult() |
|
83
|
|
|
{ |
|
84
|
|
|
throw new \RuntimeException(sprintf('Method "%s" is not implemented.', __METHOD__)); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|