forked from RetroAchievements/RAWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRA_API.php
97 lines (76 loc) · 2.55 KB
/
RA_API.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
class RetroAchievements
{
const API_URL = 'http://retroachievements.org/API/';
public $ra_user;
public $ra_api_key;
public function __construct( $user, $api_key )
{
$this->ra_user = $user;
$this->ra_api_key = $api_key;
}
private function AuthQS()
{
return "?z=" . $this->ra_user . "&y=" . $this->ra_api_key;
}
private function GetRAURL( $target, $params = "" )
{
return file_get_contents( self::API_URL . $target . self::AuthQS() . "&$params" );
}
public function GetTopTenUsers()
{
return json_decode( self::GetRAURL( 'API_GetTopTenUsers.php' ) );
}
public function GetGameInfo( $gameID )
{
return json_decode( self::GetRAURL( "API_GetGame.php", "i=$gameID" ) );
}
public function GetGameInfoExtended( $gameID )
{
return json_decode( self::GetRAURL( "API_GetGameExtended.php", "i=$gameID" ) );
}
public function GetConsoleIDs()
{
return json_decode( self::GetRAURL( 'API_GetConsoleIDs.php' ) );
}
public function GetGameList( $consoleID )
{
return json_decode( self::GetRAURL( "API_GetGameList.php", "i=$consoleID" ) );
}
public function GetFeedFor( $user, $count, $offset = 0 )
{
return json_decode( self::GetRAURL( "API_GetFeed.php", "u=$user&c=$count&o=$offset" ) );
}
public function GetUserRankAndScore( $user )
{
return json_decode( self::GetRAURL( "API_GetUserRankAndScore.php", "u=$user" ) );
}
public function GetUserProgress( $user, $gameIDCSV )
{
$gameIDCSV = preg_replace('/\s+/', '', $gameIDCSV); // Remove all whitespace
return json_decode( self::GetRAURL( "API_GetUserProgress.php", "u=$user&i=$gameIDCSV" ) );
}
public function GetUserRecentlyPlayedGames( $user, $count, $offset = 0 )
{
return json_decode( self::GetRAURL( "API_GetUserRecentlyPlayedGames.php", "u=$user&c=$count&o=$offset" ) );
}
public function GetUserSummary( $user, $numRecentGames )
{
return json_decode( self::GetRAURL( "API_GetUserSummary.php", "u=$user&g=$numRecentGames&a=5" ) );
}
public function GetGameInfoAndUserProgress( $user, $gameID )
{
return json_decode( self::GetRAURL( "API_GetGameInfoAndUserProgress.php", "u=$user&g=$gameID" ) );
}
public function GetAchievementsEarnedOnDay( $user, $dateInput )
{
return json_decode( self::GetRAURL( "API_GetAchievementsEarnedOnDay.php", "u=$user&d=$dateInput" ) );
}
public function GetAchievementsEarnedBetween( $user, $dateStart, $dateEnd )
{
$dateFrom = strtotime( $dateStart );
$dateTo = strtotime( $dateEnd );
return json_decode( self::GetRAURL( "API_GetAchievementsEarnedBetween.php", "u=$user&f=$dateFrom&t=$dateTo" ) );
}
};
?>