Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Buycraft PHP API implementation class
- *
- * @author Lmc
- *
- * ------------------------------------------------------------------------\
- *
- * DON'T BE A DICK PUBLIC LICENSE
- *
- * Version 1, December 2009
- *
- * Copyright (C) 2009 Philip Sturgeon <email@philsturgeon.co.uk>
- *
- * Everyone is permitted to copy and distribute verbatim or modified
- * copies of this license document, and changing it is allowed as long
- * as the name is changed.
- *
- * DON'T BE A DICK PUBLIC LICENSE
- *
- * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- *
- * 1. Do whatever you like with the original work, just don't be a dick.
- * Being a dick includes - but is not limited to - the following instances:
- *
- * 1a. Outright copyright infringement - Don't just copy this and change the name.
- * 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
- * 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
- *
- * 2. If you become rich through modifications, related works/services, or supporting the original work,
- * share the love. Only a dick would make loads off this work and not buy the original works
- * creator(s) a pint.
- *
- * 3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
- * you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
- *
- * ------------------------------------------------------------------------/
- */
- class Api
- {
- /**
- * Url of API location
- */
- private $apiUrl = "http://api.buycraft.net/query";
- /**
- * API secret key
- */
- private $apiSecret = "YourAuthorizationCode";
- /**
- * Calls the API and returns the JSON response
- *
- */
- private function call($params)
- {
- $params = http_build_query($params);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $this->apiUrl);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- return curl_exec($ch);
- }
- /**
- * Returns the packages currently setup for this Buycraft account in a multi-dimensional array
- *
- */
- public function packages()
- {
- $apiResponse = $this->call(array(
- 'secret' => $this->apiSecret,
- 'action' => "packages"
- ));
- return json_decode($apiResponse, TRUE);
- }
- /**
- * Creates and returns an authentification code for a given Minecraft user and Package
- *
- * NOTE: Abuse of creating authorization codes will result in a ban from using this API.
- *
- * Send users to http://buycraft.net/@AuthCodeWhatWasReturned
- */
- public function create_auth_code($username, $package)
- {
- $apiResponse = $this->call(array(
- 'secret' => $this->apiSecret,
- 'action' => "buy",
- "user" => $username,
- "package" => $package
- ));
- return json_decode($apiResponse, TRUE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement