function AmazonClient(e,t,n,r,i){function h(){s=e,o=t,u=null,f="https://music-api.amazon.com/",_defaultCertTestBaseUrl=f+"sandbox/",a=f,l="",c=n}function p(e){u=e}function d(e){l=e}function v(){a=_defaultCertTestBaseUrl}function m(e){e?a=e:a=f}function g(e,t,n){var r=a+"availability/?country="+encodeURIComponent(t),i={header:undefined,requests:[]};i.header={metaData:n,source:o,responseMessageType:e},i.requests[0]={url:r,method:"GET",cache:!0,dataType:"json"},s.apiFetch(i)}function y(e,t,n,r,o,f){o===undefined&&(o=AmazonWorker.Constants.MAX_REDIRECTS),f===undefined&&(f=AmazonWorker.Constants.MAX_RETRIES),r===undefined&&(r=!0);if(u===null&&r){var c=function(){y(e,t,n,!1,o,f)};s.consoleLog("Requesting access token for this account for the first time since app loading."),w(c,n);return}var h=[],p=S(a,e),d={Authorization:"Bearer "+u,"X-Amz-Music-Site":l,"X-Amz-Workaround":"redirect","Accept-Language":i,"X-Amz-Music-Images-Shrink":"*=150x150"};h.push({url:p,method:"GET",cache:!0,headers:d,dataType:"json"}),s.urlFetch(h,function(i){b(i,e,t,n,r,o,f)})}function b(e,t,n,r,i,o,u){if(o>0&&e.length>0&&e[0]){var a=e[0].getResponseHeader("X-Amz-Redirect-Status"),f=e[0].getResponseHeader("X-Amz-Redirect-Location");if(a){var l=parseInt(a.toString().substr(0,3));if(f&&(l===AmazonWorker.ResponseMessageCode.MOVED_PERMANENTLY||l===AmazonWorker.ResponseMessageCode.SEE_OTHER||l===AmazonWorker.ResponseMessageCode.MOVED_TEMPORARILY)){t=t.replace(/\#.*$/,""),t=x(f,t),y(t,n,r,i,o-1,u);return}}}var c={responses:e},h=new AmazonAPIResponseValidator(s,c),p=h.getValidationResults(c);if(p.valid){n(t,e);return}s.consoleLog("Received error "+e[0].status);if(!i||e[0].status!==AmazonWorker.ResponseMessageCode.UNAUTHORIZED&&e[0].status!==AmazonWorker.ResponseMessageCode.FORBIDDEN){if(e[0].status===AmazonWorker.ResponseMessageCode.INTERNAL_SERVER_ERROR&&u>0){s.consoleLog("Received error 500: Remaining retries: "+u),y(t,n,r,i,o,u-1);return}r.call(null,{errorCode:p.errorCode,errorName:p.errorName,errorText:"("+p.errorCodeFromAPI+"): "+p.errorMessageFromAPI,customError:p.customError});return}s.consoleLog("Requesting access token on error:"+e[0].status);var d=function(){y(t,n,r,!1,o,u)};w(d,r);return}function w(e,t){var n=function(n){E(n,e,t)};r.requestAccessToken("",c,"",{},n)}function E(e,t,n){var r=new AmazonAPIResponseValidator(s,{responses:e}),i=r.getValidationResults();r.isValid()?(u=e[0].responseJSON.access_token,t()):n(i)}function S(e,t){return e===null&&(e=a),t||(t=""),t.match(/^http[s]?:\/\//)?t:e+t}function x(e,t){return e?e.match(/^http[s]?:\/\//)?e:t+e:url}this.setAccessToken=p,this.setSiteId=d,this.setBaseUrl=m,this.retrieveServiceAvailability=g,this.switchToSandbox=v,this.retrieveNodes=y,this.requestAccessToken=w,this.getAbsoluteUrl=S;var s,o,u,a,f,l,c;h()};