psn_request.js
function MakePSNRequest(method, url, fields, callback, token_fetch)
	{
		// use fields var as callback if it's missed out
		if (typeof fields == "function")
		{
			token_fetch = false;
			callback = fields;
			fields = {};
		}
		else if (typeof method == "function")
		{
			token_fetch = false;
			callback = method;
		}

		// parse stache fields in fields list
		for(var field_key in fields)
		{
			fields[field_key] = ParseStaches(fields[field_key]);
		}

		CheckTokens(function(error)
		{
			// check our tokens are fine
			if (!error)
			{
				// make PSN GET request
				URLGET(
					// parse URL for region etc.
					ParseStaches(url),
					fields,
					method,
					function(error, data)
					{
						if (error)
						{
							Log("PSN " + method + " Error: " + error);
							if (callback) callback(error);
							return;
						}

						if (data.error && (data.error.code === 2105858 || data.error.code === 2138626))
						{
							// access token has expired/failed/borked
							//  login again!
							Log("Access token failure, try to login again.");
							Login(function(error) {
								if (error)
								{
									if (callback) callback(error);
									return;
								}

								// call ourselves
								parent.Get(url, fields, callback, token_fetch);
							});
						}

						if (data.error && data.error.message)
						{
							// server error
							if (callback) callback(data.error.code + ": " + data.error.message, data.error);
							return;
						}

						// everything is fine! return data
						if (callback) callback(false, data);
					}
				);
			}
			else
			{
				Log("Token error: " + error);
				if (callback) callback(error);
				return;
			}
		}, token_fetch);
	}
function MakePSNRequest(method, url, fields, callback, token_fetch)
	{
		// use fields var as callback if it's missed out
		if (typeof fields == "function")
		{
			token_fetch = false;
			callback = fields;
			fields = {};
		}
		else if (typeof method == "function")
		{
			token_fetch = false;
			callback = method;
		}

		// parse stache fields in fields list
		for(var field_key in fields)
		{
			fields[field_key] = ParseStaches(fields[field_key]);
		}

		CheckTokens(function(error)
		{
			// check our tokens are fine
			if (!error)
			{
				// make PSN GET request
				URLGET(
					// parse URL for region etc.
					ParseStaches(url),
					fields,
					method,
					function(error, data)
					{
						if (error)
						{
							Log("PSN " + method + " Error: " + error);
							if (callback) callback(error);
							return;
						}

						if (data.error && (data.error.code === 2105858 || data.error.code === 2138626))
						{
							// access token has expired/failed/borked
							//  login again!
							Log("Access token failure, try to login again.");
							Login(function(error) {
								if (error)
								{
									if (callback) callback(error);
									return;
								}

								// call ourselves
								parent.Get(url, fields, callback, token_fetch);
							});
						}

						if (data.error && data.error.message)
						{
							// server error
							if (callback) callback(data.error.code + ": " + data.error.message, data.error);
							return;
						}

						// everything is fine! return data
						if (callback) callback(false, data);
					}
				);
			}
			else
			{
				Log("Token error: " + error);
				if (callback) callback(error);
				return;
			}
		}, token_fetch);
	}
function MakePSNRequest ( method , url , fields , callback , token_fetch ) { // use fields var as callback if it's missed out if ( typeof fields == "function" ) { token_fetch = false ; callback = fields ; fields = { } ; } else if ( typeof method == "function" ) { token_fetch = false ; callback = method ; } // parse stache fields in fields list for ( var field_key in fields ) { fields [ field_key ] = ParseStaches ( fields [ field_key ] ) ; } CheckTokens ( function ( error ) { // check our tokens are fine if ( ! error ) { // make PSN GET request URLGET ( // parse URL for region etc. ParseStaches ( url ) , fields , method , function ( error , data ) { if ( error ) { Log ( "PSN " + method + " Error: " + error ) ; if ( callback ) callback ( error ) ; return ; } if ( data . error && ( data . error . code === 2105858 || data . error . code === 2138626 ) ) { // access token has expired/failed/borked //  login again! Log ( "Access token failure, try to login again." ) ; Login ( function ( error ) { if ( error ) { if ( callback ) callback ( error ) ; return ; } // call ourselves parent . Get ( url , fields , callback , token_fetch ) ; } ) ; } if ( data . error && data . error . message ) { // server error if ( callback ) callback ( data . error . code + ": " + data . error . message , data . error ) ; return ; } // everything is fine! return data if ( callback ) callback ( false , data ) ; } ) ; } else { Log ( "Token error: " + error ) ; if ( callback ) callback ( error ) ; return ; } } , token_fetch ) ; }
Make a PSN request
Make a PSN request