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 |
# 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 = "/transport/train/route" DRILL = "type=auto" # 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 = { :station1 => 'SOME_VALUE', :station2 => 'SOME_VALUE', :trainType => 'SOME_VALUE' } # The following values MAY be provided for this usage optional_values = { :occupancy => 'SOME_VALUE', :passengers => 'SOME_VALUE' } # The following values MAY be provided for this usage but will not affect the result ignored_values = { :legDetail => 'SOME_VALUE', :totalDistance => '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.merge(ignored_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 |
<?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 = "transport/train/route"; $aProfileCategory = array( "type" => "auto" ); 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( 'station1' => 'SOME_VALUE', 'station2' => 'SOME_VALUE', 'trainType' => 'SOME_VALUE' ); // The following values MAY be provided for this usage $aOptionalProfileItemValues = array( 'occupancy' => 'SOME_VALUE', 'passengers' => 'SOME_VALUE' ); // The following values MAY be provided for this usage but will not affect the result $aIgnoredProfileItemValues = array( 'legDetail' => 'SOME_VALUE', 'totalDistance' => 'SOME_VALUE' ); // Store profile item and perform calculation $oProfileItem = new Services_AMEE_ProfileItem(array( $oProfile, $oDataItem, array_merge($aRequiredProfileItemValues, $aOptionalProfileItemValues, $aIgnoredProfileItemValues) )); // 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 |
// 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 = "transport/train/route"; AmeeDrillDown drillDown = objectFactory.getDrillDown("transport/train/route/drill"); drillDown.addSelection("type","auto"); // 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("station1", SOME_VALUE)); values.add(new Choice("station2", SOME_VALUE)); values.add(new Choice("trainType", SOME_VALUE)); // The following values MAY be provided for this usage values.add(new Choice("occupancy", SOME_VALUE)); values.add(new Choice("passengers", SOME_VALUE)); // The following values MAY be provided for this usage but will not affect the result values.add(new Choice("legDetail", SOME_VALUE)); values.add(new Choice("totalDistance", 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/transport/train/route/drill?type=auto' \ -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/transport/train/route' \ -X POST \ -d 'dataItemUid=DATA_ITEM_UID&representation=full&station1=SOME_VALUE&station2=SOME_VALUE&trainType=SOME_VALUE' \ -H 'Accept: application/xml' \ -u username:password \ | xpath '//Amounts/Amount' |