parse-community / parse-php-sdk

The PHP SDK for Parse Platform
https://parseplatform.org/
Other
811 stars 346 forks source link

Adds ParseAudience #372

Closed montymxb closed 6 years ago

montymxb commented 6 years ago

Adds support for interacting with the _Audience class in parse-server. This provides a means of sending pushes using queries while also maintaining tracking on the last sent date and total sends.

This also adjusts ParseQuery::_setConditions, which is used internally for decoding queries in ParsePushStatus objects. This is to fix a few observed issues with the decoding process and to support decoding all conditions besides just where, such as limit, skip, order, etc.

An example of using ParseAudience could be:

$query = ParseInstallation::getQuery();
$query->equalTo("deviceType", "ios");

// create & save your audience
$audience = ParseAudience::createAudience(
    'MyiOSAudience',
    $query
);
$audience->save(true);

// send a push using the query in this audience and it's id
// The 'audience_id' is what allows parse to update 'lastUsed' and 'timesUsed'
// You could use any audience_id with any query and it will still update that audience
ParsePush::send([
    'data'          => [
        'alert' => 'hello ios users!'
    ],
    'where'         => $audience->getQuery(),
    'audience_id'   => $audience->getObjectId()
], true);

// fetch changes to this audience
$audience->fetch(true);

// get last & times used for tracking
$timesUsed = $audience->getTimesUsed();
$lastUsed = $audience->getLastUsed();
codecov[bot] commented 6 years ago

Codecov Report

Merging #372 into master will increase coverage by 0.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #372      +/-   ##
==========================================
+ Coverage   98.98%   98.99%   +0.01%     
==========================================
  Files          37       38       +1     
  Lines        3451     3498      +47     
==========================================
+ Hits         3416     3463      +47     
  Misses         35       35
Impacted Files Coverage Δ
src/Parse/ParseClient.php 99.28% <100%> (ø) :arrow_up:
src/Parse/ParsePushStatus.php 100% <100%> (ø) :arrow_up:
src/Parse/ParseAudience.php 100% <100%> (ø)
src/Parse/ParseQuery.php 99.42% <100%> (+0.03%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f72cc45...af148fe. Read the comment docs.