You are here

API.txt in Currency 7

Same filename and directory in other branches
  1. 5 currency_api/API.txt
  2. 6 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_convert($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_api_convert($from, $to, $amt);
 *   if ($ret['status'] == FALSE) {
 *     drupal_set_message(t('An error occured: '). $ret['message']);
 *   }
 *   else {
 *     print $amt . ' ' . $from . ' = ' . $ret['value'] . ' ' . $to;
 *   }
 *
 * @param $currency_from
 *   Currency to convert from.
 * @param $currency_to
 *   Currency to convert to.
 * @param $amount
 *   (optional) Amount to convert. Defaults to 1.
 * @param $decimals
 *   (optional) Number of digits to the right of the decimal point. Leave out this
 *   parameter if you want the actual currency result to proceess it yourself.
 *   Defaults to NULL.
 *
 * @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['rate'] - Exchange rate of $currency_from into $currency_to
 *    $result['timestamp'] - Timestamp of the last update to the rates
 *    $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_symbol($currency)

 * This function gets the currency symbol 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_api_get_symbol($ccode);
 *   if ($ret == FALSE) {
 *     drupal_set_message(t('Could not get symbol'));
 *   }
 *   else {
 *     print $ccode .' => '. $ret;
 *   }
 *
 * @param $currency
 *   Currency code (3-letter ISO)
 *
 * @return $result
 *   Contains FALSE if the currency symbol cannot be found, otherwise, it
 *   has the symbol.

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_convert($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_api_convert($from, $to, $amt);
  16. * if ($ret['status'] == FALSE) {
  17. * drupal_set_message(t('An error occured: '). $ret['message']);
  18. * }
  19. * else {
  20. * print $amt . ' ' . $from . ' = ' . $ret['value'] . ' ' . $to;
  21. * }
  22. *
  23. * @param $currency_from
  24. * Currency to convert from.
  25. * @param $currency_to
  26. * Currency to convert to.
  27. * @param $amount
  28. * (optional) Amount to convert. Defaults to 1.
  29. * @param $decimals
  30. * (optional) Number of digits to the right of the decimal point. Leave out this
  31. * parameter if you want the actual currency result to proceess it yourself.
  32. * Defaults to NULL.
  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['rate'] - Exchange rate of $currency_from into $currency_to
  42. * $result['timestamp'] - Timestamp of the last update to the rates
  43. * $result['date'] - Date of the last update to the rates (Format is "m/d/yyyy")
  44. * $result['time'] - Time of the last update to the rates (Format is "h:mmpm")
  45. function currency_api_get_desc($currency)
  46. * This function gets the currency name for a standard ISO 3-letter codes,
  47. * You can find the details here:
  48. * http://www.oanda.com/site/help/iso_code.shtml
  49. *
  50. * Here is an example on how to use it:
  51. *
  52. * $ccode = 'CAD';
  53. * $ret = currency_get_description($ccode);
  54. * if ($ret == FALSE)
  55. * {
  56. * drupal_set_message(t('Could not get description'));
  57. * }
  58. * else
  59. * {
  60. * print $ccode .' => '. $ret;
  61. * }
  62. *
  63. * @param $currency
  64. * Currency code (3-letter ISO)
  65. *
  66. * @return $result
  67. * Contains FALSE if the currency cannot be found, otherwise, it
  68. * has the description.
  69. function currency_api_get_symbol($currency)
  70. * This function gets the currency symbol for a standard ISO 3-letter codes,
  71. * You can find the details here:
  72. * http://www.oanda.com/site/help/iso_code.shtml
  73. *
  74. * Here is an example on how to use it:
  75. *
  76. * $ccode = 'CAD';
  77. * $ret = currency_api_get_symbol($ccode);
  78. * if ($ret == FALSE) {
  79. * drupal_set_message(t('Could not get symbol'));
  80. * }
  81. * else {
  82. * print $ccode .' => '. $ret;
  83. * }
  84. *
  85. * @param $currency
  86. * Currency code (3-letter ISO)
  87. *
  88. * @return $result
  89. * Contains FALSE if the currency symbol cannot be found, otherwise, it
  90. * has the symbol.
  91. function currency_api_get_list()
  92. * Returns a list of supported currencies