diff --git a/stockapi.api.php b/stockapi.api.php new file mode 100644 index 0000000..6aebc8e --- /dev/null +++ b/stockapi.api.php @@ -0,0 +1,33 @@ +@print_r', array('@print_r' => print_r( $url, TRUE))); $page = file_get_contents($url); @@ -110,8 +110,7 @@ function stockapi_fetch($symbols) { if ($stock_market == 'NASDAQ') { $stock_market = 'TSE'; } - $url = "http://finance.google.ca/?q=" . $stock_market . ':' . - $stock_symbol;// . '&' . uniqid() . '=' . rand(); + $url = stockapi_google_finance_url($stock_market, $stock_symbol);// . '&' . uniqid() . '=' . rand(); $page = file_get_contents($url); $internalErrors = libxml_use_internal_errors(true); // set error level @@ -123,8 +122,7 @@ function stockapi_fetch($symbols) { if ($stock_market == 'NYSE') { $stock_market = 'NASDAQ'; } - $url = "http://finance.google.ca/?q=" . $stock_market . ':' . - $stock_symbol;// . '&' . uniqid() . '=' . rand(); + $url = stockapi_google_finance_url($stock_market, $stock_symbol);// . '&' . uniqid() . '=' . rand(); $page = file_get_contents($url); $internalErrors = libxml_use_internal_errors(true); // set error level @@ -135,8 +133,7 @@ function stockapi_fetch($symbols) { if ($stock_market == 'NASDAQ') { $stock_market = 'NYSE'; } - $url = "http://finance.google.ca/?q=" . $stock_market . ':' . - $stock_symbol;// . '&' . uniqid() . '=' . rand(); + $url = stockapi_google_finance_url($stock_market, $stock_symbol);// . '&' . uniqid() . '=' . rand(); $page = file_get_contents($url); $internalErrors = libxml_use_internal_errors(true); // set error level @@ -424,6 +421,30 @@ function stockapi_fetch($symbols) { } } +/** + * Generate Google Finance page URL. + * + * @param string $stock_market + * Stock market name, i.e. 'NASDAQ' or 'TSE'. + * @param string $stock_symbol + * Stock symbol. + * + * @return string + * Google finance URL for given stock market and symbol. + */ +function stockapi_google_finance_url($stock_market, $stock_symbol) { + $host = 'http://finance.google.ca/'; + $options = array( + 'query' => array( + 'q' => $stock_market . ':' . $stock_symbol, + ), + ); + + drupal_alter('stockapi_google_finance_query', $host, $options, $stock_market, $stock_symbol); + + return url($host, $options); +} + function _stockapi_money_to_float($money_string) { $money_string = trim($money_string); $idx_of_scale = strlen($money_string);