Skip to content

Commit 71c2fec

Browse files
committedJul 26, 2012
Update README.md
1 parent 2914932 commit 71c2fec

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed
 

‎README.md

+92-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,92 @@
1-
mustached-canvas
2-
================
1+
Canv.as stats script
2+
===
3+
4+
Usage
5+
---
6+
CanvasStats is a PHP class which provides methods to get stats about canv.as users.
7+
8+
Objects of class CanvasStats contain stats for a single user, passed as a parameter to the class constructor.
9+
10+
Functions
11+
===
12+
new CanvasStats($user)
13+
---
14+
Creates a new CanvasStats object and loads stats for username $user.
15+
16+
CanvasStats objects provide the following functions:
17+
18+
$obj->getAllStickers()
19+
---
20+
This method returns a list with detailed sticker count.
21+
22+
Return value is an array of the form [(str)sticker_type] => (int)amount
23+
24+
$obj->getNumStickers()
25+
---
26+
Returns total number of stickers for the user
27+
28+
$obj->getNumPosts()
29+
---
30+
Returns total number of posts for the user
31+
32+
$obj->getPoints()
33+
---
34+
Returns total number of points
35+
36+
$obj->getAvgPoints()
37+
---
38+
Returns average points per post
39+
40+
$obj->getApiCalls()
41+
---
42+
Returns number of calls made to Canv.as API
43+
44+
$obj->error()
45+
---
46+
FALSE if user stats were loaded correctly
47+
Error message otherwise
48+
49+
CanvasStats::weight()
50+
---
51+
Static function which returns number of point for the given sticker type.
52+
53+
Example: weight("fuck-yeah") = 150
54+
55+
Example
56+
===
57+
<html>
58+
<head>
59+
<title>Canv.as stats example</title>
60+
</head>
61+
<body>
62+
<?php
63+
if (!isset($_GET["user"])) { ?>
64+
<form method="GET">
65+
<input type="text" name="user" placeholder="Canvas username">
66+
<input type="submit">
67+
</form>
68+
<?php
69+
} else {
70+
$user = htmlspecialchars($_GET["user"]);
71+
include("CanvasStats.php");
72+
$canvas_stats = new CanvasStats($user);
73+
if ($canvas_stats->error()){
74+
die($canvas_stats->error());
75+
}
76+
echo "<h1>Sticker list:</h1>\r\n";
77+
echo "<ul>";
78+
foreach($canvas_stats->getAllStickers() as $type => $amount) {
79+
echo "<li><b>$type:</b> $amount</li>\r\n";
80+
}
81+
echo "</ul>\r\n\r\n";
82+
echo "<h1>Additional stats:</h1>\r\n";
83+
echo "<p><b>Number of stickers:</b> ".$canvas_stats->getNumStickers()."</p>\r\n";
84+
echo "<p><b>Number of posts:</b> ".$canvas_stats->getNumPosts()."</p>\r\n";
85+
echo "<p><b>Total points:</b> ".$canvas_stats->getPoints()."</p>\r\n";
86+
echo "<p><b>Average points per post:</b> ".$canvas_stats->getAvgPoints()."</p>\r\n";
87+
echo "<p><i>A total of ".$canvas_stats->getApiCalls()." calls to Canv.as api were needed to get these stats.</i></p>\r\n";
88+
89+
}?>
90+
91+
</body>
92+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.