<commit_before>YUI.add('Twitter', function(Y) {

	Y.Twitter = {
		call : function(request, callback, where, context) {
			
			var Tweets 	= [];
			var yql 	= false;
			
			if (request.type == "timeline") {
				switch(request.timeline) {
					case "home":
						yql = 'SELECT * FROM twitter.status.timeline.friends 	WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					case "sent":
						yql = 'SELECT * FROM twitter.status.timeline.user 		WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					case "dmin":	
						yql = 'SELECT * FROM twitter.directmessages 			WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					case "dmout":	
						yql = 'SELECT * FROM twitter.directmessages.sent 		WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					default:
						throw("Invalid Twitter API method");
						break;
				}
				
			} else {
				yql = 'SELECT * FROM twitter.search WHERE ' + where.field + ' = ' + where.value + ' AND q="' + (request.query) + '";';
			}
			
			if (yql) {
				YQL(yql, {
					on: {
						start: function(){ /* nothing */ },
						complete: function(id, response, args){
							var rawTweets = []
							var response = Y.JSON.parse(response.responseText);
							
							if (response.error) {
								errorHandler(response.error);
							} else {
								if(response.results)
								{
									if (response.results.results) {
										rawTweets = response.results.results;
									}
									else if (response.results["direct-messages"]) {
										rawTweets = response.results["direct-messages"]["direct_message"];
									}
									else {
										rawTweets = response.results.statuses.status;
									}	
									
									if (!rawTweets.reverse) { // Test to see if it is an array
										rawTweets = [rawTweets]; // No? Make it one.
									}
							
									for (var i in rawTweets) { 
										Tweet = Object.create(Y.Tweet);
										Tweet.init(rawTweets[i]);
										Tweets.push(Tweet);
									}
							
									callback(Tweets, context);
								}
							}
						},
						end: function(){ /* nothing */ },
					}
				});
			}
			else {
				throw("No YQL defined");
			}
		}
	}; // End of Twitter

	// Helpers
	function YQL(yql, params){
		params.method 	= "GET";
		params.data 	= "yql=" + escape(yql);
		Y.io("yql.php", params);
	}

}, '0.0.1', { requires: ['io-base'] });<commit_msg>Better handling of various responses from Twitter<commit_after>YUI.add('Twitter', function(Y) {

	Y.Twitter = {
		call : function(request, callback, where, context) {
			
			var Tweets 	= [];
			var yql 	= false;
			
			if (request.type == "timeline") {
				switch(request.timeline) {
					case "home":
						yql = 'SELECT * FROM twitter.status.timeline.friends 	WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					case "sent":
						yql = 'SELECT * FROM twitter.status.timeline.user 		WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					case "dmin":	
						yql = 'SELECT * FROM twitter.directmessages 			WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					case "dmout":	
						yql = 'SELECT * FROM twitter.directmessages.sent 		WHERE ' + where.field + ' = ' + where.value + ' AND #oauth#;';
						break;

					default:
						throw("Invalid Twitter API method");
						break;
				}
			}
			else if (request.type == "search") {
				yql = 'SELECT * FROM twitter.search WHERE ' + where.field + ' = ' + where.value + ' AND q="' + (request.timeline) + '";';
			}
			else {
				throw("Unknown request type");
			}
			
			if (yql) {
				YQL(yql, {
					on: {
						start: function(){ /* nothing */ },
						complete: function(id, response, args){
							var Tweets 		= [];
							var rawTweets	= [];
							var response 	= Y.JSON.parse(response.responseText);
							
							if (response.error) {
								errorHandler(response.error);
							} 
							else {
								if(response.results) {
									if (response.results.results) {
										rawTweets = response.results.results;
									}
									else if (response.results["direct-messages"]) {
										rawTweets = response.results["direct-messages"]["direct_message"];
									}
									else {
										rawTweets = response.results.statuses.status;
									}	
									
									if (!rawTweets.reverse) { // Test to see if it is an array
										rawTweets = [rawTweets]; // No? Make it one.
									}
							
									for (var i in rawTweets) { 
										Tweet = Object.create(Y.Tweet);
										Tweet.init(rawTweets[i]);
										Tweets.push(Tweet);
									}
							
								}
								callback(Tweets, context);
							}
						},
						end: function(){ /* nothing */ },
					}
				});
			}
			else {
				throw("No YQL defined");
			}
		}
	}; // End of Twitter

	// Helpers
	function YQL(yql, params){
		params.method 	= "GET";
		params.data 	= "yql=" + escape(yql);
		Y.io("yql.php", params);
	}

}, '0.0.1', { requires: ['io-base'] });
{'fraction_non_alphanumeric': 0.15606361829025844, 'fraction_numerical': 0.0011928429423459245, 'mean_word_length': 1.8864027538726333, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1032065', 'n_tokens_mistral': 2490, 'n_tokens_neox': 1656, 'n_words': 347}