From 24440d489d1888e5ec060560813e72b3d76562d7 Mon Sep 17 00:00:00 2001 From: Tommy Parnell Date: Sun, 28 Jun 2015 22:01:20 -0400 Subject: [PATCH] add final fantasy data --- src/AboutMe.Mvc.Web/AboutMe.Mvc.Web.csproj | 1 + src/AboutMe.Mvc.Web/App_Start/BundleConfig.cs | 5 +- src/AboutMe.Mvc.Web/Scripts/_references.js | Bin 1520 -> 1604 bytes src/AboutMe.Mvc.Web/Scripts/lodestoneapi.js | 150 ++++++++++++++++++ src/AboutMe.Mvc.Web/Scripts/main.js | 26 +++ 5 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 src/AboutMe.Mvc.Web/Scripts/lodestoneapi.js diff --git a/src/AboutMe.Mvc.Web/AboutMe.Mvc.Web.csproj b/src/AboutMe.Mvc.Web/AboutMe.Mvc.Web.csproj index b9fbb92..ab28b13 100644 --- a/src/AboutMe.Mvc.Web/AboutMe.Mvc.Web.csproj +++ b/src/AboutMe.Mvc.Web/AboutMe.Mvc.Web.csproj @@ -227,6 +227,7 @@ + main.js diff --git a/src/AboutMe.Mvc.Web/App_Start/BundleConfig.cs b/src/AboutMe.Mvc.Web/App_Start/BundleConfig.cs index 2b3bac7..550ed76 100644 --- a/src/AboutMe.Mvc.Web/App_Start/BundleConfig.cs +++ b/src/AboutMe.Mvc.Web/App_Start/BundleConfig.cs @@ -21,9 +21,10 @@ namespace AboutMe.Mvc.Web "~/Scripts/modernizr-*")); bundles.Add(new ScriptBundle("~/bundles/site").Include( - "~/Scripts/main.js", "~/Scripts/Mustache.js", - "~/Scripts/GithubActivity.js")); + "~/Scripts/GithubActivity.js", + "~/Scripts/lodestoneapi.js", + "~/Scripts/main.js")); bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/Scripts/bootstrap.js", diff --git a/src/AboutMe.Mvc.Web/Scripts/_references.js b/src/AboutMe.Mvc.Web/Scripts/_references.js index 5408a1e416642717f1463962a9b1fc9515019ab1..35fdcb68026064e4f1013d1c9e4a7cf41a630a4e 100644 GIT binary patch delta 39 scmeyseS~Mj2iD02j9TJ34EYQx45 requires jquery. + * -------------------------------------------------- + * API calls will match those of the PHP API, so for + * example, you can do: + * + * LodestoneAPI.Search.Character(Name, Server); + * LodestoneAPI.Search.Character(123456); + */ +var LodestoneAPI = +{ + logEnabled: false, + + paths: + { + sync: 'http://xivsync.com', + search: '/search/character', + character: '/character/get', + }, + + // Initialize + init: function() + { + LodestoneAPI.log('init()'); + + // check for jquery. + if (typeof window.jQuery == 'undefined') { + console.error('Please include https://jquery.com/, this API requires it.'); + } + }, + + // wrapper for ajaxing + get: function(url, data, callback) + { + LodestoneAPI.log('get', url); + LodestoneAPI.log('get', data); + + $.ajax({ + url: url, + data: data, + crossDomain: true, + dataType: 'json', + success: function(data) + { + LodestoneAPI.log('get > return', data); + if (data.ok) { + return callback(data.data); + } + + console.error('XIVSync API Error: '+ data.msg); + return callback(false); + }, + error: function(data, status, error) + { + console.error('Error attempting to ajax to: ' + url); + console.error(status); + console.error(error); + console.error('Please open an issue on Github: https://github.com/viion/XIVPads-LodestoneAPI'); + return callback(false); + }, + }) + }, + + // Logging + log: function(text, data) + { + if (LodestoneAPI.logEnabled) { + if (data) { + console.log('[LODESTONE-API]', text, data); + return; + } + + console.log('[LODESTONE-API]', text); + } + }, + + // Search for thingz + Search: + { + Character: function(nameOrId, server, callback, recurrsive) + { + if (!callback || typeof callback !== 'function') { + console.error('Callback function not defined.'); + return; + } + + if (!nameOrId) { + console.error('Name or ID is empty'); + return callback(false); + } + + // if numeric, can just get character + // else we have to search! + if ($.isNumeric(nameOrId)) + { + LodestoneAPI.log('search > character > isNumeric = true =', nameOrId); + + var url = LodestoneAPI.paths.sync + LodestoneAPI.paths.character, + data = { lodestone: nameOrId } + + LodestoneAPI.get(url, data, function(data) + { + // if empty + if (data.length == 0) { + return callback(false); + } + + return callback(data); + }); + } + else if (!recurrsive) + { + LodestoneAPI.log('search > character > isNumeric = false =', nameOrId); + + var url = LodestoneAPI.paths.sync + LodestoneAPI.paths.search, + data = { name: nameOrId, server: server } + + // get + LodestoneAPI.get(url, data, function(data) + { + // if empty + if (data.length == 0) { + return callback(false); + } + + + // Try match server and name + for (var i in data) + { + var c = data[i]; + if (c.name == nameOrId && c.world == server && $.isNumeric(c.i)); + { + // recurrsive callback on character using id + LodestoneAPI.log('search > character > recurrsion with id:', c.id); + LodestoneAPI.Search.Character(c.id, null, callback, true); + return; + } + } + + LodestoneAPI.log('search > character > no results for: ', nameOrId); + return callback(false); + }); + } + }, + }, +} +LodestoneAPI.init(); \ No newline at end of file diff --git a/src/AboutMe.Mvc.Web/Scripts/main.js b/src/AboutMe.Mvc.Web/Scripts/main.js index d2c4754..e1ccd77 100644 --- a/src/AboutMe.Mvc.Web/Scripts/main.js +++ b/src/AboutMe.Mvc.Web/Scripts/main.js @@ -49,4 +49,30 @@ jQuery(document).ready(function ($) { limit: 20 // optional }); + var buildFinalFantasy = function (data) { + return ""; + }; + + LodestoneAPI.Search.Character(8696200, null, function (data) { + if (data !== undefined && data !== null) { + $('.secondary').append(buildFinalFantasy(data)); + } + }); + + + });