{"size": 4420, "ext": "js", "max_stars_repo_path": "app/lib/webapi.js", "max_stars_repo_name": "brunocsbh/Pag-Mobile", "max_stars_repo_stars_event_min_datetime": "2020-05-27T21:44:19.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-27T21:44:19.000Z", "max_issues_repo_path": "app/lib/webapi.js", "max_issues_repo_name": "brunocsbh/Pag-Mobile", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/lib/webapi.js", "max_forks_repo_name": "brunocsbh/Pag-Mobile", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.0217391304, "max_line_length": 70, "alphanum_fraction": 0.6658371041}
function getConsumidorOLD(cb) {
	if (!Ti.Network.online) {
		cb({
			errorCode : Alloy.Globals.ErrorCodes.NoInternetConnection
		});
		return;
	}

	var xhr = Ti.Network.createHTTPClient({
		onload : function() {
			var statusCode = this.status;
			if (statusCode == 200) {
				var response = JSON.parse(this.responseText);
				cb(false, response);
			} else {
				cb({
					errorCode : Alloy.Globals.ErrorCodes.BadServerResponse
				});
			}
		},
		onerror : function(e) {
			cb({
				errorCode : Alloy.Globals.ErrorCodes.Unknown
			});
		}
	});
	xhr.enableKeepAlive = true;
	xhr.setTimeout = 5000;
	xhr.open('GET', 'http://pagws.herokuapp.com/api/consumidor');
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.send();
}

function getConsumidorSearch(search, cb) {
	if (!Ti.Network.online) {
		cb({
			errorCode : Alloy.Globals.ErrorCodes.NoInternetConnection
		});
		return;
	}

	var xhr = Ti.Network.createHTTPClient({
		onload : function() {
			var statusCode = this.status;
			if (statusCode == 200) {
				var response = JSON.parse(this.responseText);
				cb(false, response);
			} else {
				cb({
					errorCode : Alloy.Globals.ErrorCodes.BadServerResponse
				});
			}
		},
		onerror : function(e) {
			cb({
				errorCode : Alloy.Globals.ErrorCodes.Unknown
			});
		}
	});
	xhr.setTimeout = 5000;
	xhr.open('POST', 'http://pagws.herokuapp.com/api/consumidor/search');
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.setRequestHeader('Connection', 'close');
	xhr.send(JSON.stringify(search));
}

//------- CONSUMIDOR

function getConsumidor(cb) {
	if (!Ti.Network.online) {
		cb({
			errorCode : Alloy.Globals.ErrorCodes.NoInternetConnection
		});
		return;
	}

	var xhr = Ti.Network.createHTTPClient({
		onload : function() {
			var statusCode = this.status;
			if (statusCode == 200) {
				var response = JSON.parse(this.responseText);
				cb(false, response);
			} else {
				cb({
					errorCode : Alloy.Globals.ErrorCodes.BadServerResponse
				});
			}
		},
		onerror : function(e) {
			cb({
				errorCode : Alloy.Globals.ErrorCodes.Unknown
			});
		}
	});
	xhr.enableKeepAlive = true;
	xhr.setTimeout = 5000;
	xhr.open('GET', Alloy.Globals.WebApiBaseAddress + 'consumidor');
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.send();
}

function postConsumidor(consumidor, cb) {
	console.log('--->post consumidor!!!!!');
	if (!Ti.Network.online) {
		cb({
			errorCode : Alloy.Globals.ErrorCodes.NoInternetConnection
		});
		return;
	}

	var xhr = Ti.Network.createHTTPClient({
		onload : function() {
			var statusCode = this.status;
			if (statusCode == 200) {
				var response = JSON.parse(this.responseText);
				cb(false, response);
			} else {
				cb({
					errorCode : Alloy.Globals.ErrorCodes.BadServerResponse
				});
			}
		},
		onerror : function(e) {
			cb({
				errorCode : Alloy.Globals.ErrorCodes.Unknown
			});
		}
	});
	xhr.enableKeepAlive = true;
	xhr.setTimeout = 5000;
	xhr.open('POST', Alloy.Globals.WebApiBaseAddress + 'consumidor');

	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.setRequestHeader('Connection', 'close');
	xhr.send(JSON.stringify(consumidor));
}

//------- CARTAO DE CREDITO

function postCartao(tokenApp, cartao, cb) {
	console.log('--->post cartao!!!');
	console.log('p_tokenApp: ' + tokenApp);
	console.log('p_cartao: ' + cartao);
	if (!Ti.Network.online) {
		cb({
			errorCode : Alloy.Globals.ErrorCodes.NoInternetConnection
		});
		return;
	}

	var xhr = Ti.Network.createHTTPClient({
		onload : function() {
			var statusCode = this.status;
			if (statusCode == 200) {
				var response = JSON.parse(this.responseText);
				cb(false, response);
			} else {
				console.log('1: ' + this.status);
				cb({
					errorCode : Alloy.Globals.ErrorCodes.BadServerResponse
				});
			}
		},
		onerror : function(e) {
			console.log('2: ' + e.error);
			console.log('2.1: ' + this.responseText);
			cb(this.responseText);
		}
	});
	xhr.enableKeepAlive = true;
	xhr.setTimeout = 5000;
	xhr.open('POST', Alloy.Globals.WebApiBaseAddress + 'cartaocredito');

	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.setRequestHeader('consumidor_token', tokenApp);
	xhr.setRequestHeader('Connection', 'close');
	xhr.send(JSON.stringify(cartao));
}

exports.getConsumidor = getConsumidor;
exports.getConsumidorSearch = getConsumidorSearch;
exports.postConsumidor = postConsumidor;
exports.postCartao = postCartao;
