using coinbase with uc_bitcoin drupal module I need a simple hack to change the Drupal uc_bitcoin modules code so it gets the exchange rate from Coinbase, it is designed to use MtGox. I want to avoid using the entire coinbase API because I just want the exchange rate, not the kitchen sink. There is a lot of documentation there.

I have found the code in the uc_bitcoin drupal module which gets the information from MtGox. It needs some simple changes so it gets this data from Coinbase. Since both are so different, and I'm not fluent with PHP I thought someone might be able to help me with this.

Here is the code which gets the exchange rate from MtGox:

function uc_bitcoin_exchange_rate($order) {

  static $rate;

  if(isset($rate)) {
    return $rate;
  }

  if ($order-&gt;currency == 'BTC') {
    // BTC 1:1
    return 1;
  }

  // Supported MtGox currencies, Dec 15 2012
  $mtGox_currencies = array(
    'USD',
    'EUR',
    'JPY',
    'CAD',
    'GBP',
    'CHF',
    'RUB',
    'AUD',
    'SEK',
    'DKK',
    'HKD',
    'PLN',
    'CNY',
    'SGD',
    'THB',
    'NZD',
    'NOK'
  );

  // @todo add cache
  if (in_array($order-&gt;currency, $mtGox_currencies)) {
    if ($response = drupal_http_request('https://data.mtgox.com/api/1/BTC' . $order-&gt;currency . '/ticker')) { 
      if ($response-&gt;code == 200) {
        $data = json_decode($response-&gt;data);
        if(!empty($data-&gt;return-&gt;avg-&gt;value)) {
          $rate = $data-&gt;return-&gt;avg-&gt;value;
        }
      }
    }
  }

// @todo add cache
  if (in_array($order-&gt;currency, $mtGox_currencies)) {
    if ($response = drupal_http_request('https://data.mtgox.com/api/1/BTC' . $order-&gt;currency . '/ticker')) { 
      if ($response-&gt;code == 200) {
        $data = json_decode($response-&gt;data);
        if(!empty($data-&gt;return-&gt;avg-&gt;value)) {
          $rate = $data-&gt;return-&gt;avg-&gt;value;
        }
      }
    }
  }

  if (!$rate || !is_numeric($rate)) {
    watchdog('uc_bitcoin', 'MtGox lookup - Unable to get current exchange rate', WATCHDOG_ERROR);
    $rate = FALSE; // just to be super sure.
  }

  return $rate;
}
I'm not terribly familiar with drupal, and I've never used the module you're talking about, but I'll take a shot at it:

function uc_bitcoin_exchange_rate($order) {
  static $data;
  $rate = FALSE;
  $currency = $order-&gt;currency;
  $currency_code = 'btc_to_' . strtolower($currency);

  if ($currency == 'BTC') {
    // BTC 1:1
    return 1;
  }
  if (!isset($data) {
    if ($response = drupal_http_request('https://api.coinbase.com/v1/currencies/exchange_rates')) {
      if ($response-&gt;code == 200) {
        $data = json_decode($response-&gt;data);
        $rate = $data[$currency_code];
      }
    }
  }

  if (!is_numeric($rate)) {
    watchdog('uc_bitcoin', 'CoinBase lookup - Unable to get current exchange rate', WATCHDOG_ERROR);
    $rate = FALSE; // just to be super sure.
  }

  return $rate;
}