|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file contains the PulseUser class |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright 2015 Vladimir Jimenez |
|
7
|
|
|
* @license https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace allejo\DaPulse; |
|
11
|
|
|
|
|
12
|
|
|
use allejo\DaPulse\Exceptions\IllegalAccessException; |
|
13
|
|
|
use allejo\DaPulse\Objects\ApiUser; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The PulseUser class contains all of the functions related to accessing information about a user |
|
17
|
|
|
* |
|
18
|
|
|
* @package allejo\DaPulse |
|
19
|
|
|
* @since 0.1.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class PulseUser extends ApiUser |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
const API_PREFIX = "users"; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The membership type of this user with respect to a specific Pulse or PulseBoard. This value will not be set if |
|
30
|
|
|
* a PulseUser object is created standalone and not by another object which supports subscribers or membership. |
|
31
|
|
|
* |
|
32
|
|
|
* @var mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $membership; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The URL pattern used for all calls |
|
38
|
|
|
* |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
private $urlSyntax = "%s/%s/%s.json"; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getMembership () |
|
47
|
|
|
{ |
|
48
|
|
|
if (isset($this->membership)) |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->membership; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
throw new IllegalAccessException("This value is not accessible which means this user was not created in regards to another object."); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get the user's newsfeed |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $params GET parameters that need to be passed in the URL |
|
60
|
|
|
* |
|
61
|
|
|
* @since 0.1.0 |
|
62
|
|
|
* |
|
63
|
|
|
* @return PulseUpdate[] An array of PulseUpdates that make up the user's newsfeed |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getNewsFeed ($params = array()) |
|
66
|
|
|
{ |
|
67
|
|
|
$url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "newsfeed"); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
return parent::fetchJsonArrayToObjectArray($url, "PulseUpdate", $params); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get the user's posts |
|
74
|
|
|
* |
|
75
|
|
|
* @param array $params GET parameters that need to be passed in the URL |
|
76
|
|
|
* |
|
77
|
|
|
* @since 0.1.0 |
|
78
|
|
|
* |
|
79
|
|
|
* @return PulseUpdate[] An array of PulseUpdates for each of the posts |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getPosts ($params = array()) |
|
82
|
|
|
{ |
|
83
|
|
|
$url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "posts"); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
return parent::fetchJsonArrayToObjectArray($url, "PulseUpdate", $params); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get the user's unread posts |
|
90
|
|
|
* |
|
91
|
|
|
* @param array $params GET parameters that need to be passed in the URL |
|
92
|
|
|
* |
|
93
|
|
|
* @since 0.1.0 |
|
94
|
|
|
* |
|
95
|
|
|
* @return PulseUpdate[] An array of PulseUpdates for each of the posts |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getUnreadFeed ($params = array()) |
|
98
|
|
|
{ |
|
99
|
|
|
$url = sprintf($this->urlSyntax, parent::apiEndpoint(), $this->id, "unread_feed"); |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
return parent::fetchJsonArrayToObjectArray($url, "PulseUpdate", $params); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Get all of the users |
|
106
|
|
|
* |
|
107
|
|
|
* @param array $params GET parameters that need to be passed in the URL |
|
108
|
|
|
* |
|
109
|
|
|
* @since 0.1.0 |
|
110
|
|
|
* |
|
111
|
|
|
* @return PulseUser[] An array of PulseUsers for each of the users |
|
112
|
|
|
*/ |
|
113
|
|
|
public static function getUsers ($params = array()) |
|
114
|
|
|
{ |
|
115
|
|
|
$url = sprintf("%s.json", parent::apiEndpoint()); |
|
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
return parent::fetchJsonArrayToObjectArray($url, "PulseUser", $params); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
} |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.