Skip to content

Commit 9e2c3d0

Browse files
author
Arthur Cinader
authored
Merge pull request #305 from montymxb/push-status-status
Added methods to ParsePushStatus for checking push status
2 parents a5cd7ac + 1f79079 commit 9e2c3d0

File tree

3 files changed

+99
-17
lines changed

3 files changed

+99
-17
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,21 +284,25 @@ if(ParsePush::hasStatus($response)) {
284284

285285
// Retrieve PushStatus object
286286
$pushStatus = ParsePush::getStatus($response);
287-
288-
// get push status string
289-
$status = $pushStatus->getPushStatus();
290-
291-
if($status == "succeeded") {
292-
// handle a successful push request
293-
294-
} else if($status == "running") {
287+
288+
// check push status
289+
if($pushStatus->isPending()) {
290+
// handle a pending push request
291+
292+
} else if($pushStatus->isRunning()) {
295293
// handle a running push request
296-
297-
} else if($status == "failed") {
298-
// push request did not succeed
299-
294+
295+
} else if($pushStatus->hasSucceeded()) {
296+
// handle a successful push request
297+
298+
} else if($pushStatus->hasFailed()) {
299+
// handle a failed request
300+
300301
}
301302

303+
// ...or get the push status string to check yourself
304+
$status = $pushStatus->getPushStatus();
305+
302306
// get # pushes sent
303307
$sent = $pushStatus->getPushesSent();
304308

src/Parse/ParsePushStatus.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ class ParsePushStatus extends ParseObject
1111
{
1212
public static $parseClassName = '_PushStatus';
1313

14+
// possible push status values from parse server
15+
const STATUS_SCHEDULED = 'scheduled';
16+
const STATUS_PENDING = 'pending';
17+
const STATUS_RUNNING = 'running';
18+
const STATUS_SUCCEEDED = 'succeeded';
19+
const STATUS_FAILED = 'failed';
20+
21+
/**
22+
* 'scheduled', 'pending', etc. Add constants and 'isPending' and such for better status checking
23+
*/
24+
1425
/**
1526
* Returns a push status object or null from an id
1627
*
@@ -98,6 +109,61 @@ public function getPushStatus()
98109

99110
}
100111

112+
/**
113+
* Indicates whether this push is scheduled
114+
*
115+
* @return bool
116+
*/
117+
public function isScheduled()
118+
{
119+
return $this->getPushStatus() === self::STATUS_SCHEDULED;
120+
121+
}
122+
123+
/**
124+
* Indicates whether this push is pending
125+
*
126+
* @return bool
127+
*/
128+
public function isPending()
129+
{
130+
return $this->getPushStatus() === self::STATUS_PENDING;
131+
132+
}
133+
134+
/**
135+
* Indicates whether this push is running
136+
*
137+
* @return bool
138+
*/
139+
public function isRunning()
140+
{
141+
return $this->getPushStatus() === self::STATUS_RUNNING;
142+
143+
}
144+
145+
/**
146+
* Indicates whether this push has succeeded
147+
*
148+
* @return bool
149+
*/
150+
public function hasSucceeded()
151+
{
152+
return $this->getPushStatus() === self::STATUS_SUCCEEDED;
153+
154+
}
155+
156+
/**
157+
* Indicates whether this push has failed
158+
*
159+
* @return bool
160+
*/
161+
public function hasFailed()
162+
{
163+
return $this->getPushStatus() === self::STATUS_FAILED;
164+
165+
}
166+
101167
/**
102168
* Gets the number of pushes sent
103169
*

tests/Parse/ParsePushTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public function testPushDates()
123123
{
124124
ParsePush::send(
125125
[
126-
'data' => ['alert' => 'iPhone 5 is out!'],
127-
'push_time' => new \DateTime(),
128-
'expiration_time' => new \DateTime(),
129-
'channels' => [],
126+
'data' => ['alert' => 'iPhone 5 is out!'],
127+
'push_time' => new \DateTime(),
128+
'expiration_time' => new \DateTime(),
129+
'channels' => [],
130130
]
131131
, true);
132132
}
@@ -215,10 +215,18 @@ public function testGettingPushStatus()
215215
$this->assertEquals("rest", $pushStatus->getPushSource(),
216216
'Source was not rest');
217217

218+
// verify not scheduled
219+
$this->assertFalse($pushStatus->isScheduled());
220+
221+
// verify not pending
222+
$this->assertFalse($pushStatus->isPending());
223+
218224
// verify 'running'
219-
$this->assertEquals("running", $pushStatus->getPushStatus(),
225+
$this->assertTrue($pushStatus->isRunning(),
220226
'Push did not succeed');
221227

228+
229+
222230
// verify # sent & failed
223231
$this->assertEquals(0, $pushStatus->getPushesSent(),
224232
'More than 0 pushes sent');
@@ -228,6 +236,10 @@ public function testGettingPushStatus()
228236
$this->assertNotNull($pushStatus->getPushHash(),
229237
'Hash not present');
230238

239+
// verify we have neither failed or succeeded
240+
$this->assertFalse($pushStatus->hasFailed());
241+
$this->assertFalse($pushStatus->hasSucceeded());
242+
231243
}
232244

233245
/**

0 commit comments

Comments
 (0)