Index: currency_api.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/currency/currency_api/currency_api.module,v
retrieving revision 1.4.2.4
diff -u -p -r1.4.2.4 currency_api.module
--- currency_api.module	29 Oct 2007 22:27:51 -0000	1.4.2.4
+++ currency_api.module	17 Mar 2008 23:21:37 -0000
@@ -26,8 +26,20 @@ function currency_api_menu($may_cache) {
   }
   return $items;
 }
-  
+
+/**
+ * Instantiation of hook_admin_settings()
+ */
 function currency_api_admin_settings() {    
+  $form['currency_api_vendor'] = array(
+    '#type' => 'radios',
+    '#title' => t('Choose currency provider'),    
+    '#default_value' => variable_get('currency_api_vendor', 'all'),    
+    '#options' => array('nyfed' => t('New York Federal Bank'), 
+                        'yahoo' => t('Yahoo Finance')), 
+    '#description' => t("Note: Please read Yahoo's TOS if choosing Yahoo or All. <br/> Choosing the New York Federal Bank will allow conversion of a select 22 countries, which gets updated only once a day at noon, whereas the Yahoo conversion is real-time. "),
+  );
+
   $form['currency_api_watchdog'] = array(
     '#type' => 'checkbox',
     '#title' => t('Log all currency exchange requests and errors to watchdog'),    
@@ -80,13 +92,6 @@ function currency_api_admin_settings() {
  *    $result['time']   Time of the last update to the rates (Format is "h:mmpm")
  */
 function currency_api_convert($currency_from, $currency_to, $amount = 1) {
-  $currency_array = array(
-    's'  => 'Currencies',
-    'l1' => 'Last',
-    'd1' => 'Date',
-    't1' => 'Time'
-  );
-
   $result = array();
   $result['status']  = FALSE;
   $result['message'] = NULL;
@@ -97,8 +102,6 @@ function currency_api_convert($currency_
   $from = strtoupper($currency_from);
   $to   = strtoupper($currency_to);
 
-  $url = 'http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f='. currency_api_get_fields($currency_array) .'&s='. $from . $to .'=X';
-
   // Validate the passed currency codes, to make sure they are valid
   if (FALSE == currency_api_get_desc($from)) {
     $msg = "currency: Invalid currency_from=$from";
@@ -122,6 +125,60 @@ function currency_api_convert($currency_
     $result['status'] = FALSE;
   }
 
+  if (variable_get('currency_api_vendor', 'all') == 'nyfed') {
+    // NYFED uses VEF instead of VEB
+    if ('VEB' == $from) {
+      $from == 'VEF';
+    } elseif ('VEB' == $to) {
+      $to == 'VEF';
+    }
+    $curr_from_rate = 1;
+    $curr_to_rate = 1;
+    // New York Federal Bank noon rates, using PHP5 SOAP client
+    $soapClient = new SoapClient('http://www.newyorkfed.org/' .
+                  '/markets/fxrates/WebService/v1_0/FXWS.wsdl');
+
+    if ($from != 'USD' ) {
+      // Get rate of starting currency to USD
+      $xmlstr = $soapClient->getLatestNoonRate($from);
+      $xmlstr = str_replace('frbny:', 'frbny', $xmlstr);
+      $xml = new SimpleXMLElement($xmlstr);
+      $curr_rate = $xml->frbnyDataSet->frbnySeries->frbnyObs->frbnyOBS_VALUE;
+      if (('AUD' == $from) || (EUR == $from) || (NZD == $from) || (GBP == $from)) {
+        $curr_from_rate = bcdiv(1, $curr_rate, 5);
+      } else {
+        $curr_from_rate = $curr_rate;
+      }
+    }
+
+    if ($to != 'USD' ) {
+      // Get rate of ending currency from USD
+      $xmlstr = $soapClient->getLatestNoonRate($to);
+      $xmlstr = str_replace('frbny:', 'frbny', $xmlstr);
+      $xml = new SimpleXMLElement($xmlstr);
+      $curr_rate = $xml->frbnyDataSet->frbnySeries->frbnyObs->frbnyOBS_VALUE;
+      if (('AUD' == $to) || (EUR == $to) || (NZD == $to) || (GBP == $to)) {
+        $curr_to_rate = bcdiv(1, $curr_rate, 5);
+      } else {
+        $curr_to_rate = $curr_rate;
+      }
+    }
+    $result['status'] = TRUE;
+    $result['message'] = 'af';
+    $result['value'] = round($amount * bcdiv($curr_to_rate, $curr_from_rate, 5), 2);
+    # $result['date']   Date of the last update to the rates (Format is "m/d/yyyy")
+    $result['time'] = "12:00pm";
+    return $result;
+  }
+
+  $currency_array = array(
+    's'  => 'Currencies',
+    'l1' => 'Last',
+    'd1' => 'Date',
+    't1' => 'Time'
+  );
+
+  $url = 'http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f='. currency_api_get_fields($currency_array) .'&s='. $from . $to .'=X';
 
   if (($ch = @curl_init())) {
     $timeout = 5; // set to zero for no timeout
@@ -201,7 +258,39 @@ function currency_api_get_desc($currency
   return FALSE;
 }
 
+/**
+ * Obtain a vendor specific list of currencies available for conversion
+ */
 function currency_api_get_list() {
+  if (variable_get('currency_api_vendor', 'all') == 'nyfed') {
+    $currency = array(
+      'AUD' => t('Australian Dollar (AUD)'),
+      'BRL' => t('Brazilian Real (BRL)'),
+      'GBP' => t('British Pound (GBP)'),
+      'CAD' => t('Canadian Dollar (CAD)'),
+      'CNY' => t('Chinese Yuan (CNY)'),
+      'DKK' => t('Danish Krone (DKK)'),
+      'EUR' => t('Euro (EUR)'),
+      'HKD' => t('Hong Kong Dollar (HKD)'),
+      'INR' => t('Indian Rupee (INR)'),
+      'JPY' => t('Japanese Yen (JPY)'),
+      'KRW' => t('Korean Won (KRW)'),
+      'NZD' => t('New Zealand Dollar (NZD)'),
+      'MYR' => t('Malaysian Ringgit (MYR)'),
+      'MXN' => t('Mexican Peso (MXN)'),
+      'NOK' => t('Norwegian Krone (NOK)'),
+      'SGD' => t('Singapore Dollar (SGD)'),
+      'ZAR' => t('South African Rand (ZAR)'),
+      'LKR' => t('Sri Lanka Rupee (LKR)'),
+      'SEK' => t('Swedish Krona (SEK)'),
+      'CHF' => t('Swiss Franc (CHF)'),
+      'TWD' => t('Taiwan Dollar (TWD)'),
+      'USD' => t('U.S. Dollar (USD)'),
+      'VEB' => t('Venezuelan Bolivar/Frank (VEB)'),
+    );
+    return $currency;
+  }
+
   $currency = array(
     'AFN' => t('Afghanistani Afghani (AFA)'),
     'ALL' => t('Albanian Lek (ALL)'),
@@ -358,7 +447,7 @@ function currency_api_get_list() {
     'UYU' => t('Uruguayan New Peso (UYU)'),
     'UZS' => t('Uzbekistan Sum (UZS)'),
     'VUV' => t('Vanuatu Vatu (VUV)'),
-    'VEB' => t('Venezuelan Bolivar (VEB)'),
+    'VEB' => t('Venezuelan Bolivar/Frank (VEB)'),
     'VND' => t('Vietnam Dong (VND)'),
     'YER' => t('Yemen Riyal (YER)'),
     'YUM' => t('Yugoslav Dinar (YUM)'),
