Skip to content

Commit

Permalink
Added segment_name and last_active_since parameters to CSV export (#120)
Browse files Browse the repository at this point in the history
* Added segment_name and last_active_since parameters to CSV export

* fixed style issues

* removed nullable php7 question mark

* make type hinting compatible with 5.6

* removed forgotten int

* changed 2 is_null instances to null !==, and added @param to docblock as per code review

* fixed style issues

* fixed docblock formatting
  • Loading branch information
mkherlakian authored and norkunas committed Jul 13, 2019
1 parent 1d2fded commit 61e527f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/Devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ public function onFocus($id, array $data)
*
* Application auth key must be set.
*
* @param array $extraFields Additional fields that you wish to include.
* Currently supports: "location", "country", "rooted"
* @param array $extraFields Additional fields that you wish to include.
* Currently supports: "location", "country", "rooted"
* @param string $segmentName A segment name to filter the scv export by.
* Only devices from that segment will make it into the export
* @param int $lastActiveSince An epoch to filter results to users active after this time
*
* @return array
*/
public function csvExport(array $extraFields = [])
public function csvExport(array $extraFields = [], $segmentName = null, $lastActiveSince = null)
{
$url = '/players/csv_export?app_id='.$this->api->getConfig()->getApplicationId();

Expand All @@ -190,6 +193,14 @@ public function csvExport(array $extraFields = [])
'extra_fields' => $extraFields,
];

if (null !== $segmentName) {
$body['segment_name'] = $segmentName;
}

if (null !== $lastActiveSince) {
$body['last_active_since'] = (string) $lastActiveSince;
}

return $this->api->request('POST', $url, $headers, json_encode($body));
}
}
6 changes: 4 additions & 2 deletions tests/OneSignal/Tests/DevicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ public function testOnPurchase()

public function testCsvExport()
{
$lastActiveSince = time() - 30 * 86400;

$expectedRequest = [
'POST',
'/players/csv_export?app_id=fakeApplicationId',
['Authorization' => 'Basic fakeApplicationAuthKey'],
'{"extra_fields":["myField1","myField2"]}',
'{"extra_fields":["myField1","myField2"],"segment_name":"Active Users","last_active_since":"'.$lastActiveSince.'"}',
];

$this->assertEquals($expectedRequest, $this->devices->csvExport(['myField1', 'myField2']));
$this->assertEquals($expectedRequest, $this->devices->csvExport(['myField1', 'myField2'], 'Active Users', $lastActiveSince));
}
}

0 comments on commit 61e527f

Please sign in to comment.