1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Api\Providers; |
4
|
|
|
|
5
|
|
|
use seregazhuk\PinterestBot\Helpers\Pagination; |
6
|
|
|
use seregazhuk\PinterestBot\Helpers\UrlBuilder; |
7
|
|
|
use seregazhuk\PinterestBot\Api\Providers\Core\Provider; |
8
|
|
|
|
9
|
|
|
class Comments extends Provider |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected $loginRequiredFor = [ |
15
|
|
|
'delete', |
16
|
|
|
'create', |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Write a comment for a pin with current id. |
21
|
|
|
* |
22
|
|
|
* @param int $pinId |
23
|
|
|
* @param string $text Comment |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public function create($pinId, $text) |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
$requestOptions = [ |
32
|
|
|
'objectId' => $this->getAggregatedPinId($pinId), |
33
|
|
|
'pinId' => $pinId, |
34
|
|
|
'text' => $text, |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
return $this->post(UrlBuilder::RESOURCE_COMMENT_PIN, $requestOptions, true); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Delete a comment for a pin with current id. |
42
|
|
|
* |
43
|
|
|
* @param string $pinId |
44
|
|
|
* @param int $commentId |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
public function delete($pinId, $commentId) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$requestOptions = ['commentId' => $commentId]; |
51
|
|
|
|
52
|
|
|
return $this->post(UrlBuilder::RESOURCE_COMMENT_DELETE_PIN, $requestOptions); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $pinId |
58
|
|
|
* @param int $limit |
59
|
|
|
* @return Pagination |
60
|
|
|
*/ |
61
|
|
|
public function getList($pinId, $limit = Pagination::DEFAULT_LIMIT) |
62
|
|
|
{ |
63
|
|
|
return $this->paginate( |
64
|
|
|
'resource/AggregatedCommentResource/get/', |
65
|
|
|
['bookmarks' => '', 'objectId' => $this->getAggregatedPinId($pinId), 'page_size' => 2], |
66
|
|
|
$limit |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $pinId |
72
|
|
|
* @return null|string |
73
|
|
|
*/ |
74
|
|
|
protected function getAggregatedPinId($pinId) |
75
|
|
|
{ |
76
|
|
|
$requestOptions = [ |
77
|
|
|
'id' => $pinId, |
78
|
|
|
'field_set_key' => 'detailed', |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
$pinInfo = $this->get(UrlBuilder::RESOURCE_PIN_INFO, $requestOptions); |
82
|
|
|
|
83
|
|
|
return isset($pinInfo['aggregated_pin_data']['id']) ? $pinInfo['aggregated_pin_data']['id'] : null; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|