You are here

API.txt in Currency 5

Same filename and directory in other branches
  1. 6 currency_api/API.txt
  2. 7 currency_api/API.txt
The currency module provides two callable API functions that allow other
modules to do real time currency exchange.

The functions are:

function currency_api_exchange($currency_from, $currency_to, $amount = 1)

 * This function converts two currencies using exchange rates from Yahoo Finance.
 * The currency codes are standard ISO 3-letter codes, and you can find the details
 * here:
 *  http://www.oanda.com/site/help/iso_code.shtml
 *
 * Here is an example on how to use it:
 *
 *   $from = 'CAD';
 *   $to   = 'USD';
 *   $amt  = 20;
 *   $ret = currency_exchange($from, $to, $amt);
 *   if ($ret['status'] == FALSE)
 *   {
 *     drupal_set_message(t('An error occured: '). $ret['message']);
 *   }
 *   else
 *   {
 *     print $amt .' '. $from .' = '. $ret['value'];
 *   }
 *
 * @param $currency_from
 *   Currency to convert from
 *
 * @param $currency_to
 *   Currency to convert to
 *
 * @param $amount
 *   Option amount to convert. If not supplied, 1 is assumed.
 *
 * @return $result
 *   An associative array that contains the following:
 *    $result['status'] TRUE or FALSE
 *    $result['message']'success' when status is TRUE, otherwise, contains a 
 *                      descriptive error text
 *   The following items are only returned when status is TRUE
 *    $result['value']  $amount * exchange rate of $currency_from into $currency_to
 *    $result['date']   Date of the last update to the rates (Format is "m/d/yyyy")
 *    $result['time']   Time of the last update to the rates (Format is "h:mmpm")

function currency_api_get_desc($currency)

 * This function gets the currency name for a standard ISO 3-letter codes,
 * You can find the details here:
 *  http://www.oanda.com/site/help/iso_code.shtml
 *
 * Here is an example on how to use it:
 *
 *   $ccode = 'CAD';
 *   $ret = currency_get_description($ccode);
 *   if ($ret == FALSE)
 *   {
 *     drupal_set_message(t('Could not get description'));
 *   }
 *   else
 *   {
 *     print $ccode .' => '. $ret;
 *   }
 *
 * @param $currency
 *   Currency code (3-letter ISO)
 *
 * @return $result
 *   Contains FALSE if the currency cannot be found, otherwise, it
 *   has the description.

function currency_api_get_list()

 * Returns a list of supported currencies

File

currency_api/API.txt
View source
  1. The currency module provides two callable API functions that allow other
  2. modules to do real time currency exchange.
  3. The functions are:
  4. function currency_api_exchange($currency_from, $currency_to, $amount = 1)
  5. * This function converts two currencies using exchange rates from Yahoo Finance.
  6. * The currency codes are standard ISO 3-letter codes, and you can find the details
  7. * here:
  8. * http://www.oanda.com/site/help/iso_code.shtml
  9. *
  10. * Here is an example on how to use it:
  11. *
  12. * $from = 'CAD';
  13. * $to = 'USD';
  14. * $amt = 20;
  15. * $ret = currency_exchange($from, $to, $amt);
  16. * if ($ret['status'] == FALSE)
  17. * {
  18. * drupal_set_message(t('An error occured: '). $ret['message']);
  19. * }
  20. * else
  21. * {
  22. * print $amt .' '. $from .' = '. $ret['value'];
  23. * }
  24. *
  25. * @param $currency_from
  26. * Currency to convert from
  27. *
  28. * @param $currency_to
  29. * Currency to convert to
  30. *
  31. * @param $amount
  32. * Option amount to convert. If not supplied, 1 is assumed.
  33. *
  34. * @return $result
  35. * An associative array that contains the following:
  36. * $result['status'] TRUE or FALSE
  37. * $result['message']'success' when status is TRUE, otherwise, contains a
  38. * descriptive error text
  39. * The following items are only returned when status is TRUE
  40. * $result['value'] $amount * exchange rate of $currency_from into $currency_to
  41. * $result['date'] Date of the last update to the rates (Format is "m/d/yyyy")
  42. * $result['time'] Time of the last update to the rates (Format is "h:mmpm")
  43. function currency_api_get_desc($currency)
  44. * This function gets the currency name for a standard ISO 3-letter codes,
  45. * You can find the details here:
  46. * http://www.oanda.com/site/help/iso_code.shtml
  47. *
  48. * Here is an example on how to use it:
  49. *
  50. * $ccode = 'CAD';
  51. * $ret = currency_get_description($ccode);
  52. * if ($ret == FALSE)
  53. * {
  54. * drupal_set_message(t('Could not get description'));
  55. * }
  56. * else
  57. * {
  58. * print $ccode .' => '. $ret;
  59. * }
  60. *
  61. * @param $currency
  62. * Currency code (3-letter ISO)
  63. *
  64. * @return $result
  65. * Contains FALSE if the currency cannot be found, otherwise, it
  66. * has the description.
  67. function currency_api_get_list()
  68. * Returns a list of supported currencies