// LGI TV Guide JS SDK // ---------------------------------- // v0.4.8 // // Copyright (c) 2015 Liberty Global // Distributed under BSD license !function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define(b):(a.LGI={},a.LGI.Guide=b())}(this,function(){function a(){this.initialRequestURL="",this.nextBatchLink=""}function b(a){this._name=a}function c(a){b.call(this,a)}function d(a){b.call(this,a)}function e(a,c){b.call(this,a),this.prefixString=c}function f(a,c){b.call(this,a),this.prefixString=c}function g(a){this.items=[],"undefined"!=typeof a&&this.add(a)}function h(){g.call(this),this.filters=[],this._queryModificationActions=[],this._requestURL="",this._request=new a}var i={};i.Guide={},i.Guide.config={APIURL:"http://api.lgi.io/kraken/v2/schedule/",region:"",authId:"dc573c37",authKey:"f4521ced0cb9af73374731a77b2f21f6"},i.Guide.utils={addFactory:function(a){a.create=function(){return new a}}};var j=function(){function a(){}function b(b,c,d){var e=new XMLHttpRequest;"function"!=typeof c&&(c=a),"function"!=typeof d&&(d=a),e.open("GET",b,!0),e.setRequestHeader("X-Auth-Id",i.Guide.config.authId),e.setRequestHeader("X-Auth-Key",i.Guide.config.authKey),e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status)try{var a=JSON.parse(e.responseText);c(a)}catch(b){d(new Error(["Invalid JSON response","("+b.message+")"].join(" ")))}else d(new Error(["Unexpected server response","(status="+e.status+",","statusText="+e.statusText+")"].join(" ")))};try{e.send(null)}catch(f){d(f.description)}}return b},k=function(){function a(a,b,c){-1===a.indexOf("http:")&&(a="http:"+a);var d=require("http"),e=require("url"),f=e.parse(a,!0),g={host:f.hostname,port:80,method:"GET",path:f.path},h=d.request(g,function(a){a.on("data",function(a){b(JSON.parse(a))})});h.end(),h.on("error",function(b){c?c(b):console.warn("KrakenSDK: Error during request to "+a)})}return a},l=function(){return"undefined"!=typeof module&&module.exports?k():j()},m=l();return a.prototype.execute=function(a,b,c,d){var e=[];this.initialRequestURL=a,m(a,this.createScopedCallback(b,c,e),d)},a.prototype.proceedResponse=function(a,b,c,d){c=c.concat(a.data),a.nextBatchLink?this.nextBatchLink=a.nextBatchLink.href:this.nextBatchLink=void 0,void 0!==b&&b--,(b>0||void 0===b)&&void 0!==this.nextBatchLink&&this.nextBatchLink?m(this.nextBatchLink,this.createScopedCallback(d,b,c)):void 0!==d&&d.bind(this)(c,a)},a.prototype.createScopedCallback=function(a,b,c){var d=function(d){this.proceedResponse(d,b,c,a)};return d.bind(this)},b.prototype.toString=function(){return this._name},b.prototype._getStringForOperation=function(a,b){return this._name+a+b},b.prototype._getURLModificationObject=function(a,b){var c={};return c.stringValue=b,c.context=this,c.actionFunction=a,c},c.prototype=Object.create(b.prototype),c.prototype.equalTo=function(a){return this._getStringForOperation("=",a)},c.prototype.greaterThan=function(a){return this._getStringForOperation(">",a)},c.prototype.greaterThanOrEqualTo=function(a){return this._getStringForOperation(">=",a)},c.prototype.lessThan=function(a){return this._getStringForOperation("<",a)},c.prototype.lessThanOrEqualTo=function(a){return this._getStringForOperation("<=",a)},d.prototype=Object.create(b.prototype),d.prototype.equalTo=function(a){return this._getStringForOperation("=",a)},d.prototype.isMatching=function(a){return this._getStringForOperation("~",a)},e.prototype=Object.create(b.prototype),e.prototype.equalTo=function(a){return this._getURLModificationObject(this._modifyURL,a)},e.prototype._modifyURL=function(a,b){var c=a.lastIndexOf("/"),d="/"+this.prefixString+"/"+b;return a=a.substr(0,c)+d+a.substr(c)},f.prototype=Object.create(b.prototype),f.prototype.equalTo=function(a){return this._getURLModificationObject(this._modifyURL,a)},f.prototype._modifyURL=function(a,b){var c=-1!==a.indexOf("?")?a.indexOf("?"):a.length,d=a.substring(0,c),e=a.substring(0,d.lastIndexOf("/")),f="/"+this.prefixString+"/"+b+".json";return a.replace(d,e+f)},g.prototype.each=function(a){this.items.forEach(a)},g.prototype.where=function(a){var b=Object.keys(a);return this.items.filter(function(c){return b.every(function(b){return c.hasOwnProperty(b)&&c[b]===a[b]})})},g.prototype.add=function(a){"[object Array]"===Object.prototype.toString.call(a)?this.items=this.items.concat(a):this.items.push(a)},g.prototype.get=function(a){return this.items[a]},g.prototype.toArray=function(){return this.items.slice(0)},g.prototype.reset=function(){return this.items=[],this.items},h.prototype=Object.create(g.prototype),h.prototype.limit=function(a){return this._addURLModification("limit="+a),this},h.prototype.fields=function(a){return this._addURLModification("fields="+Array.prototype.slice.call(arguments).join(",")),this},h.prototype.sort=function(a,b){if(("undefined"==typeof b||null===b)&&(b="asc"),"asc"!==b&&"desc"!==b)throw new Error('Invalid sort option, expecting "asc" or "desc"');return this._addURLModification("sort="+a+"("+b+")"),this},h.prototype.filter=function(a){for(var b=0;b