Advertisement
Guest User

Untitled

a guest
Nov 15th, 2011
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.03 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  *  Buycraft PHP API implementation class
  5.  *
  6.  *  @author Lmc
  7.  *
  8.  * ------------------------------------------------------------------------\
  9.  *
  10.  *  DON'T BE A DICK PUBLIC LICENSE
  11.  *
  12.  *  Version 1, December 2009
  13.  *
  14.  *  Copyright (C) 2009 Philip Sturgeon <email@philsturgeon.co.uk>
  15.  *
  16.  *  Everyone is permitted to copy and distribute verbatim or modified
  17.  *  copies of this license document, and changing it is allowed as long
  18.  *  as the name is changed.
  19.  *
  20.  *  DON'T BE A DICK PUBLIC LICENSE
  21.  *
  22.  *  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  23.  *  
  24.  *  1.  Do whatever you like with the original work, just don't be a dick.
  25.  *      Being a dick includes - but is not limited to - the following instances:
  26.  *
  27.  *  1a. Outright copyright infringement - Don't just copy this and change the name.
  28.  *  1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
  29.  *  1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
  30.  *
  31.  *  2. If you become rich through modifications, related works/services, or supporting the original work,
  32.  *  share the love. Only a dick would make loads off this work and not buy the original works
  33.  *  creator(s) a pint.
  34.  *
  35.  *  3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
  36.  *  you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
  37.  *
  38.  * ------------------------------------------------------------------------/
  39.  */
  40.  
  41. class Api
  42. {
  43.     /**
  44.      * Url of API location
  45.      */
  46.     private $apiUrl = "http://api.buycraft.net/query";
  47.    
  48.     /**
  49.      * API secret key
  50.      */
  51.     private $apiSecret = "YourAuthorizationCode";
  52.  
  53.     /**
  54.      * Calls the API and returns the JSON response
  55.      *
  56.      */
  57.     private function call($params)
  58.     {
  59.         $params = http_build_query($params);
  60.        
  61.         $ch = curl_init();
  62.        
  63.         curl_setopt($ch, CURLOPT_URL, $this->apiUrl);
  64.         curl_setopt($ch, CURLOPT_POST, true);
  65.         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  66.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  67.         curl_setopt($ch, CURLOPT_HEADER, false);
  68.         curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  69.        
  70.         return curl_exec($ch);
  71.     }
  72.    
  73.     /**
  74.      * Returns the packages currently setup for this Buycraft account in a multi-dimensional array
  75.      *
  76.      */
  77.     public function packages()
  78.     {
  79.         $apiResponse =  $this->call(array(
  80.             'secret' => $this->apiSecret,
  81.             'action' => "packages"
  82.         ));
  83.        
  84.         return json_decode($apiResponse, TRUE);
  85.     }
  86.    
  87.     /**
  88.      * Creates and returns an authentification code for a given Minecraft user and Package
  89.      *
  90.      * NOTE: Abuse of creating authorization codes will result in a ban from using this API.
  91.      *
  92.      * Send users to http://buycraft.net/@AuthCodeWhatWasReturned
  93.      */
  94.     public function create_auth_code($username, $package)
  95.     {
  96.         $apiResponse =  $this->call(array(
  97.                     'secret' => $this->apiSecret,
  98.                     'action' => "buy",
  99.                     "user" => $username,
  100.                     "package" => $package
  101.         ));
  102.        
  103.         return json_decode($apiResponse, TRUE);
  104.     }
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement