Difference between revisions of "Integration:api"
Line 114: | Line 114: | ||
URL: http://yourprometheus.com/assignPackageExample2.php?key=2839123yb293y8239y1231b9y32 | URL: http://yourprometheus.com/assignPackageExample2.php?key=2839123yb293y8239y1231b9y32 | ||
− | |||
<?php | <?php | ||
SESSION_START(); | SESSION_START(); | ||
Line 154: | Line 153: | ||
} | } | ||
?> | ?> | ||
− |
Revision as of 01:41, 1 August 2015
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 |
---|---|---|---|
Hash | No | Yes | Yes |
Properties | None | steamid, package | steamid, amount |
Returns | error, cur, total, goal | error, msg | error, msg |
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']); } ?>
assignPackageExample2.php Give a package only if the user has a specific key
URL: http://yourprometheus.com/assignPackageExample2.php?key=2839123yb293y8239y1231b9y32
<?php SESSION_START(); if(isset($_SESSION['uid')){ // Replace this $SUPERSECRETKEY = '2839123yb293y8239y1231b9y32'; $api_hash = ; // API hash $package = 0; // Package ID
$url = 'http://yourprometheus.com'; // Your site url, including sub directory. But no trailing /
// DO NOT EDIT PAST THIS LINE // if($_GET['key'] == $SUPERSECRETKEY){ // Replace everything in uppercase letters with your own information $source = $url . '/api.php?hash='.$api_hash.'&action=assignPackage&package='.$package.'&steamid=' . $_SESSION['uid']; $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']); } } else { echo 'Secret key is invalid'; } } else { echo 'Not logged in. <a href=".">Go back</a>' } ?>