document.write(''); document.write(''); document.write(''); document.write(''); document.write('Paste provided by Paste.ee - View Original - View Raw - Download
'); document.write('
\<\?php
\n/**
\n * This program is free software: you can redistribute it and/or modify
\n * it under the terms of the GNU General Public License as published by
\n * the Free Software Foundation, either version 3 of the License, or
\n * (at your option) any later version.
\n *
\n * This program is distributed in the hope that it will be useful,
\n * but WITHOUT ANY WARRANTY; without even the implied warranty of
\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
\n * GNU General Public License for more details.
\n *
\n * You should have received a copy of the GNU General Public License
\n * along with this program.  If not, see <http://www.gnu.org/licenses/>.
\n *
\n */
\n
\n/**
\n * The main API class, used to map the api interfaces
\n * 
\n * @author Nikki
\n * 
\n */
\nclass SteamWebAPI {
\n	
\n	public $key;
\n	
\n	private $interfaces;
\n	
\n	public function __construct($key) {
\n		$this->key = $key;
\n	}
\n	
\n	public function __get($property) {
\n		if(!empty($this->interfaces->$property)) {
\n			return $this->interfaces->$property;
\n		}
\n	}
\n	
\n	public function LoadSupportedAPIList($file = false, $update = false) {
\n		if(!$update && !empty($file) && file_exists($file) && filesize($file) > 0) {
\n			$this->interfaces = new stdClass;
\n			$apis = json_decode(file_get_contents($file));
\n			foreach($apis as $obj) {
\n				$this->interfaces->{$obj->name} = new SteamWebAPIInterface($this, $obj->name, $obj->methods);
\n			}
\n		} else {
\n			$json = $this->request(\'ISteamWebAPIUtil\', \'GetSupportedAPIList\', 1, $this->make_request());
\n			
\n			// Map it into a format we can easily use
\n			$apis = new stdClass;
\n			$this->interfaces = new stdClass;
\n			foreach($json->apilist->interfaces as $obj) {
\n				$methods = new stdClass;
\n				foreach($obj->methods as $method) {
\n					$methods->{$method->name} = $method;
\n				}
\n				
\n				$this->interfaces->{$obj->name} = new SteamWebAPIInterface($this, $obj->name, $methods);
\n				
\n				$apis->{$obj->name} = array(\'name\' => $obj->name, \'methods\' => $methods);
\n			}
\n			if(!empty($file)) {
\n				file_put_contents($file, json_encode($apis));
\n			}
\n		}
\n	}
\n	
\n	private function make_request(array $info = array()) {
\n		return array_merge($info, array(\'key\' => $this->key));
\n	}
\n	
\n	public function request($api, $method, $version, array $info) {
\n		$version = \'v\' . str_pad("$version", 4, "0", STR_PAD_LEFT);
\n		$url = sprintf("http://api.steampowered.com/%s/%s/%s/?%s", $api, $method, $version, http_build_query($info));
\n		if(function_exists(\'curl_init\')) {
\n			$ch = curl_init();
\n			curl_setopt($ch, CURLOPT_URL, $url);
\n			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
\n			curl_setopt($ch, CURLOPT_HEADER, false);
\n			
\n			$res = curl_exec($ch);
\n			
\n			curl_close($ch);
\n		} else if(function_exists(\'file_get_contents\') && ini_get(\'allow_url_fopen\')) {
\n			$res = file_get_contents($url);
\n		} else {
\n			trigger_error(\'Unable to find a valid HTTP request method, please enable allow_url_fopen or install cURL.\', E_SEVERE);
\n			return false;
\n		}
\n		
\n		if($res[0] != \'{\') {
\n			trigger_error(\'Invalid response from Steam API\', E_SEVERE);
\n			return false;
\n		}
\n		
\n		return json_decode($res);
\n	}
\n}
\n
\n/**
\n * The API Interface class used to actually call the methods
\n * 
\n * @author Nikki
\n *
\n */
\nclass SteamWebAPIInterface {
\n	private $name;
\n	private $api;
\n	private $methods;
\n	
\n	public function __construct($api, $name, $methods) {
\n		$this->api = $api;
\n		$this->name = $name;
\n		$this->methods = $methods;
\n	}
\n	
\n	public function __call($name, $arguments) {
\n		if(!empty($this->methods->$name)) {
\n			$api = $this->methods->$name;
\n			
\n			$args = array();
\n			
\n			$parameters = $api->parameters;
\n			if($api->parameters[0]->name == \'key\') {
\n				array_shift($parameters);
\n				
\n				if (empty($api->requires_key)) {
\n					$api->requires_key = true;
\n				}
\n			}
\n			$paramCount = count($parameters);
\n			
\n			if(!empty($arguments)) {
\n				if(is_array($arguments[0])) {
\n					$arguments = $arguments[0];
\n					$argCount = count($parameters);
\n					// Verify arguments exist
\n					for($i = 0; $i < $paramCount; $i++) {
\n						$arg = $parameters[$i];
\n						if(!isset($arguments[$arg->name])) {
\n							return false;
\n						}
\n						$args[$arg->name] = $arguments[$arg->name];
\n					}
\n				} else {
\n					// Verify arguments and order
\n					// TODO actual ordering somehow? For now it assumes that the api list order doesn\'t change.
\n					for($i = 0; $i < $paramCount; $i++) {
\n						$arg = $parameters[$i];
\n						if(!isset($arguments[$i]) && empty($arg->optional)) {
\n							return;
\n						}
\n						$args[$arg->name] = $arguments[$i];
\n					}
\n				}
\n			}
\n			
\n			if ($api->requires_key) {
\n				$args[\'key\'] = $this->api->key;
\n			}
\n			
\n			return $this->api->request($this->name, $name, $api->version, $args);
\n		}
\n	}
\n}
'); function initEmbeddedPaste_BxUfbGqvEyX0kl2A() { hljs.highlightBlock(document.getElementById('pastee-BxUfbGqvEyX0kl2A-content')); } addEventListener('DOMContentLoaded', initEmbeddedPaste_BxUfbGqvEyX0kl2A, false); addEventListener('load', initEmbeddedPaste_BxUfbGqvEyX0kl2A, false);