Difference between revisions of "Integration:api"

From PrometheusIPN Wiki
Jump to: navigation, search
Line 114: Line 114:
 
URL: http://yourprometheus.com/assignPackageExample2.php?key=2839123yb293y8239y1231b9y32
 
URL: http://yourprometheus.com/assignPackageExample2.php?key=2839123yb293y8239y1231b9y32
  
  <?php
+
<code php>
  SESSION_START();
+
<?php
  if(isset($_SESSION['uid')){
+
SESSION_START();
// Replace this
+
if(isset($_SESSION['uid')){
$SUPERSECRETKEY = '2839123yb293y8239y1231b9y32';
+
// Replace this
$api_hash = ''; // API hash
+
$SUPERSECRETKEY = '2839123yb293y8239y1231b9y32';
$package = 0; // Package ID
+
$api_hash = ''; // API hash
$url = 'http://yourprometheus.com'; // Your site url, including sub directory. But no trailing /
+
$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){
+
// DO NOT EDIT PAST THIS LINE //
// Replace everything in uppercase letters with your own information
+
if($_GET['key'] == $SUPERSECRETKEY){
$source = $url . '/api.php?hash='.$api_hash.'&action=assignPackage&package='.$package.'&steamid=' . $_SESSION['uid'];
+
// Replace everything in uppercase letters with your own information
$ch = curl_init();
+
$source = $url . '/api.php?hash='.$api_hash.'&action=assignPackage&package='.$package.'&steamid=' . $_SESSION['uid'];
curl_setopt($ch, CURLOPT_URL, $source);
+
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_SSLVERSION,4);
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
+
curl_setopt($ch, CURLOPT_SSLVERSION,4);
$error = curl_error($ch);
+
$data = curl_exec($ch);
curl_close ($ch);
+
$error = curl_error($ch);
if($data === false) {
+
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
die('Curl error: ' . $error);
+
if($array['error'] == 1){
}
+
die($array['msg']);
// Decode the data response
+
}
$array = json_decode($data, true);
+
// Display success message
// Display an error if there is any
+
if($array['error'] == 0){
if($array['error'] == 1){
+
echo($array['msg']);
die($array['msg']);
+
}
}
+
} else { echo 'Secret key is invalid'; }
// Display success message
+
} else {
if($array['error'] == 0){
+
echo 'Not logged in. <a href=".">Go back</a>'
echo($array['msg']);
+
}
}
+
?>
} else { echo 'Secret key is invalid'; }
+
</code>
    } else {
 
echo 'Not logged in. <a href=".">Go back</a>'
 
    }
 
  ?>
 

Revision as of 01:38, 1 August 2015

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
Api calls
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>' } ?>