lib/yquotes/yahoo.rb in yquotes-0.1.9 vs lib/yquotes/yahoo.rb in yquotes-1.1.0

- old
+ new

@@ -61,11 +61,11 @@ # build_params: build parameters for get query def build_url(ticker, start_date=nil, end_date=nil, period='d') url = QUOTE_ENDPOINT - url = url %{:symbol => URI.escape(ticker).upcase} + url = url %{:symbol => URI.escape(ticker.upcase)} params = { :crumb => URI.escape(@crumb), :events => 'history', :interval => '1d' @@ -75,22 +75,23 @@ params[:period1] = get_date(start_date).to_i unless start_date.nil? params[:period2] = get_date(end_date).to_i unless end_date.nil? params[:interval] = "1d" if period == "d" params[:interval] = "1mo" if period == "m" + params[:interval] = "1wk" if period == "w" url + "#{params.map { |k,v| "#{k}=#{v}" }.join("&")}" end # get_date: get date from String def get_date(d) return nil if d.nil? - return d.to_time if d.is_a? Date + return d.to_time if d.is_a? DateTime if d.is_a? String begin - dt = Date.parse(d).to_time + dt = DateTime.parse(d).to_time rescue Exception => e raise "invalid param #{d} - date should be in yyyy-mm-dd format" end end end \ No newline at end of file