diff options
| -rw-r--r-- | StoneIsland/www/index.html | 4 | ||||
| -rw-r--r-- | StoneIsland/www/js/lib/products/CollectionView.js | 2 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/_sdk.js | 17 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/account.js | 53 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/auth.js | 22 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/product.js | 25 |
6 files changed, 94 insertions, 29 deletions
diff --git a/StoneIsland/www/index.html b/StoneIsland/www/index.html index d3e047c3..0fa45793 100644 --- a/StoneIsland/www/index.html +++ b/StoneIsland/www/index.html @@ -379,10 +379,6 @@ <script src="js/sdk/account.js"></script> <script src="js/sdk/auth.js"></script> <script src="js/sdk/product.js"></script> -<script src="js/sdk/.js"></script> -<script src="js/sdk/.js"></script> -<script src="js/sdk/.js"></script> -<script src="js/sdk/.js"></script> <script src="js/index.js"></script> </html> diff --git a/StoneIsland/www/js/lib/products/CollectionView.js b/StoneIsland/www/js/lib/products/CollectionView.js index 5d4e45f2..71d07723 100644 --- a/StoneIsland/www/js/lib/products/CollectionView.js +++ b/StoneIsland/www/js/lib/products/CollectionView.js @@ -26,7 +26,7 @@ var CollectionView = View.extend({ fetch: function(){ this.$loader.show() - sdk.fetch_collection({ + sdk.product.fetch_collection({ gallery_id: 31483, // FOCUS ON CAMO success: this.populate.bind(this) }) diff --git a/StoneIsland/www/js/sdk/_sdk.js b/StoneIsland/www/js/sdk/_sdk.js index 073d6c0d..ce68da62 100644 --- a/StoneIsland/www/js/sdk/_sdk.js +++ b/StoneIsland/www/js/sdk/_sdk.js @@ -3,26 +3,11 @@ var sdk = (function(){ // var endpoint = "https://secure.api.yoox.biz/" var endpoint = "https://sandbox.api.yoox.biz/" - - sdk.headers = { - "x-yoox-appname": "{API-TEST}", - "x-yoox-api-key": "{API-KEY}", - "x-yoox-device": "smartphone", - } - + sdk.path = function(api, path){ return endpoint + api + "/STONEISLAND_US/" + path } - sdk.fetch_collection = function(opt){ - $.ajax({ - method: "GET", - url: sdk.path("Search.API/1.2", "search.json"), - data: { format: "full", gallery: opt.gallery_id }, - success: opt.success, - }) - } - sdk.image = function(code){ return "http://cdn.yoox.biz/" + code.substr(0,2) + "/" + code + "_11_f.jpg" } diff --git a/StoneIsland/www/js/sdk/account.js b/StoneIsland/www/js/sdk/account.js index 40ba1d67..bc37020f 100644 --- a/StoneIsland/www/js/sdk/account.js +++ b/StoneIsland/www/js/sdk/account.js @@ -1,12 +1,17 @@ sdk.account = (function(){ + var user_id, access_token + // https://gist.github.com/fanfare/d18498e7fa25acbd4486 var account = {} account.signup = function(opt){ $.ajax({ method: "POST", url: sdk.path("Account.API/1.5", "users.json"), - headers: sdk.headers, + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-api-key": auth.apikey, + }, data: opt.data, success: function(data){ console.log(data) @@ -24,17 +29,20 @@ sdk.account = (function(){ } account.login = function(opt){ - // TODO: fetch access token from storage $.ajax({ method: "POST", url: sdk.path("Account.API/1.5", "authfull.json"), - headers: sdk.headers, + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + }, data: opt.data, success: function(data){ console.log(data) - user_id = data['UserAccount']['UserId'] - access_token = data['UserAccount']['AccessToken'] + auth.user_id = data['UserAccount']['UserId'] + auth.access_token = data['UserAccount']['AccessToken'] + // why bother? // auth.set_user(user_id, access_token, name) opt.success(data) @@ -43,6 +51,41 @@ sdk.account = (function(){ }) } + // https://gist.github.com/fanfare/31bcccd9b3c4e5ee3575 + account.add_address = function(opt){ + $.ajax({ + method: "POST", + url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/addressBook/item.json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + }, + data: opt.data, + success: function(data){ + console.log(data) + opt.success(data) + }, + error: opt.error, + }) + } + + account.list_addresses = function(opt){ + $.ajax({ + method: "GET", + url: sdk.path("Account.API/1.5", "users/" + auth.user_id + "/addressBook.json"), + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + }, + data: opt.data, + success: function(data){ + console.log(data) + opt.success(data["Object"]) + }, + error: opt.error, + }) + } + return account })() diff --git a/StoneIsland/www/js/sdk/auth.js b/StoneIsland/www/js/sdk/auth.js index d2375aca..a8489b5d 100644 --- a/StoneIsland/www/js/sdk/auth.js +++ b/StoneIsland/www/js/sdk/auth.js @@ -1,9 +1,25 @@ -sdk.auth = (function(){ +/* + headers: { + "x-yoox-appname": auth.appname, + "x-yoox-account-token": auth.access_token, + "x-yoox-device": auth.device, + "x-yoox-api-key": auth.apikey, + }, +*/ + +var auth = (function(){ var auth = {} - + + auth.appname = "{API-TEST}" + auth.apikey = "{API-KEY}" + auth.device = "smartphone" + + auth.access_token = "" + auth.user_id = -1 + // integrate keychain/cordova.file.externalRootDirectory api - auth.set_user = function(access_token, api_key){ + auth.set_user = function(user_id, access_token, name){ // persist user data } auth.get_user = function(cb){ diff --git a/StoneIsland/www/js/sdk/product.js b/StoneIsland/www/js/sdk/product.js new file mode 100644 index 00000000..c904eb32 --- /dev/null +++ b/StoneIsland/www/js/sdk/product.js @@ -0,0 +1,25 @@ +sdk.product = (function(){ + var product = {} + + product.fetch_collection = function(opt){ + $.ajax({ + method: "GET", + url: sdk.path("Search.API/1.2", "search.json"), + data: { format: "full", gallery: opt.gallery_id }, + success: opt.success, + error: opt.error, + }) + } + + // https://gist.github.com/fanfare/2d25d1b36944188948ff + product.item = function(opt){ + $.ajax({ + method: "GET", + url: sdk.path("Item.API/1.0", "item/" + data.code + ".json"), + success: opt.success, + error: opt.error, + }) + } + + return product +})()
\ No newline at end of file |
