1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace PeeHaa\AsyncTwitter\Api\Request\Search; |
4
|
|
|
|
5
|
|
|
use PeeHaa\AsyncTwitter\Api\Request\BaseRequest; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @link https://dev.twitter.com/rest/reference/get/search/tweets |
9
|
|
|
*/ |
10
|
|
|
class Search extends BaseRequest |
11
|
|
|
{ |
12
|
|
|
const METHOD = 'GET'; |
13
|
|
|
const ENDPOINT = '/search/tweets.json'; |
14
|
|
|
|
15
|
|
|
private $resultTypes = ['mixed', 'recent', 'popular']; |
16
|
|
|
|
17
|
19 |
|
public function __construct(string $searchString) |
18
|
|
|
{ |
19
|
19 |
|
parent::__construct(self::METHOD, self::ENDPOINT); |
20
|
|
|
|
21
|
19 |
|
$this->parameters['q'] = $searchString; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
//use string instead of float |
25
|
2 |
|
public function geocode(string $latitude, string $longitude, string $radius): Search |
26
|
|
|
{ |
27
|
2 |
|
$this->parameters['geocode'] = sprintf('%s %s %s', $latitude, $longitude, $radius); |
28
|
|
|
|
29
|
2 |
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
2 |
|
public function language(string $language = 'en'): Search |
33
|
|
|
{ |
34
|
2 |
|
$this->parameters['lang'] = $language; |
35
|
|
|
|
36
|
2 |
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
public function locale(): Search |
40
|
|
|
{ |
41
|
2 |
|
$this->parameters['locale'] = 'ja'; |
42
|
|
|
|
43
|
2 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
public function resultType(string $resultType): Search |
47
|
|
|
{ |
48
|
2 |
|
if (in_array($resultType, $this->resultTypes)) { |
49
|
2 |
|
$this->parameters['result_type'] = $resultType; |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
public function amount(int $amount): Search |
56
|
|
|
{ |
57
|
2 |
|
$this->parameters['count'] = (string) $amount; |
58
|
|
|
|
59
|
2 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
2 |
|
public function until(\DateTime $until): Search |
63
|
|
|
{ |
64
|
2 |
|
$this->parameters['until'] = $until->format('Y-m-d'); |
65
|
|
|
|
66
|
2 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
public function minimumId(int $id): Search |
70
|
|
|
{ |
71
|
2 |
|
$this->parameters['since_id'] = (string) $id; |
72
|
|
|
|
73
|
2 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
2 |
|
public function maximumId(int $id): Search |
77
|
|
|
{ |
78
|
2 |
|
$this->parameters['max_id'] = (string) $id; |
79
|
|
|
|
80
|
2 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
public function excludeEntities(): Search |
84
|
|
|
{ |
85
|
2 |
|
$this->parameters['include_entities'] = 'false'; |
86
|
|
|
|
87
|
2 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|