|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Api\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use seregazhuk\PinterestBot\Helpers\UrlHelper; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Trait Followable |
|
9
|
|
|
* @package seregazhuk\PinterestBot\Api\Traits |
|
10
|
|
|
* |
|
11
|
|
|
* @property string $followUrl |
|
12
|
|
|
* @property string $unFollowUrl |
|
13
|
|
|
*/ |
|
14
|
|
|
trait Followable |
|
15
|
|
|
{ |
|
16
|
|
|
use HandlesRequestAndResponse, HasEntityIdName; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Follow user by user_id. |
|
20
|
|
|
* |
|
21
|
|
|
* @param $entityId |
|
22
|
|
|
* |
|
23
|
|
|
* @return bool |
|
24
|
|
|
*/ |
|
25
|
|
|
public function follow($entityId) |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->followCall($entityId, $this->getFollowUrl()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* UnFollow user by user_id. |
|
32
|
|
|
* |
|
33
|
|
|
* @param $entityId |
|
34
|
|
|
* |
|
35
|
|
|
* @return bool |
|
36
|
|
|
*/ |
|
37
|
|
|
public function unFollow($entityId) |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->followCall($entityId, $this->getUnFollowUrl()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Make api call for follow/unFollow a entity (user/board). |
|
44
|
|
|
* |
|
45
|
|
|
* @param int $entityId |
|
46
|
|
|
* @param string $resourceUrl |
|
47
|
|
|
* |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function followCall($entityId, $resourceUrl) |
|
51
|
|
|
{ |
|
52
|
|
|
$response = $this |
|
53
|
|
|
->followMethodCall( |
|
54
|
|
|
$entityId, $resourceUrl |
|
55
|
|
|
); |
|
56
|
|
|
|
|
57
|
|
|
return !$this->getResponse()->hasErrors($response); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Executes api call for follow/unfollow user. |
|
62
|
|
|
* |
|
63
|
|
|
* @param int $entityId |
|
64
|
|
|
* @param string $entityName |
|
|
|
|
|
|
65
|
|
|
* @param string $url |
|
66
|
|
|
* |
|
67
|
|
|
* @return array |
|
68
|
|
|
*/ |
|
69
|
|
|
public function followMethodCall($entityId, $url) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getRequest()->exec($url, $this->createFollowRequestQuery($entityId)); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function createFollowRequestQuery($entityId) |
|
75
|
|
|
{ |
|
76
|
|
|
$entityName = $this->getEntityIdName(); |
|
77
|
|
|
|
|
78
|
|
|
$dataJson = [ |
|
79
|
|
|
'options' => [ |
|
80
|
|
|
$entityName => (string)$entityId, |
|
81
|
|
|
], |
|
82
|
|
|
'context' => [], |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
if ($entityName == 'interest_id') { |
|
86
|
|
|
$dataJson['options']['interest_list'] = 'favorited'; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$post = ['data' => json_encode($dataJson, JSON_FORCE_OBJECT)]; |
|
90
|
|
|
return UrlHelper::buildRequestString($post); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function getFollowUrl() |
|
97
|
|
|
{ |
|
98
|
|
|
return property_exists($this, 'followUrl') ? $this->followUrl : ''; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
protected function getUnFollowUrl() |
|
105
|
|
|
{ |
|
106
|
|
|
return property_exists($this, 'followUrl') ? $this->unFollowUrl : ''; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.