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
|
|
|
$requestOptions = [ |
30
|
|
|
'objectId' => $this->getAggregatedPinId($pinId), |
31
|
|
|
'pinId' => $pinId, |
32
|
|
|
'text' => $text, |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
return $this->post(UrlBuilder::RESOURCE_COMMENT_PIN, $requestOptions, true); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Delete a comment for a pin with current id. |
40
|
|
|
* |
41
|
|
|
* @param string $pinId |
42
|
|
|
* @param int $commentId |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
|
|
public function delete($pinId, $commentId) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$requestOptions = ['commentId' => $commentId]; |
49
|
|
|
|
50
|
|
|
return $this->post(UrlBuilder::RESOURCE_COMMENT_DELETE_PIN, $requestOptions); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string $pinId |
56
|
|
|
* @param int $limit |
57
|
|
|
* @return Pagination |
58
|
|
|
*/ |
59
|
|
|
public function getList($pinId, $limit = Pagination::DEFAULT_LIMIT) |
60
|
|
|
{ |
61
|
|
|
return $this->paginate( |
62
|
|
|
'resource/AggregatedCommentResource/get/', |
63
|
|
|
['bookmarks' => '', 'objectId' => $this->getAggregatedPinId($pinId), 'page_size' => 2], |
64
|
|
|
$limit |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $pinId |
70
|
|
|
* @return null|string |
71
|
|
|
*/ |
72
|
|
|
protected function getAggregatedPinId($pinId) |
73
|
|
|
{ |
74
|
|
|
$requestOptions = [ |
75
|
|
|
'id' => $pinId, |
76
|
|
|
'field_set_key' => 'detailed', |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
$pinInfo = $this->get(UrlBuilder::RESOURCE_PIN_INFO, $requestOptions); |
80
|
|
|
|
81
|
|
|
return isset($pinInfo['aggregated_pin_data']['id']) ? $pinInfo['aggregated_pin_data']['id'] : null; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|