angular.module('stocks.services', [])

	.factory('stockDataService', function($q, $http){

		var getDetailsData = function(ticker){

			var deffered = $q.defer(),
			url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20IN%20(%22" + ticker + "%22)&format=json&env=http://datatables.org/alltables.env";
			
			$http.get(url)
    		.success(function(json){
		    	var jsonData = json.query.results.quote;
		    	//console.log(json);
		    	deffered.resolve(jsonData);
			})
			.error(function(error){
				console.log("Details data error: " + error);
				deffered.reject();
			});

			return deffered.promise;

		};

		var getPriceData = function(ticker){

			//console.log(ticker);

			var deffered = $q.defer(),
			url = "http://finance.yahoo.com/webservice/v1/symbols/" + ticker + "/quote?format=json&view=detail";

			$http.get(url)
    		.success(function(json){
		    	var jsonData = json.list.resources[0].resource.fields;
		    	deffered.resolve(jsonData);
			})
			.error(function(error){
				console.log("Price data error: " + error);
				deffered.reject();
			});

			return deffered.promise;

		};

		return {
			getPriceData: getPriceData,
			getDetailsData: getDetailsData
		};

	});
@@ -32,16 +32,228 @@
 ', %5B%5D)%0A%0A
+%09.factory('encodeURIService', function()%7B%0A%0A%09%09return%7B%0A%09%09%09encode: function(string) %7B%0A%09%09%09    return encodeURIComponent(string).replace(/%5C%22/g, %22%2522%22).replace(/%5C /g, %22%2520%22).replace(/%5B!'()%5D/g, escape);%0A%09%09%09%7D%0A%09%09%7D;%0A%0A%09%7D)%0A%0A
 %09.factor
@@ -292,16 +292,34 @@
 q, $http
+, encodeURIService
 )%7B%0A%0A%09%09va
@@ -393,78 +393,31 @@
 %0A%09%09%09
-url = %22http://query.yahooapis.com/v1/public/yql?q=select%2520*%2520
+query = 'select * 
 from
-%2520
+ 
 yaho
@@ -436,55 +436,140 @@
 otes
-%2520
+ 
 where
-%2520
+ 
 symbol
-%2520IN%2520(%2522%22 + ticker + %22%2522)
+ IN (%22' + ticker + '%22)',%0A%09%09    url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIService.encode(query) + '
 &for
@@ -616,17 +616,17 @@
 bles.env
-%22
+'
 ;%0A%09%09%09%0A%09%09

add encodeURIService