-
Notifications
You must be signed in to change notification settings - Fork 0
/
userclass.php
executable file
·56 lines (48 loc) · 1.39 KB
/
userclass.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
<?php
class user{
var $id;
var $uname;
var $name;
var $fccurl;
var $apiurl;
var $points;
function __construct($id,$uname,$name){
//echo "i am in\n";
$this->id=$id;
$this->uname=$uname;
$this->name=$name;
$this->fccurl="https://www.freecodecamp.com/".$uname;
$this->apiurl="https://www.freecodecamp.com/api/users/about?username=".strtolower($uname);
//$this->points = self::pointsFetcher();
//echo $this->points."\n";
//echo "i am out\n";
}
function pointsFetcher(){
try{
/*$result=file_get_contents($this->apiurl);
$object = json_decode($result);
echo "got the data\n";*/
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$this->apiurl);
// Execute
$object=curl_exec($ch);
// Closing
curl_close($ch);
// Will dump a beauty json :3
$object=json_decode($object, true);
//var_dump($object["about"]->browniePoints);
if(isset($object["about"]["browniePoints"]))
return $object["about"]["browniePoints"];
else
return 0;
}catch(Exception $e){
}
}
}
?>