Skip to content

Instantly share code, notes, and snippets.

@Jmayhak
Created June 30, 2011 00:03
Show Gist options
  • Save Jmayhak/1055321 to your computer and use it in GitHub Desktop.
Save Jmayhak/1055321 to your computer and use it in GitHub Desktop.
pull all flurry data for your platforms
#!/usr/bin/php
<?php
// NOTE: create a folder for each metric. ./ActiveUsers and ./NewUsers and etc
$appMetrics = array('ActiveUsers', 'NewUsers', 'MedianSessionLength', 'AvgSessionLength', 'Sessions', 'RetainedUsers');
// define your platforms as listed in Flurry
$platforms = array();
// define the dates you want to pull. 1 year increments (flurry limitation)
// array('start' => 'end', 'next start' => 'next end')
$dates = array();
// define your api access code
$api_access_code = '';
foreach ($appMetrics as $appMetric) {
foreach ($platforms as $platform) {
$apikey = '';
// define each platform's api key you specified above
switch ($platform) {
default:
$apikey = 'nothing';
break;
}
$response = '';
foreach ($dates as $start_date => $end_date) {
$url = "http://api.flurry.com/appMetrics/$appMetric?apiAccessCode=$api_access_code&apiKey=$apiKey&startDate=$start_date&endDate=$end_date";
// set up however you want to request the data.
// NOTE: this part WILL fail. you need to set it up for your environment
$rest_request = new Model_Request($url);
$rest_request->execute();
$request_info = $rest_request->getResponseInfo();
if ($request_info['http_code'] != 200) {
file_put_contents(__DIR__ . '/error.json', $rest_request->getResponseBody(), FILE_APPEND);
}
else {
if ($start_date != '2008-05-31') { // compare to your first start date
$old_response_array = json_decode($response, true);
$new_response_array = json_decode($rest_request->getResponseBody(), true);
if (is_array($new_response_array['day'])) {
foreach ($new_response_array['day'] as $day) {
$old_response_array['day'][] = $day;
}
}
else {
echo print_r($new_response_array['day']);
}
$response = json_encode($old_response_array);
}
else {
$response = $rest_request->getResponseBody();
}
}
sleep(3); // sleep for a little bit
}
file_put_contents(__DIR__ . '/' . $appMetric . '/' . $platform . '.json', $response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment