-
Notifications
You must be signed in to change notification settings - Fork 141
Fix for the sketchy Yahoo API #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,7 +89,7 @@ function addreloader(mule, target) { | |
| var rld = $('<div class="button">') | ||
| rld.text('\u21bb') | ||
| if (mule.data) { | ||
| var updated = new Date(mule.data.query.created) | ||
| var updated = new Date(mule.data.created) | ||
| rld.attr('title', 'last updated: ' + updated.toLocaleString()) | ||
| } | ||
| rld.click(function(){ mule.reload() }) | ||
|
|
@@ -224,7 +224,11 @@ Mule.prototype.query = function(ignore_cache) { | |
|
|
||
| this.log('loading data') | ||
| window.realmAPI('char/list', CR, function(xhr) { | ||
| xhr.done(onResponse).fail(onFail) | ||
| if(xhr.Chars){ | ||
| onResponse(xhr); | ||
| } else { | ||
| onFail(); | ||
| } | ||
| }) | ||
|
|
||
| function onFail() { | ||
|
|
@@ -239,15 +243,9 @@ Mule.prototype.query = function(ignore_cache) { | |
| } | ||
|
|
||
| function onResponse(data) { | ||
| //console.log(data); | ||
| self.busy = false; | ||
| if (!data.query || !data.query.results) { | ||
| self.error(data.query ? 'server error' : 'YQL service denied'); | ||
| if (data.query) { | ||
| self.log('full response:' + JSON.stringify(data.query)) | ||
| } | ||
| return; | ||
| } | ||
| var res = data.query.results | ||
| var res = data; | ||
|
|
||
| function watchProgress(percent) { | ||
| if (typeof percent != 'string') { | ||
|
|
@@ -309,13 +307,22 @@ var STATTAGS = 'MaxHitPoints MaxMagicPoints Attack Defense Speed Dexterity HpReg | |
| var STATABBR = 'HP MP ATT DEF SPD DEX VIT WIS'.split(' ') | ||
| Mule.prototype.parse = function(data) { | ||
| if (this.overlay) this.overlay.hide() | ||
|
|
||
| var d = data.query.results.Chars | ||
| console.log(data); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no |
||
| if(data.Chars){ | ||
| var d = data.Chars | ||
| } else { | ||
| var d = data.query.results.Chars | ||
| } | ||
| d = { | ||
| Char: d.Char, | ||
| Account: d.Account || {} | ||
| } | ||
| data.query.results.Chars = d | ||
| if(data.Chars){ | ||
| data.Chars = d | ||
| } else { | ||
| data.query.results.Chars = d | ||
| } | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These switches are presumably for compatibility with yql? If you intend to have it as a fallback, actually do it. |
||
|
|
||
| // check if data changed? | ||
| /* if (this.data && compare(d, this.data.query.results.Chars)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of the whitespace changes are uncalled for. also use tabs for indentation (in all the other places) |
||
| (function($, window) { | ||
|
|
||
| var BASEURL = [ | ||
|
|
@@ -27,11 +28,10 @@ function update_counter() { | |
| $('#counter').text(_cnt).parent().toggle(!!_cnt); | ||
| } | ||
|
|
||
|
|
||
| var x2js = new X2JS(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where this is coming from |
||
| function realmAPI(path, opts, extraopts, callback) { | ||
| opts.ignore = Math.floor(1e3 + 9e3 * Math.random()) | ||
| var url = BASEURL + path + '?' + $.param(opts) | ||
|
|
||
| if (typeof extraopts == 'function') { | ||
| callback = extraopts | ||
| extraopts = {} | ||
|
|
@@ -48,15 +48,27 @@ function realmAPI(path, opts, extraopts, callback) { | |
| ifr.src = url | ||
| return | ||
| } | ||
|
|
||
| /* | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't leave commented code, version control exists for a reason |
||
| queue_request({ | ||
| dataType: 'jsonp', | ||
| url: 'https://query.yahooapis.com/v1/public/yql', | ||
| data: { | ||
| q: 'select * from xml where url="' + url + '"', | ||
| format: 'json' | ||
| }, | ||
| complete: callback | ||
| complete: function(result){ | ||
| console.log(JSON.stringify(result)); | ||
| callback(result); | ||
| } | ||
| }) | ||
| */ | ||
| queue_request({ | ||
| url: 'https://cors-anywhere.herokuapp.com/' + url, | ||
| complete: function(result){ | ||
| var jsonResult = x2js.xml_str2json(result.responseText); | ||
| //console.log(JSON.stringify(jsonResult)); | ||
| callback(jsonResult); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you changed the type of the argument that is passed to callback (it used to be the xhr object) and didn't fix all instances where this function is used (namely the |
||
| } | ||
| }) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
queryobject and it'screatedproperty are inherent to the yql api. With your changes this is same asnew Date()which is not correct if loading from cache. You need to set this timestamp yourself after updating.