-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.php
57 lines (53 loc) · 2.19 KB
/
get.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* NxFitbit - Cron commandline tool
*
* @version 0.0.1
* @author Stuart McCulloch Anderson <stuart@nxfifteen.me.uk>
* @link http://nxfifteen.me.uk NxFIFTEEN
* @copyright 2015 Stuart McCulloch Anderson
* @license http://stuart.nx15.at/mit/2015 MIT
*/
parse_str( implode( '&', array_slice( $argv, 1 ) ), $argv );
foreach ( $argv as $key => $value ) {
$key = str_ireplace( "--", "", $key );
$_GET[ $key ] = $value;
}
require_once( dirname( __FILE__ ) . "/inc/app.php" );
$fitbitApp = new NxFitbit();
if ( $fitbitApp->isUser( $_GET['user'] ) ) {
$cooldown = $fitbitApp->getUserCooldown( $_GET['user'] );
if ( strtotime( $cooldown ) < strtotime( date( "Y-m-d H:i:s" ) ) ) {
if ( $fitbitApp->supportedApi( $_GET['get'] ) != $_GET['get'] ) {
nxr( "Forcing pull of " . $fitbitApp->supportedApi( $_GET['get'] ) . " for " . $_GET['user'] );
$fitbitApp->getFitbitAPI( $_GET['user'] )->setForceSync( TRUE );
$fitbitApp->getFitbitAPI( $_GET['user'] )->pull( $_GET['user'], $_GET['get'] );
} else {
nxr( "Unknown trigger " . $_GET['get'] . ". Supported calls are:" );
print_r( $fitbitApp->supportedApi() );
}
} else {
$fitbitApp->getErrorRecording()->captureMessage( "API limit reached", array( 'remote_api' ), array(
'level' => 'info',
'extra' => array(
'api_req' => $_GET['get'],
'user' => $_GET['user'],
'cooldown' => $cooldown,
'php_version' => phpversion(),
'core_version' => $this->getAppClass()->getSetting( "version", "0.0.0.1", TRUE )
)
) );
nxr( "Can not process " . $fitbitApp->supportedApi( $_GET['get'] ) . ". API limit reached for " . $_GET['user'] . ". Cooldown period ends " . $cooldown );
}
} else {
$fitbitApp->getErrorRecording()->captureMessage( "Unknown User", array( 'authentication' ), array(
'level' => 'info',
'extra' => array(
'api_req' => $_GET['get'],
'user' => $_GET['user'],
'php_version' => phpversion(),
'core_version' => $this->getAppClass()->getSetting( "version", "0.0.0.1", TRUE )
)
) );
nxr( "Can not process " . $fitbitApp->supportedApi( $_GET['get'] ) . " since " . $_GET['user'] . " is no longer a user." );
}