Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


greena5 last won the day on February 16 2013

greena5 had the most liked content!

About greena5

  • Rank
  • Birthday 08/07/1979

Profile Information

  • Gender
    Not Telling
  • Location
    Darlington, United Kingdom

Recent Profile Visitors

81 profile views
  1. See my wrapper I've just posted and have a play about with it. Still a little bit of work to be done on it so feel free to make the changes you need, maybe a bonus for you as it uses file_get_contents(). I've posted some instructions/guidance on it too. have fun
  2. I managed to push fixes to my forked version of your wrapper here https://github.com/andrewgreenwood23/Xbox-API-Wrapper Can you pull this in to your version if its acceptable? Still not entirely sure based on what I've read.
  3. <?php // This try/catch can be placed in the file where you wish to process the received data // The $data variable will contain the data if exceptions are not thrown try { $requestData = array(); $api = new LeadersApi(); foreach ($api->_allowedRequests as $var) { $requestData[$var] = (isset($_GET[$var])) ? $_GET[$var] : null; } $data = $api->processRequest($requestData); } catch (Exception $e) { echo $e->getMessage(); } // Below can go in a new file but remember to include it!! Class LeadersApi { /** * A list of all possible request variables * * @var array */ public $_allowedRequests = array('type', 'tag', 'gameId'); /** * The base URL for the API * * @var string */ protected $_baseUri = 'http://www.xboxleaders.com/api/'; /** * Gets the data from a URL build with supplied parameters * * @param $file String * @param $requestVars array */ protected function getData($file, array $requestVars) { try { $url = $this->_baseUri . strtolower($file) . ".json?" . http_build_query($requestVars, null, '&'); return json_decode(file_get_contents($url)); } catch (Exception $e) { return $e; } } /** * Construct method to ensure user has correct libs */ public function __construct() { if (!function_exists('json_decode')) { throw new Exception('This wrapper requires the JSON library'); } } /** * Processed the variables collected from the view * * @param $options array */ public function processRequest(array $options) { if(null !== $options['type']) { $type = ($options['type'] = ucfirst(strtolower($options['type']))); if(method_exists(get_class($this), 'get' . $type)) { $method = "get" . $type; return $this->$method($options); } else { throw new Exception("The type: " . $options['type'] . ", does not exist!"); } } else { throw new Exception('The request type has not been set'); } } /** * Ensures the parameters for games have been set and can therefore process data * Will otherwise throw an exception * * @param $option array */ protected function getGames($option) { if (null !== $option['tag']) { $parameters = array( 'gamertag' => $option['tag'] ); return $this->getData($option['type'], $parameters); } else { $message = $this->exceptionMessage(__FUNCTION__); throw new Exception($message); } } /** * Ensures the parameters for profile have been set and can therefore process data * Will otherwise throw an exception * * @param $option array */ protected function getProfile($option) { if (null !== $option['tag']) { $parameters = array( 'gamertag' => $option['tag'] ); return $this->getData($option['type'], $parameters); } else { $message = $this->exceptionMessage(__FUNCTION__); throw new Exception($message); } } /** * Ensures the parameters for achievements have been set and can therefore process data * Will otherwise throw an exception * * @param $option array */ protected function getAchievements($option) { if(null !== $option['tag'] && null !== $option['gameId'] ) { $parameters = array( 'gamertag' => $option['tag'], 'gameid' => $option['gameId'] ); return $this->getData($option['type'], $parameters); } else { $message = $this->exceptionMessage(__FUNCTION__); throw new Exception($message); } } /** * Ensures the parameters for friends have been set and can therefore process data * Will otherwise trow an exception * * @param $option array */ protected function getFriends($option) { if(null !== $option['tag']) { $parameters = array( 'gamertag' => $option['tag'] ); return $this->getData($option['type'], $parameters); } else { $message = $this->exceptionMessage(__FUNCTION__); throw new Exception($message); } } /** * Generic message for all of the 'get' * @param $message string (the function name it was initiated on) */ public function exceptionMessage($message) { return "Unable to process $message request, the variables have not been set"; } } Here's a wrapper I quickly knocked up tonight and its loosely based on the wrapper I'm sure you've all seen on Github. It only returns decoded JSON Object Array (Not XML, PHP Blah Blah Blah). The idea is that URL or the POST request variables determine what action is to be done when the Class is instantiated. There is however, as of yet, no validation around the gamertag which to be honest is in the wrapper on github so feel free to mash this and that together if desired (I would advise you to do it!). Anyway, it's nothing that I am using, just thought I would try knocking one up. Also, It doesn't use cURL, not sure if this is a good thing or a bad thing as I'm quite a noob in terms of coding experience Erm, what else.... The $_allowedRequests are the variable keys that must be passed for example: www.mywebsite.com?type=profile&tag=gamertag when 2 params are required such as the achievements request, this might look like: www.mywebsite.com?type=achievements&tag=gamertag&gameId=1096157379 type can be: profile, achievements, games, friends. Which then maps to the relevant method in the Class. Regards Andrew Any questions, either post on here of course, or, you can send me a message on twitter @addictedtoxbox
  4. Okay, so I gave it a shot. Not reading any instructions beforehand (stupid I know), I forked the repo, cloned it on my machine, setup the upstream/master, made changes, committed and pushed to my repo, but how do I push to yours? Be gentle, I'm a complete noob at this...
  5. Okay, I'll give GitHub a bash. Any problems, I'll just mail the file to you or post it on here.
  6. I've been looking to do something similar, so if you find a way of doing this, can you let me know? I was looking at the 360 voice API for one particular reason, and that's the fact they keep an average score for all their users for every game but there's no way of creating a relationship between Voice and most other API's as a lot of their game titles are way different to everywhere else and the game ID's are just awful. I could do it with XboxLeaders and just keep it to the friends of the requested user but that would lead to possibly hundreds of requests p/hour, would be a strain on resources no doubt, would get me banned and would it be worth it for one float value? No, lol.
  7. Hi all, I'm sort of new to this, although I use git on my dev machine at work as a local repo but I don't use it at home and therefore have never used the github site itself. I copied the code from the lib file here: https://github.com/j...api.wrapper.php and plopped the code in a new file on my machine. I had a few small problems getting the code to work at first but its now working really well. Quick question, the code in the linked file above, is this what I would have pulled from github? If so, I am willing to post my fixes on here or, get to grips with github and contribute. Keep up the good work guys
  8. Hello, New to the forum, just been looking at your API docs and this looks like a good product! Just wondering, I have also been reading the terms of service and noticed the following: "excessively frequent requests to XboxLeaders via the API may result in the temporary or permanent suspension of your account's access to the API" I don't have an account with you guys, so, what is deemed as excessive if using the free option? X amount of requests per hour? Cheers Andy G (@addictedtoxbox)
  • Create New...