-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFriendFeedMessage.class.php
More file actions
131 lines (115 loc) · 3.02 KB
/
FriendFeedMessage.class.php
File metadata and controls
131 lines (115 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* FriendFeedMessage class
* Encapsulates a message to be sent to FriendFeed via the API
*
* @package FriendFeed API
* @author Evan Fribourg <evan@dotevan.com>
* @copyright 2010. All Rights Reserved.
* @license see LICENSE provided with this package.
*/
class FriendFeedMessage {
private $message = array();
private $targets = array();
/**
* Sets the message body
*
* @param String $body
* @return FriendFeedMessage Provides a fluent interface
*/
public function setBody($body) {
$this->message['body'] = $body;
return $this;
}
/**
* Gets the message body
*
* @return string
*/
public function getBody() {
return @$this->message['body'];
}
/**
* Sets the entry_id that this message references
*
* @param string $entry
* @return FriendFeedMessage Provides a fluent interface
*/
public function setEntry($entry) {
$this->message['entry'] = $entry;
return $this;
}
/**
* Gets the entry_id that this message references.
*
* @return string
*/
public function getEntry() {
return @$this->message['entry'];
}
/**
* A specific place to post the message. If not specified it will default
* to the API's current default, which is the user's personal feed. (me)
*
* @param string $target
* @return FriendFeedMessage Provides a fluent interface
*/
public function addTarget($target) {
if(!in_array($target, $this->targets)) {
array_push($this->targets, $target);
}
return $this;
}
/**
* retrieves a list of targets
* @return array
*/
public function getTargets() {
if(isset($this->message['to'])) {
$ret = $this->message['to'];
} else {
$ret = array();
}
return $ret;
}
/**
* set/replace the targets entireley with a new list.
*
* @param array $targets
*/
public function setTargets(array $targets) {
$this->targets = $targets;
}
/**
* Moves the entry value into the id field.
* Deals with the same value needed in different names for different calls
* **sigh**
*
* @return FriendFeedMessage Provides a fluent interface
*/
public function moveEntryToId() {
$this->message['id'] = @$this->message['entry'];
unset($this->message['entry']);
return $this;
}
/**
* Returns the message in a JSON encoded string
*
* @return string JSON encoded
*/
public function toJson() {
if(count($this->targets) > 0) {
$this->message['to'] = $this->targets;
}
return json_encode($this->message);
}
/**
* Returns the message in a JSON encoded string when the object
* is cast as a string
*
* @return string
*/
public function __toString() {
return $this->toJson();
}
}