-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathUpdate.php
More file actions
129 lines (108 loc) · 2.86 KB
/
Update.php
File metadata and controls
129 lines (108 loc) · 2.86 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
<?php
namespace Ipalaus\Buffer;
use DateTime;
use InvalidArgumentException;
class Update
{
/**
* The status update text.
*
* @var string
*/
public $text = null;
/**
* An array of profile id’s that the status update should be sent to.
* Invalid profile_id’s will be silently ignored.
*
* @var array
*/
public $profiles = array();
/**
* If shorten is false links within the text will not be automatically
* shortened, otherwise they will.
*
* @var boolean
*/
public $shorten = 'true';
/**
* If now is set, this update will be sent immediately to all profiles
* instead of being added to the buffer.
*
* @var boolean
*/
public $now = 'false';
/**
* If top is set, this update will be added to the top of the buffer and
* will become the next update sent.
*
* @var boolean
*/
public $top = 'false';
/**
* In the absence of the media parameter, controls whether a link in the
* text should automatically populate the media parameter.
*
* @var boolean
*/
public $attachment = 'true';
/**
* An associative array of media to be attached to the update, currently
* accepts link, description and picture parameters.
*
* @var array
*/
public $media = array();
/**
* A date describing when the update should be posted. Overrides any top or
* now parameter. When using ISO 8601 format, if no UTC offset is specified,
* UTC is assumed.
*
* @var \DateTime
*/
public $scheduled_at = null;
/**
* Add a social profile to be updated.
*
* @param string $id
* @return \Ipalaus\Buffer\Update
*/
public function addProfile($id)
{
$this->profiles[] = $id;
return $this;
}
/**
* Add media to the update.
*
* @param string $key
* @param string $value
* @return \Ipalaus\Buffer\Update
*/
public function addMedia($key, $value)
{
$available = array('link', 'description', 'title', 'picture', 'photo', 'thumbnail');
// accept only valid types for media
if ( ! in_array($key, $available)) {
throw new InvalidArgumentException('Media type must be a valid value: '.implode(', ', $available));
}
$this->media[$key] = $value;
return $this;
}
/**
* Schedule a post with a timestamp or a valid DateTime string.
*
* @param mixed $when
* @return \Ipalaus\Buffer\Update
*/
public function schedule($when)
{
if (is_numeric($when)) {
$dt = new DateTime;
$dt->setTimestamp($when);
} else {
$dt = new DateTime($when);
}
$this->scheduled_at = $dt->format(DateTime::ISO8601);
return $this;
}
}