Skip to content

Commit 61e527f

Browse files
mkherlakiannorkunas
authored andcommitted
Added segment_name and last_active_since parameters to CSV export (#120)
* 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
1 parent 1d2fded commit 61e527f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/Devices.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ public function onFocus($id, array $data)
173173
*
174174
* Application auth key must be set.
175175
*
176-
* @param array $extraFields Additional fields that you wish to include.
177-
* Currently supports: "location", "country", "rooted"
176+
* @param array $extraFields Additional fields that you wish to include.
177+
* Currently supports: "location", "country", "rooted"
178+
* @param string $segmentName A segment name to filter the scv export by.
179+
* Only devices from that segment will make it into the export
180+
* @param int $lastActiveSince An epoch to filter results to users active after this time
178181
*
179182
* @return array
180183
*/
181-
public function csvExport(array $extraFields = [])
184+
public function csvExport(array $extraFields = [], $segmentName = null, $lastActiveSince = null)
182185
{
183186
$url = '/players/csv_export?app_id='.$this->api->getConfig()->getApplicationId();
184187

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

196+
if (null !== $segmentName) {
197+
$body['segment_name'] = $segmentName;
198+
}
199+
200+
if (null !== $lastActiveSince) {
201+
$body['last_active_since'] = (string) $lastActiveSince;
202+
}
203+
193204
return $this->api->request('POST', $url, $headers, json_encode($body));
194205
}
195206
}

tests/OneSignal/Tests/DevicesTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ public function testOnPurchase()
113113

114114
public function testCsvExport()
115115
{
116+
$lastActiveSince = time() - 30 * 86400;
117+
116118
$expectedRequest = [
117119
'POST',
118120
'/players/csv_export?app_id=fakeApplicationId',
119121
['Authorization' => 'Basic fakeApplicationAuthKey'],
120-
'{"extra_fields":["myField1","myField2"]}',
122+
'{"extra_fields":["myField1","myField2"],"segment_name":"Active Users","last_active_since":"'.$lastActiveSince.'"}',
121123
];
122124

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

0 commit comments

Comments
 (0)