diff --git a/src/js/api/index.js b/src/js/api/index.js index 527b8c4b6..384841560 100644 --- a/src/js/api/index.js +++ b/src/js/api/index.js @@ -1,7 +1,9 @@ +const locale = require("./locale"); const oauth = require("./oauth"); const order = require("./order"); const size = require("./size"); +Object.assign(module.exports, locale); Object.assign(module.exports, oauth); Object.assign(module.exports, order); Object.assign(module.exports, size); diff --git a/src/js/api/locale.js b/src/js/api/locale.js new file mode 100644 index 000000000..a6f55f745 --- /dev/null +++ b/src/js/api/locale.js @@ -0,0 +1,27 @@ +if (typeof require !== "undefined") { + // eslint-disable-next-line no-redeclare + var base = require("../base"); + // eslint-disable-next-line no-redeclare + var ripe = base.ripe; +} + +ripe.Ripe.prototype.locale = function(value, locale, options, callback) { + return this.localeMultiple(value, locale, options, callback); +}; + +ripe.Ripe.prototype.localeMultiple = function(values, locale, options, callback) { + values = typeof values === "string" ? [values] : values; + callback = typeof options === "function" ? options : callback; + options = typeof options === "function" ? {} : options; + var url = this.url + "locale"; + options = Object.assign(options, { + url: url, + method: "GET", + params: { + values: values, + locale: locale + } + }); + options = this._build(options); + return this._cacheURL(options.url, options, callback); +}; diff --git a/src/js/main.join.json b/src/js/main.join.json index 55dbf7d79..168ec396f 100644 --- a/src/js/main.join.json +++ b/src/js/main.join.json @@ -10,6 +10,7 @@ "base/utils.js", "base/api.js", "base/auth.js", + "api/locale.js", "api/oauth.js", "api/order.js", "api/size.js", @@ -32,6 +33,7 @@ "base/utils.js", "base/api.js", "base/auth.js", + "api/locale.js", "api/oauth.js", "api/order.js", "api/size.js", diff --git a/src/js/ripe-min.js b/src/js/ripe-min.js index 8d56161de..878bb4549 100644 --- a/src/js/ripe-min.js +++ b/src/js/ripe-min.js @@ -80,6 +80,7 @@ if(options.force){this.unauth();} var query=window.location.search||"";var unpacked=this._unpackQuery(query);var code=typeof options.code==="undefined"?unpacked.code:options.code;var clientId=options.clientId||localStorage.getItem("oauth_client_id");var clientSecret=options.clientSecret||localStorage.getItem("oauth_client_secret");var redirectUri=options.redirectUri||localStorage.getItem("oauth_redirect_uri");var scope=options.scope||(localStorage.getItem("oauth_scope")||"").split(",")||[];var oauthToken=options.oauthToken||localStorage.getItem("oauth_token");scope&&localStorage.setItem("oauth_scope",scope.join(","));if(oauthToken&&clientId&&clientSecret&&redirectUri){return this.oauthLogin(oauthToken,options,function(result,isValid){if(isValid&&result){this.sid=result.sid;this.trigger("auth");callback&&callback(result);}else{this.oauth({clientId:clientId,clientSecret:clientSecret,redirectUri:redirectUri,scope:scope,code:null,force:true},callback);}}.bind(this));} if(code&&clientId&&clientSecret&&redirectUri){return this.oauthAccessToken(code,{clientId:clientId,clientSecret:clientSecret,redirectUri:redirectUri},function(result,isValid){if(isValid&&result){localStorage.setItem("oauth_token",result.access_token);result.scope&&localStorage.setItem("oauth_scope",result.scope.join(","));this.oauth(callback);}else{this.oauth({clientId:clientId,clientSecret:clientSecret,redirectUri:redirectUri,scope:scope,code:null,force:true},callback);}}.bind(this));} return this.oauthRedirect(options,callback);};ripe.Ripe.prototype.oauthRedirect=function(options,callback){var location=window.location;var currentUrl=location.protocol+"//"+location.host+"/"+location.pathname.split("/")[1];var clientId=options.clientId||this.clientId;var clientSecret=options.clientSecret||this.clientSecret;var redirectUri=options.redirectUri||currentUrl;localStorage.setItem("oauth_client_id",clientId);localStorage.setItem("oauth_client_secret",clientSecret);localStorage.setItem("oauth_redirect_uri",redirectUri);var url=this.webUrl+"admin/oauth/authorize";var params={client_id:clientId,redirect_uri:redirectUri,response_type:options.responseType||"code",scope:(options.scope||[]).join(" ")};var data=this._buildQuery(params);url=url+"?"+data;document.location=url;};if(typeof require!=="undefined"){var base=require("../base");var ripe=base.ripe;} +ripe.Ripe.prototype.locale=function(value,locale,options,callback){return this.localeMultiple(value,locale,options,callback);};ripe.Ripe.prototype.localeMultiple=function(values,locale,options,callback){values=typeof values==="string"?[values]:values;callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"locale";options=Object.assign(options,{url:url,method:"GET",params:{values:values,locale:locale}});options=this._build(options);return this._cacheURL(options.url,options,callback);};if(typeof require!=="undefined"){var base=require("../base");var ripe=base.ripe;} ripe.Ripe.prototype.oauthAccessToken=function(code,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"admin/oauth/access_token";options=Object.assign(options,{url:url,method:"POST",params:{code:code,client_id:options.clientId||this.clientId,client_secret:options.clientSecret||this.clientSecret,redirect_uri:options.redirectUri||this.redirectUri,grant_type:options.grantType||this.grantType||"authorization_code"}});options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.oauthLogin=function(accessToken,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"admin/oauth/login";options=Object.assign(options,{url:url,method:"POST",params:{access_token:accessToken}});return this._cacheURL(options.url,options,callback);};if(typeof require!=="undefined"){var base=require("../base");var ripe=base.ripe;} ripe.Ripe.prototype.getOrders=function(options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"orders";options=Object.assign(options,{url:url,method:"GET",auth:true});options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.getOrder=function(number,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"orders/"+String(number);options=Object.assign(options,{url:url,method:"GET",auth:true});options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.createOrder=function(number,options,callback){return this.setOrderStatus(number,"create",options,callback);};ripe.Ripe.prototype.produceOrder=function(number,options,callback){return this.setOrderStatus(number,"produce",options,callback);};ripe.Ripe.prototype.readyOrder=function(number,options,callback){return this.setOrderStatus(number,"ready",options,callback);};ripe.Ripe.prototype.sendOrder=function(number,trackingNumber,trackingUrl,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;options=Object.assign(options,{params:{tracking_number:trackingNumber,tracking_url:trackingUrl}});return this.setOrderStatus(number,"send",options,callback);};ripe.Ripe.prototype.receiveOrder=function(number,options,callback){return this.setOrderStatus(number,"receive",options,callback);};ripe.Ripe.prototype.returnOrder=function(number,options,callback){return this.setOrderStatus(number,"return",options,callback);};ripe.Ripe.prototype.cancelOrder=function(number,options,callback){return this.setOrderStatus(number,"cancel",options,callback);};ripe.Ripe.prototype.setOrderStatus=function(number,status,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"orders/"+String(number)+"/"+status;options=Object.assign(options,{url:url,auth:true,method:"PUT"});options=this._build(options);return this._cacheURL(options.url,options,callback);};if(typeof require!=="undefined"){var base=require("../base");var ripe=base.ripe;} ripe.Ripe.prototype.getSizes=function(options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"sizes";options=Object.assign(options,{url:url,method:"GET"});options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.sizeToNative=function(scale,value,gender,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var url=this.url+"sizes/size_to_native";options=Object.assign(options,{url:url,method:"GET",params:{scale:scale,value:value,gender:gender}});options=this._build(options);return this._cacheURL(options.url,options,callback);};ripe.Ripe.prototype.sizeToNativeB=function(scales,values,genders,options,callback){callback=typeof options==="function"?options:callback;options=typeof options==="function"?{}:options;var scalesP=[];var valuesP=[];var gendersP=[];for(var index=0;index