Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# Install the AMEEconnect Ruby SDK with 'gem install amee' # See https://github.com/AMEE/amee-ruby require 'rubygems' require 'amee' # Server connection details SERVER = "stage.amee.com" USERNAME = "your_api_key" PASSWORD = "your_api_key" # The path and drill to identify the correct calculation CATEGORY = "/business/processes/production/aluminium/alternative" DRILL = "type=Normal" # Create a connection to the server amee = AMEE::Connection.new(SERVER, USERNAME, PASSWORD) # Create a new profile profile = AMEE::Profile::Profile.create(amee) # Get the UID of the data item uid = AMEE::Data::DrillDown.get(amee, "/data#{CATEGORY}/drill?#{DRILL}").data_item_uid # Prepare the values for the calculation # The following values MUST be provided for this usage required_values = { :anodeQuantity => 'SOME_VALUE', :byprodQuantity => 'SOME_VALUE', :cokeQuantity => 'SOME_VALUE', :packingQuantity => 'SOME_VALUE', :pitchQuantity => 'SOME_VALUE', :soldQuantity => 'SOME_VALUE' } # The following values MAY be provided for this usage optional_values = { :carbonAnode => 'SOME_VALUE', :carbonCoke => 'SOME_VALUE', :carbonPacking => 'SOME_VALUE', :carbonPitch => 'SOME_VALUE', :carbonSold => 'SOME_VALUE' } # Store profile item and perform calculation item = AMEE::Profile::Item.create_without_category(amee, "/profiles/#{profile.uid}#{CATEGORY}", uid, required_values.merge(optional_values) ) # Print results puts 'Result:' item.amounts.each do |amt| puts "#{amt[:type]}: #{amt[:value]} #{amt[:unit]}#{'/'+amt[:per_unit] if amt[:per_unit].present?}" end |
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
<?php // Install the AMEEconnect PHP SDK with 'pear install pearhub/Services_AMEE' // See https://github.com/AMEE/amee-lib-php // Include required files require_once 'Services/AMEE/DataItem.php'; require_once 'Services/AMEE/Profile.php'; require_once 'Services/AMEE/ProfileItem.php'; // Server connection details define('AMEE_API_URL', 'stage.amee.com'); define('AMEE_API_PROJECT_KEY', 'your_api_key'); define('AMEE_API_PROJECT_PASSWORD', 'your_api_password'); // The path and drill to identify the correct calculation $sProfileCategory = "business/processes/production/aluminium/alternative"; $aProfileCategory = array( "type" => "Normal" ); try { // Create a new profile $oProfile = new Services_AMEE_Profile(); // Get the data item $oDataItem = new Services_AMEE_DataItem($sProfileCategory, $aProfileCategory); // Prepare the values for the calculation // The following values MUST be provided for this usage $aRequiredProfileItemValues = array( 'anodeQuantity' => 'SOME_VALUE', 'byprodQuantity' => 'SOME_VALUE', 'cokeQuantity' => 'SOME_VALUE', 'packingQuantity' => 'SOME_VALUE', 'pitchQuantity' => 'SOME_VALUE', 'soldQuantity' => 'SOME_VALUE' ); // The following values MAY be provided for this usage $aOptionalProfileItemValues = array( 'carbonAnode' => 'SOME_VALUE', 'carbonCoke' => 'SOME_VALUE', 'carbonPacking' => 'SOME_VALUE', 'carbonPitch' => 'SOME_VALUE', 'carbonSold' => 'SOME_VALUE' ); // Store profile item and perform calculation $oProfileItem = new Services_AMEE_ProfileItem(array( $oProfile, $oDataItem, array_merge($aRequiredProfileItemValues, $aOptionalProfileItemValues) )); // Display the result $aInfo = $oProfileItem->getInfo(); echo "Result:\n"; echo "CO2 ({$aInfo['unit']}/{$aInfo['perUnit']}): {$aInfo['amount']}\n"; } catch (Exception $oException) { // An error occured echo "Error: " . $oException->getMessage() . "\n"; } ?> |
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
// First, get the AMEEconnect Java SDK and add to your CLASSPATH // See https://github.com/AMEE/amee-lib-java import java.util.List; import java.util.ArrayList; import com.amee.client.AmeeException; import com.amee.client.service.*; import com.amee.client.model.base.*; import com.amee.client.model.profile.*; import com.amee.client.model.data.*; import com.amee.client.util.Choice; public class CreateProfileItem { public static void main(String[] args) throws AmeeException { // Set up connection to the server AmeeContext.getInstance().setUsername("your_api_key"); AmeeContext.getInstance().setPassword("your_api_password"); AmeeContext.getInstance().setBaseUrl("http://stage.amee.com"); AmeeObjectFactory objectFactory = AmeeObjectFactory.getInstance(); // The path and drill to identify the correct calculation String profileCategory = "business/processes/production/aluminium/alternative"; AmeeDrillDown drillDown = objectFactory.getDrillDown("business/processes/production/aluminium/alternative/drill"); drillDown.addSelection("type","Normal"); // Create a new profile AmeeProfile profile = objectFactory.getProfile(); // Get the UID of the data item drillDown.fetch(); String dataItemUID = drillDown.getDataItem().getUid(); // Set options for new item List<Choice> values = new ArrayList<Choice>(); // The following values MUST be provided for this usage values.add(new Choice("anodeQuantity", SOME_VALUE)); values.add(new Choice("byprodQuantity", SOME_VALUE)); values.add(new Choice("cokeQuantity", SOME_VALUE)); values.add(new Choice("packingQuantity", SOME_VALUE)); values.add(new Choice("pitchQuantity", SOME_VALUE)); values.add(new Choice("soldQuantity", SOME_VALUE)); // The following values MAY be provided for this usage values.add(new Choice("carbonAnode", SOME_VALUE)); values.add(new Choice("carbonCoke", SOME_VALUE)); values.add(new Choice("carbonPacking", SOME_VALUE)); values.add(new Choice("carbonPitch", SOME_VALUE)); values.add(new Choice("carbonSold", SOME_VALUE)); // Store profile item and perform calculation AmeeProfileCategory cat = objectFactory.getProfileCategory(profile, profileCategory); AmeeProfileItem item = cat.addProfileItem(dataItemUID, values); // Print results System.out.println("Result:"); System.out.format("CO2 (kg/year): %s\n", item.getAmount()); } } |
cURL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# These commands assume a bash shell and that # you have curl and xpath available. # Create profile and get UID curl 'https://stage.amee.com/profiles' \ -X POST \ -d 'profile=true' \ -H 'Accept: application/xml' \ -u your_api_key:your_api_password \ | xpath '//Profile/@uid' # Get data item UID curl 'https://stage.amee.com/data/business/processes/production/aluminium/alternative/drill?type=Normal' \ -H 'Accept: application/xml' \ -u your_api_key:your_api_password \ | xpath '//Choices/Choice/Name/text()' # Perform calculation curl 'https://stage.amee.com/profiles/PROFILE_UID/business/processes/production/aluminium/alternative' \ -X POST \ -d 'dataItemUid=DATA_ITEM_UID&representation=full&anodeQuantity=SOME_VALUE&byprodQuantity=SOME_VALUE&cokeQuantity=SOME_VALUE&packingQuantity=SOME_VALUE&pitchQuantity=SOME_VALUE&soldQuantity=SOME_VALUE' \ -H 'Accept: application/xml' \ -u username:password \ | xpath '//Amounts/Amount' |