diff options
| -rw-r--r-- | StoneIsland/platforms/ios/StoneIsland.xcodeproj/project.xcworkspace/xcuserdata/jules.xcuserdatad/UserInterfaceState.xcuserstate | bin | 13540 -> 13291 bytes | |||
| -rw-r--r-- | StoneIsland/platforms/ios/www/js/index.js | 2 | ||||
| -rw-r--r-- | StoneIsland/platforms/ios/www/js/lib/products/ProductView.js | 2 | ||||
| -rw-r--r-- | StoneIsland/platforms/ios/www/js/sdk/_sdk.js | 16 | ||||
| -rw-r--r-- | StoneIsland/www/js/index.js | 2 | ||||
| -rw-r--r-- | StoneIsland/www/js/sdk/_sdk.js | 16 | ||||
| -rw-r--r-- | proxy/index.js | 127 | ||||
| -rw-r--r-- | proxy/package.json | 5 | ||||
| -rw-r--r-- | test/lib/promise.js | 2 | ||||
| -rw-r--r-- | test/lib/sdk.js | 2 | ||||
| -rw-r--r-- | test/test/01-product.js | 5 | ||||
| -rw-r--r-- | test/test/02-login.js | 2 | ||||
| -rw-r--r-- | test/test/03-address.js | 43 | ||||
| -rw-r--r-- | test/test/04-cart.js | 8 |
14 files changed, 181 insertions, 51 deletions
diff --git a/StoneIsland/platforms/ios/StoneIsland.xcodeproj/project.xcworkspace/xcuserdata/jules.xcuserdatad/UserInterfaceState.xcuserstate b/StoneIsland/platforms/ios/StoneIsland.xcodeproj/project.xcworkspace/xcuserdata/jules.xcuserdatad/UserInterfaceState.xcuserstate Binary files differindex 12703a70..51158e5f 100644 --- a/StoneIsland/platforms/ios/StoneIsland.xcodeproj/project.xcworkspace/xcuserdata/jules.xcuserdatad/UserInterfaceState.xcuserstate +++ b/StoneIsland/platforms/ios/StoneIsland.xcodeproj/project.xcworkspace/xcuserdata/jules.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/StoneIsland/platforms/ios/www/js/index.js b/StoneIsland/platforms/ios/www/js/index.js index 332e780d..e0b08351 100644 --- a/StoneIsland/platforms/ios/www/js/index.js +++ b/StoneIsland/platforms/ios/www/js/index.js @@ -5,7 +5,7 @@ var app = (function(){ app.bind() app.build() - sdk.init({ production: true }) + sdk.init({ env: "test" }) if (window.cordova) { document.addEventListener('deviceready', app.ready, false) diff --git a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js index e87fa398..76527c8b 100644 --- a/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js +++ b/StoneIsland/platforms/ios/www/js/lib/products/ProductView.js @@ -44,7 +44,7 @@ var ProductView = View.extend({ load: function(data){ var name_partz = data['ModelNames'].split(' ') var num = name_partz.shift() - var title = name_parts.join(' ') + var title = name_partz.join(' ') var type = data['MicroCategory'].toUpperCase() var price = "$" + data['DiscountedPrice'] + ".00" var size = data['Sizes'][0] diff --git a/StoneIsland/platforms/ios/www/js/sdk/_sdk.js b/StoneIsland/platforms/ios/www/js/sdk/_sdk.js index a7ecf6d3..31fd96ca 100644 --- a/StoneIsland/platforms/ios/www/js/sdk/_sdk.js +++ b/StoneIsland/platforms/ios/www/js/sdk/_sdk.js @@ -1,11 +1,21 @@ var sdk = (function(){ var sdk = {} - var endpoint = "https://sandbox.api.yoox.biz/" + var endpoint = "https://secure.api.yoox.biz/" + // var endpoint = "http://api.yoox.biz/" sdk.init = function(opt){ - if (opt && opt.production) { - endpoint = "https://secure.api.yoox.biz/" + switch (opt.env) { + case 'test': + endpoint = "http://lvh.me:9090/" + break + default: + case 'development': + endpoint = "http://api.yoox.biz/" + break + case 'production': + endpoint = "https://secure.api.yoox.biz/" + break } } diff --git a/StoneIsland/www/js/index.js b/StoneIsland/www/js/index.js index 332e780d..e0b08351 100644 --- a/StoneIsland/www/js/index.js +++ b/StoneIsland/www/js/index.js @@ -5,7 +5,7 @@ var app = (function(){ app.bind() app.build() - sdk.init({ production: true }) + sdk.init({ env: "test" }) if (window.cordova) { document.addEventListener('deviceready', app.ready, false) diff --git a/StoneIsland/www/js/sdk/_sdk.js b/StoneIsland/www/js/sdk/_sdk.js index a7ecf6d3..31fd96ca 100644 --- a/StoneIsland/www/js/sdk/_sdk.js +++ b/StoneIsland/www/js/sdk/_sdk.js @@ -1,11 +1,21 @@ var sdk = (function(){ var sdk = {} - var endpoint = "https://sandbox.api.yoox.biz/" + var endpoint = "https://secure.api.yoox.biz/" + // var endpoint = "http://api.yoox.biz/" sdk.init = function(opt){ - if (opt && opt.production) { - endpoint = "https://secure.api.yoox.biz/" + switch (opt.env) { + case 'test': + endpoint = "http://lvh.me:9090/" + break + default: + case 'development': + endpoint = "http://api.yoox.biz/" + break + case 'production': + endpoint = "https://secure.api.yoox.biz/" + break } } diff --git a/proxy/index.js b/proxy/index.js index c2e12c60..85a4981c 100644 --- a/proxy/index.js +++ b/proxy/index.js @@ -1,15 +1,52 @@ var http = require('http') -var PORT = 4567 +var https = require('https') +var path = require('path') +var fs = require('fs') +var url = require('url') -var server = http.createServer(function (req, res){ - res.end('It Works!! Path Hit: ' + req.url) - console.log(req.headers) +var PORT = 9090 + +var server = http.createServer().listen(PORT, function(){ + console.log("Proxy listening on: http://lvh.me:%s", PORT) }) -server.listen(PORT, function(){ - console.log("Proxy listening on: http://localhost:%s", PORT) +server.on('request', function (req, res){ + + if ( req.method == 'GET' && ! req.url.match(/API/) ) { + // public... + return stream(req, res) + } + + console.log(req.method, req.url) + + // console.log(req.headers) + + var options = {} + options.headers = get_headers(req.headers) + options.method = req.method + options.port = 443 + options.hostname = "secure.api.yoox.biz" + options.path = req.url + + req.pause() + + var connector = https.request(options, function(server_res) { + console.log(">> GOT", server_res.statusCode) + + server_res.pause() + res.writeHeader(server_res.statusCode, server_res.headers) + // server_res.on("data", function(s){ console.log("<<", s.toString()) }) + server_res.pipe(res) + server_res.resume() + }) + // req.on("data", function(s){ console.log(">>", s.toString()) }) + req.on("error", function(s){ console.log("/!\\ ERROR /!\\"); console.log(s) }) + req.pipe(connector) + req.resume() + }) + /* headers: { "x-yoox-appname": auth.appname, @@ -18,8 +55,76 @@ server.listen(PORT, function(){ "x-yoox-api-key": auth.apikey, "x-yoox-cart-token": cart.token, }, - - proxy content body - proxy method - proxy query string -*/
\ No newline at end of file +*/ + +function get_headers (h){ + var hh = {} + "appname account-token device api-key cart-token".split(" ").forEach(function(s){ + var key = "x-yoox-" + s + if (key in h) hh[key] = h[key] + }) + hh['Content-Type'] = "application/json" // h['content-type'] + if ('content-length' in h) hh['Content-Length'] = h['content-length'] + if ('connection' in h) hh['Connection'] = h['connection'] + return hh +} + +var mimes = { + "gif": "image/gif", + "png": "image/png", + "jpg": "image/jpeg", + "jpeg": "image/jpeg", + "html": "text/html", + "js": "application/javascript", + "css": "text/css", + "woff": "application/font-woff", + "ttf": "application/font-woff", +} + +function stream (req, res) { + var url = req.url.toLowerCase().split("?")[0] + var ext_partz = url.split("."), ext = ext_partz[ext_partz.length-1] + var mime = mimes[ext] || "application/octet-stream" + + if (! url || url == "/") { + url = "index.html" + mime = "text/html" + } + + var file = path.resolve("../StoneIsland/www/" + url) + + fs.stat(file, function(err, stats) { + if (! stats) { + // console.log(404) + res.writeHead(404) + res.end("404") + return + } + + var headers = { + "Content-Length": stats.size, + "Content-Type": mime, + } + + res.writeHead(200, "OK", headers) + + var stream = fs.createReadStream(file, { start: 0, end: stats.size }) + stream.on("open", function() { + stream.pipe(res) + }) + stream.on("error", function(err) { + console.log(err) + stream.destroy() + res.end() + }) + stream.on("close", function(){ + stream.destroy() + res.end() + }) + req.connection.setMaxListeners(50) + req.connection.on('close', function(){ + stream.destroy() + res.end() + }) + }) +}
\ No newline at end of file diff --git a/proxy/package.json b/proxy/package.json index f7304d43..fd5c7ee2 100644 --- a/proxy/package.json +++ b/proxy/package.json @@ -7,5 +7,8 @@ "test": "echo \"Error: no test specified\" && exit 1" }, "author": "okfocus", - "license": "LNT" + "license": "LNT", + "dependencies": { + "najax": "^0.2.1" + } } diff --git a/test/lib/promise.js b/test/lib/promise.js index ad895d90..a3638de4 100644 --- a/test/lib/promise.js +++ b/test/lib/promise.js @@ -21,10 +21,12 @@ module.exports = function(fn, data){ then: function(cb){ if (my_res) cb(my_res) else my_cb = cb + return promise }, error: function(cb){ if (my_error) cb(my_error) else error_cb = cb + return promise } } return promise diff --git a/test/lib/sdk.js b/test/lib/sdk.js index a34b18f9..a52d63c2 100644 --- a/test/lib/sdk.js +++ b/test/lib/sdk.js @@ -23,7 +23,7 @@ for (var i = 0; i < files.length; i++) { eval( fs.readFileSync(fn) + '' ) } -sdk.init({ production: true }) +sdk.init({ env: 'test' }) sdk.auth = auth // stick this here for now module.exports = sdk diff --git a/test/test/01-product.js b/test/test/01-product.js index 2a3f1aa0..5f9ebe6e 100644 --- a/test/test/01-product.js +++ b/test/test/01-product.js @@ -15,13 +15,12 @@ describe('product', function(){ assert(data.SearchResponseFull.Results.Items.length > 0) test_item = data.SearchResponseFull.Results.Items[0] done() + }).error(function(error){ + done() }) }) - }) - describe('#item()', function(){ it('returns an item', function(done){ - // console.log( test_item ) promise(sdk.product.item, { code: test_item['Code8'] }).then(function(data){ assert(data.Header.StatusCode == 200) assert('Item' in data) diff --git a/test/test/02-login.js b/test/test/02-login.js index 5bf2cdef..e96e93b5 100644 --- a/test/test/02-login.js +++ b/test/test/02-login.js @@ -33,9 +33,7 @@ describe('account', function(){ done() }) }) - }) - describe('#login()', function(){ it('refreshes the token', function(done){ promise(sdk.account.login, { data: login_user_data }).then(function(data){ // console.log(data) diff --git a/test/test/03-address.js b/test/test/03-address.js index cecc1bf4..9cf2dab5 100644 --- a/test/test/03-address.js +++ b/test/test/03-address.js @@ -6,36 +6,37 @@ var assert = require("assert") // sdk.address.list describe('address', function(){ - - sdk.auth.access_token = "45871479f5001afc06e628c7bb8e95ffb1f71df8" - sdk.auth.user_id = 374663521 - - var new_address_data = { - "Name":"name", - "Surname":"surname", - "Address":"address", - "IsDefault":false, - "IsBillingDefault":false, - "IsOwner":false, - "ZipCode":"88040", - "City":"City", - "Province":"Province", - "Phone":"Phone", - "Mobile":"Mobile", - "Mail":"Mail", - "UserId": sdk.auth.user_id, - } describe('#add()', function(){ it('adds an address', function(done){ + + if (! sdk.auth.access_token) { + sdk.auth.access_token = "45871479f5001afc06e628c7bb8e95ffb1f71df8" + sdk.auth.user_id = 374663521 + } + + var new_address_data = { + "Name":"name", + "Surname":"surname", + "Address":"address", + "IsDefault":false, + "IsBillingDefault":false, + "IsOwner":false, + "ZipCode":"88040", + "City":"City", + "Province":"Province", + "Phone":"Phone", + "Mobile":"Mobile", + "Mail":"Mail", + "UserId": sdk.auth.user_id, + } + promise(sdk.address.add, { data: new_address_data }).then(function(data){ assert(data.Header.StatusCode == 200) done() }) }) - }) - describe('#list()', function(){ it('lists addresses', function(done){ promise(sdk.address.list, {}).then(function(data){ // console.log(data.AddressBook) diff --git a/test/test/04-cart.js b/test/test/04-cart.js index dcb65c5b..2272f7bb 100644 --- a/test/test/04-cart.js +++ b/test/test/04-cart.js @@ -22,12 +22,14 @@ var assert = require("assert") // sdk.cart.finalize describe('cart', function(){ - - sdk.auth.access_token = "45871479f5001afc06e628c7bb8e95ffb1f71df8" - sdk.auth.user_id = 374663521 describe('#initialize()', function(){ it('initializes the cart', function(done){ + if (! sdk.auth.access_token) { + sdk.auth.access_token = "45871479f5001afc06e628c7bb8e95ffb1f71df8" + sdk.auth.user_id = 374663521 + } + promise(sdk.address.add, { data: {} }).then(function(data){ console.log(data) assert(data.Header.StatusCode == 200) |
