This repository was archived by the owner on Feb 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFN.class.php
More file actions
153 lines (141 loc) · 4.24 KB
/
FFN.class.php
File metadata and controls
153 lines (141 loc) · 4.24 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* A simple PHP5 class to retrieve data from FantasyFootballNerd.com (FFN)
* Class is available free of charge, however you will need an API Key to return results.
* The class is intended to retrieve data from FFN, but please store the data locally to remain
* bandwidth-friendly.
*
* @author J. Joseph Dyken <nerd@fantasyfootballnerd.com>
* @copyright Copyright (c) 2010, TayTech, LLC
* @version 1.1 2010-08-21
*
* This is a fork of the above. Author information for the fork:
* @author Philip Olson <philip@roshambo.org>
* Version is not being tracked at this time. See https://github.com/philip/FantasyNerdAPI for commit history.
*
**/
class FFN {
/**
* Your API Key from FantasyFootballNerd.com
* @var int
**/
private $apiKey;
private $baseurl = "http://www.fantasyfootballnerd.com/service/";
/**
* Error Message - a holder for any error that we may encounter
* @var string
**/
public $errorMsg;
/**
* Constructor
*
* @param int $apiKey Your API Key given to you by registering at FantasyFootballNerd.com
**/
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}//-----
/**
* Get the season schedule
* This will return a stdClass object with the season schedule
*
* @return object
**/
public function getSchedule() {
$url = $this->baseurl . "schedule/json/" . $this->apiKey . "/";
if (!$data = $this->fetch($url)) {
return false;
}
return $data;
}//-----
/**
* Get the list of players from FFN
* This will return a stdClass object with all the NFL players. This does not need to be called
* more than once per week as it doesn't change with much frequency.
*
* @return array
**/
public function getPlayers() {
$url = $this->baseurl . "players/json/" . $this->apiKey . "/";
if (!$data = $this->fetch($url)) {
return false;
}
return $data['Players'];
}
/**
* Get player details
* This will return a stdClass object with the details for the player requested.
*
* @param int $playerId The FFN playerId to retrieve
* @return object
**/
public function getPlayerDetails($playerId) {
$url = $this->baseurl . "player/json/" . $this->apiKey . "/" . $playerId;
if (!$data = $this->fetch($url)) {
return false;
}
return $data;
}//-----
/**
* Get Draft Rankings
* This will return a stdClass object with the current preseason draft rankings
*
* @param string $position The position to retrieve. Options: ALL, QB, RB, WR, TE, DEF, K
* @param int $limit How many results to return. Pass an integer between 1 and 1000
* @param int $sos Return the Strength of Schedule for every player? Pass a 1 for yes, 0 for no
* @return object
**/
public function getDraftRankings($ppr = 0) {
$url = $this->baseurl . "draft-rankings/json/" . $this->apiKey . "/" . $ppr;
if (!$data = $this->fetch($url)) {
return false;
}
return $data;
}//-----
/**
* Get the current injury list
* This will return an array of stdClass objects with a list of injured players by team
*
* @param int $week The week number to retrieve injuries for (1-17)
* @return object
**/
public function getInjuries($week = 1) {
$url = $this->baseurl . "injuries/json/" . $this->apiKey . "/" . $week;
if (!$data = $this->fetch($url)) {
return false;
}
return $data;
}//-----
/**
* Get Weekly Projections
* This will return an array of stdClass objects with the requested week's projections
*
* @param string $position The position to retrieve. Options: QB, RB, WR, TE, DEF, K
* @param int $week The week to return results for (1-17)
* @return object
**/
public function getWeeklyRankings($position = 'QB', $week = 1, $ppr = 1) {
$url = $this->baseurl . "weekly-rankings/json/" . $this->apiKey . "/" . $position . '/' . $week . '/' . $ppr;
if (!$data = $this->fetch($url)) {
return false;
}
return $data;
}//-----
/**
* Utility to call the FFN endpoint and return the data result
* The url with the appropriate vars attached to it.
*
* @param string $url The endpoint url that we're calling
**/
private function fetch($url) {
$json = file_get_contents($url);
if (empty($json)) {
return false;
}
$data = json_decode($json, true);
if (empty($data) || !is_array($data)) {
return false;
}
return $data;
}//-----------------------------
}
?>