Difference between revisions of "Integration:api"
(→assignPackage Example) |
m (Reverted edits by 86.156.41.224 (talk) to last revision by Marcuz) |
||
| Line 1: | Line 1: | ||
| − | + | ====== The API ====== | |
| + | ===== What is this api? ===== | ||
| + | An API(Application Program Interface), is a way of communication with a system both internally and externally. With Prometheus this allows you to do the following things currently: | ||
| − | + | Add a package to a user(Using Steam64 or SteamID) | |
| + | Get donation goal info | ||
| + | |||
| + | The API has a few things you can designate: | ||
| + | |||
| + | ''hash'' - The hash you generate above if you enable API. This has to be kept a secret. Do not give it to anyone else. | ||
| + | |||
| + | ''action'' - The performed action | ||
| + | |||
| + | ''steamid'' - The users steamid | ||
| + | |||
| + | ''package'' - The package | ||
| + | |||
| + | ===== How do I use it? ===== | ||
| + | The API is accessed by typing this into your browser: | ||
| + | |||
| + | http://yourprometheus.com/api.php?hash=HASH&action=ACTION | ||
| + | |||
| + | Not all actions require a hash, for instance the getGoal action does not require a hash and can be accessed directly. The API returns the response in **JSON**. It can be securely communicated with using **cURL**. | ||
===== List of actions ===== | ===== List of actions ===== | ||
| Line 34: | Line 54: | ||
===== Examples ===== | ===== Examples ===== | ||
| − | + | ==== getGoal Example ==== | |
| + | |||
| + | '''getGoalExample.php''' | ||
| + | <?php | ||
| + | |||
| + | $get = file_get_contents('http://marcuz.eu/ipn/api.php?action=getGoal'); | ||
| + | $array = json_decode($get, true); | ||
| + | |||
| + | if($array['error'] == 0){ | ||
| + | $percentage = $array['perc']; | ||
| + | $total = $array['total']; | ||
| + | $goal = $array['goal']; | ||
| + | $currency = $array['cur']; | ||
| + | |||
| + | echo ' | ||
| + | <b>Goal:</b> '.$goal.' '.$currency.'<br> | ||
| + | <b>Received:</b> '.$total.' '.$currency.'<br> | ||
| + | <b>Percentage:</b> '.$percentage.'% | ||
| + | '; | ||
| + | } | ||
| + | |||
| + | ?> | ||
| + | ==== assignPackage Example ==== | ||
| + | '''assignPackageExample.php''' | ||
| + | <?php | ||
| + | |||
| + | // Replace everything in uppercase letters with your own information | ||
| + | $source = 'http://yourprometheus.com/api.php?hash=YOUR_HASH&action=assignPackage&package=PACKAGE_ID&steamid=STEAM64_OR_STEAMID'; | ||
| + | |||
| + | $ch = curl_init(); | ||
| + | curl_setopt($ch, CURLOPT_URL, $source); | ||
| + | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
| + | curl_setopt($ch, CURLOPT_SSLVERSION,4); | ||
| + | $data = curl_exec($ch); | ||
| + | $error = curl_error($ch); | ||
| + | curl_close ($ch); | ||
| + | |||
| + | if($data === false) { | ||
| + | // Display an error if there is any | ||
| + | die('Curl error: ' . $error); | ||
| + | } | ||
| + | |||
| + | // Decode the data response | ||
| + | $array = json_decode($data, true); | ||
| + | |||
// Display an error if there is any | // Display an error if there is any | ||
if($array['error'] == 1){ | if($array['error'] == 1){ | ||
Revision as of 02:57, 30 August 2016
Contents
The API
What is this api?
An API(Application Program Interface), is a way of communication with a system both internally and externally. With Prometheus this allows you to do the following things currently:
Add a package to a user(Using Steam64 or SteamID) Get donation goal info
The API has a few things you can designate:
hash - The hash you generate above if you enable API. This has to be kept a secret. Do not give it to anyone else.
action - The performed action
steamid - The users steamid
package - The package
How do I use it?
The API is accessed by typing this into your browser:
http://yourprometheus.com/api.php?hash=HASH&action=ACTION
Not all actions require a hash, for instance the getGoal action does not require a hash and can be accessed directly. The API returns the response in **JSON**. It can be securely communicated with using **cURL**.
List of actions
| Action | getGoal | assignPackage | addCredits | getPackages |
|---|---|---|---|---|
| Hash | No | Yes | Yes | Yes |
| Properties | None | steamid, package | steamid, amount | None |
| Returns | error, cur, total, goal | error, msg | error, msg | error, packages |
Examples
getGoal Example
getGoalExample.php
<?php
$get = file_get_contents('http://marcuz.eu/ipn/api.php?action=getGoal');
$array = json_decode($get, true);
if($array['error'] == 0){
$percentage = $array['perc'];
$total = $array['total'];
$goal = $array['goal'];
$currency = $array['cur'];
echo '
Goal: '.$goal.' '.$currency.'
Received: '.$total.' '.$currency.'
Percentage: '.$percentage.'%
';
}
?>
assignPackage Example
assignPackageExample.php
<?php
// Replace everything in uppercase letters with your own information
$source = 'http://yourprometheus.com/api.php?hash=YOUR_HASH&action=assignPackage&package=PACKAGE_ID&steamid=STEAM64_OR_STEAMID';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSLVERSION,4);
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close ($ch);
if($data === false) {
// Display an error if there is any
die('Curl error: ' . $error);
}
// Decode the data response
$array = json_decode($data, true);
// Display an error if there is any
if($array['error'] == 1){
die($array['msg']);
}
// Display success message
if($array['error'] == 0){
echo($array['msg']);
}
?>