|
var config = { |
|
headers: {}, |
|
timeout: 30000, |
|
domain: 'http://localhost', |
|
port: 8080 |
|
}; |
|
|
|
var NoCache = 1, |
|
CacheElseNetwork = 2, |
|
NetworkElseCache = 4, |
|
CacheThenNetwork = 8, |
|
CacheOnly = 16, |
|
NetworkOnly = 32; |
|
|
|
var SDK = module.exports = { |
|
/* |
|
Public API. |
|
*/ |
|
getModel: function (name, failIfMissing) { |
|
name = String(name || '').replace('connector/', ''); |
|
var result = this.models[name]; |
|
if (!result) { |
|
for (var modelName in this.models) { |
|
if (this.models.hasOwnProperty(modelName) && name === modelName.split('/').pop()) { |
|
result = this.models[modelName]; |
|
break; |
|
} |
|
} |
|
} |
|
if (!result && failIfMissing) { |
|
throw new Error('Couldn\'t find model named: ' + name); |
|
} |
|
return result; |
|
}, |
|
getAPI: function (pathOrNickname, method) { |
|
for (var i = 0; i < this.apis.length; i++) { |
|
var API = this.apis[i]; |
|
if (1 === arguments.length) { |
|
if (API.nickname === pathOrNickname) { |
|
return API; |
|
} |
|
} |
|
else { |
|
if (API.path === pathOrNickname && API.method === method) { |
|
return API; |
|
} |
|
} |
|
} |
|
return null; |
|
}, |
|
|
|
/* |
|
Constants. |
|
*/ |
|
Policy: { |
|
/** |
|
* No caches are used or saved. This is the default caching policy for models. |
|
*/ |
|
NoCache: 1, |
|
/** |
|
* If a local cache of the results is available, it will be used; otherwise, the network will be used. Results will |
|
* be cached. |
|
*/ |
|
CacheElseNetwork: 2, |
|
/** |
|
* If the network is available, it will be used for results; otherwise, the local cache will be used. Results will |
|
* be cached. |
|
*/ |
|
NetworkElseCache: 4, |
|
/** |
|
* If a local cache of the result is available, it will be used immediately, and then the network will be used. The |
|
* callback will, thus, be called twice. Results will be cached. |
|
*/ |
|
CacheThenNetwork: 8, |
|
/** |
|
* If a local cache of results is available, it will be used. |
|
*/ |
|
CacheOnly: 16, |
|
/** |
|
* If the network is available, it will be used for results. Results will be cached. |
|
*/ |
|
NetworkOnly: 32 |
|
}, |
|
|
|
/* |
|
Configuration. |
|
*/ |
|
get domain() { return config.domain; }, |
|
set domain(val) { config.domain = val; }, |
|
get port() { return config.port; }, |
|
set port(val) { config.port = val; }, |
|
get timeout() { return config.timeout; }, |
|
set timeout(val) { config.timeout = val; }, |
|
get APIKey() { return config.APIKey; }, |
|
set APIKey(val) { config.APIKey = val; }, |
|
get Authorization() { return config.Authorization; }, |
|
set Authorization(val) { |
|
if (0 === val.indexOf('Basic ')) { |
|
config.headers.Authorization = val; |
|
} |
|
else if (':' === val.slice(-1)) { |
|
config.headers.Authorization = 'Basic ' + Ti.Utils.base64encode(val); |
|
} |
|
else { |
|
config.headers.Authorization = 'Basic ' + Ti.Utils.base64encode(val + ':'); |
|
} |
|
}, |
|
|
|
/* |
|
Utility. |
|
*/ |
|
isFunction: function isFunction(val) { |
|
return 'function' === typeof val; |
|
}, |
|
|
|
appendQuery: function appendQuery(url, query) { |
|
for (var queryName in query) { |
|
if (query.hasOwnProperty(queryName)) { |
|
url += (url.indexOf('?') === -1 ? '?' : '&') + queryName; |
|
if (query[queryName] !== '') { |
|
url += '=' + encodeURIComponent(query[queryName]); |
|
} |
|
} |
|
} |
|
return url; |
|
}, |
|
|
|
constructHTTP: function constructHTTP(method, url, onLoad, onError) { |
|
var client = Ti.Network.createHTTPClient({ |
|
onload: onLoad, |
|
onerror: onError, |
|
timeout: config.timeout |
|
}); |
|
client.open(method, url); |
|
|
|
// Add headers. |
|
for (var headerName in config.headers) { |
|
if (config.headers.hasOwnProperty(headerName)) { |
|
client.setRequestHeader(headerName, config.headers[headerName]); |
|
} |
|
} |
|
|
|
return client; |
|
}, |
|
|
|
getURL: function getURL(path) { |
|
var url = config.domain; |
|
if (config.port && config.port !== 80) { |
|
url += ':' + config.port; |
|
} |
|
url += path; |
|
return url; |
|
}, |
|
|
|
/** |
|
* Gets the cache db, ensuring it has the proper schema set up. |
|
* @returns {Window} |
|
*/ |
|
getCacheDB: function () { |
|
if (this.cacheDB) { |
|
return Ti.Database.open(this.cacheDB); |
|
} |
|
this.cacheDB = 'weatherserviceCache'; |
|
var db = Ti.Database.open(this.cacheDB); |
|
db.execute('CREATE TABLE IF NOT EXISTS cache(hash TEXT PRIMARY KEY, until INTEGER, result BLOB);'); |
|
db.file.setRemoteBackup(false); |
|
return db; |
|
}, |
|
/** |
|
* Checks the cache to see if results have been cached for the specific request. |
|
* @param hash A string that uniquely identifies the request. |
|
* @returns The cached results, or undefined. |
|
*/ |
|
readCache: function (hash) { |
|
hash = Ti.Utils.md5HexDigest(hash); |
|
var db = this.getCacheDB(); |
|
db.execute('DELETE FROM cache WHERE until < ?', Date.now()); |
|
var result = db.execute('SELECT result FROM cache WHERE hash = ? LIMIT 1', hash), |
|
retVal; |
|
if (result.isValidRow()) { |
|
retVal = JSON.parse(result.fieldByName('result')); |
|
} |
|
result.close(); |
|
db.close(); |
|
return retVal; |
|
}, |
|
/** |
|
* |
|
* @param hash |
|
* @param duration |
|
* @param results |
|
*/ |
|
writeCache: function (hash, duration, results) { |
|
hash = Ti.Utils.md5HexDigest(hash); |
|
var db = this.getCacheDB(); |
|
db.execute('INSERT OR REPLACE INTO cache (hash, until, result) VALUES (?, ?, ?);', |
|
hash, |
|
Date.now() + duration, |
|
JSON.stringify(results)); |
|
db.close(); |
|
}, |
|
|
|
/* |
|
Definitions. |
|
*/ |
|
models: { |
|
'appc.labs.soap/Global': { |
|
cachePolicy: { |
|
duration: 60000, |
|
type: NoCache |
|
}, |
|
'deleteAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'create': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'findAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'count': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'upsert': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'query': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityWeatherByZIPHttpPost': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityWeatherByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityWeatherByZIP': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityWeatherByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'findAndModify': function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
}, |
|
'GetWeatherInformation': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetWeatherInformation'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'GetWeatherInformationHttpPost': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetWeatherInformation'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'GetCityForecastByZIP': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityForecastByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityForecastByZIPHttpPost': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityForecastByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'findOne': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'update': function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
}, |
|
'delete': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'distinct': function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
'appc.labs.soap/Weather/WeatherSoap': { |
|
cachePolicy: { |
|
duration: 60000, |
|
type: NoCache |
|
}, |
|
'query': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'findAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'deleteAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'create': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'upsert': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'count': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'GetWeatherInformationHttpPost': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'GetCityForecastByZIP': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityForecastByZIPHttpPost': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'findAndModify': function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityWeatherByZIPHttpPost': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityWeatherByZIP': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'GetWeatherInformation': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'update': function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
}, |
|
'delete': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'findOne': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'distinct': function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
'appc.labs.soap/Weather/WeatherSoap12': { |
|
cachePolicy: { |
|
duration: 60000, |
|
type: NoCache |
|
}, |
|
'GetCityWeatherByZIPHttpPost': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'findAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'deleteAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'create': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'query': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'upsert': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'count': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'findAndModify': function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityWeatherByZIP': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityForecastByZIPHttpPost': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'GetCityForecastByZIP': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'GetWeatherInformationHttpPost': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'GetWeatherInformation': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'findOne': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'delete': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'update': function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
}, |
|
'distinct': function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
'testuser': { |
|
cachePolicy: { |
|
duration: 60000, |
|
type: NoCache |
|
}, |
|
'query': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'count': function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
}, |
|
'findAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/testuser'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'deleteAll': function method(callback) { |
|
|
|
var url = SDK.getURL('/api/testuser'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
}, |
|
'create': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'upsert': function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
}, |
|
'findAndModify': function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
}, |
|
'findOne': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/testuser/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'distinct': function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
}, |
|
'delete': function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/testuser/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
}, |
|
'update': function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
} |
|
} |
|
}, |
|
apis: [ |
|
{ |
|
nickname: '/api/testapi', |
|
path: '/api/testapi/:id', |
|
method: 'GET', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/testapi/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser/query', |
|
path: '/api/testuser/query', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser/count', |
|
path: '/api/testuser/count', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser', |
|
path: '/api/testuser', |
|
method: 'GET', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/testuser'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser', |
|
path: '/api/testuser', |
|
method: 'DELETE', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/testuser'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser', |
|
path: '/api/testuser', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser/upsert', |
|
path: '/api/testuser/upsert', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser/findAndModify', |
|
path: '/api/testuser/findAndModify', |
|
method: 'PUT', |
|
execute: function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser', |
|
path: '/api/testuser/:id', |
|
method: 'GET', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/testuser/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser/distinct', |
|
path: '/api/testuser/distinct/:field', |
|
method: 'GET', |
|
execute: function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser', |
|
path: '/api/testuser/:id', |
|
method: 'DELETE', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/testuser/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/testuser', |
|
path: '/api/testuser/:id', |
|
method: 'PUT', |
|
execute: function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/testuser/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/query', |
|
path: '/api/appc.labs.soap/weather/weathersoap/query', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap', |
|
path: '/api/appc.labs.soap/weather/weathersoap', |
|
method: 'GET', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap', |
|
path: '/api/appc.labs.soap/weather/weathersoap', |
|
method: 'DELETE', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap', |
|
path: '/api/appc.labs.soap/weather/weathersoap', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/upsert', |
|
path: '/api/appc.labs.soap/weather/weathersoap/upsert', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/count', |
|
path: '/api/appc.labs.soap/weather/weathersoap/count', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation', |
|
path: '/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation', |
|
method: 'POST', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityForecastByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/findAndModify', |
|
path: '/api/appc.labs.soap/weather/weathersoap/findAndModify', |
|
method: 'PUT', |
|
execute: function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetCityWeatherByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation', |
|
path: '/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation', |
|
method: 'GET', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/GetWeatherInformation'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap', |
|
path: '/api/appc.labs.soap/weather/weathersoap/:id', |
|
method: 'PUT', |
|
execute: function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap', |
|
path: '/api/appc.labs.soap/weather/weathersoap/:id', |
|
method: 'DELETE', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap', |
|
path: '/api/appc.labs.soap/weather/weathersoap/:id', |
|
method: 'GET', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap/distinct', |
|
path: '/api/appc.labs.soap/weather/weathersoap/distinct/:field', |
|
method: 'GET', |
|
execute: function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global', |
|
path: '/api/appc.labs.soap/global', |
|
method: 'DELETE', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global', |
|
path: '/api/appc.labs.soap/global', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global', |
|
path: '/api/appc.labs.soap/global', |
|
method: 'GET', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/count', |
|
path: '/api/appc.labs.soap/global/count', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/upsert', |
|
path: '/api/appc.labs.soap/global/upsert', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/query', |
|
path: '/api/appc.labs.soap/global/query', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/GetCityWeatherByZIP', |
|
path: '/api/appc.labs.soap/global/GetCityWeatherByZIP', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityWeatherByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/GetCityWeatherByZIP', |
|
path: '/api/appc.labs.soap/global/GetCityWeatherByZIP', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityWeatherByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/findAndModify', |
|
path: '/api/appc.labs.soap/global/findAndModify', |
|
method: 'PUT', |
|
execute: function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/GetWeatherInformation', |
|
path: '/api/appc.labs.soap/global/GetWeatherInformation', |
|
method: 'GET', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetWeatherInformation'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/GetWeatherInformation', |
|
path: '/api/appc.labs.soap/global/GetWeatherInformation', |
|
method: 'POST', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetWeatherInformation'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/GetCityForecastByZIP', |
|
path: '/api/appc.labs.soap/global/GetCityForecastByZIP', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityForecastByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/GetCityForecastByZIP', |
|
path: '/api/appc.labs.soap/global/GetCityForecastByZIP', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/GetCityForecastByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global', |
|
path: '/api/appc.labs.soap/global/:id', |
|
method: 'GET', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global', |
|
path: '/api/appc.labs.soap/global/:id', |
|
method: 'PUT', |
|
execute: function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global', |
|
path: '/api/appc.labs.soap/global/:id', |
|
method: 'DELETE', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/global/distinct', |
|
path: '/api/appc.labs.soap/global/distinct/:field', |
|
method: 'GET', |
|
execute: function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/global/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12', |
|
path: '/api/appc.labs.soap/weather/weathersoap12', |
|
method: 'GET', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12', |
|
path: '/api/appc.labs.soap/weather/weathersoap12', |
|
method: 'DELETE', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12'); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12', |
|
path: '/api/appc.labs.soap/weather/weathersoap12', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/query', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/query', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/query'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/upsert', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/upsert', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/upsert'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/count', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/count', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/count'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/findAndModify', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/findAndModify', |
|
method: 'PUT', |
|
execute: function method(query, body, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
body = {}; |
|
} |
|
else if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/findAndModify'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityWeatherByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP', |
|
method: 'POST', |
|
execute: function method(body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP', |
|
method: 'GET', |
|
execute: function method(query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetCityForecastByZIP'); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
query = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation', |
|
method: 'POST', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation'); |
|
|
|
|
|
var client = SDK.constructHTTP('POST', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation', |
|
method: 'GET', |
|
execute: function method(callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/GetWeatherInformation'); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/:id', |
|
method: 'GET', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/:id'); |
|
url = url.replace(':id', id); |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/:id', |
|
method: 'DELETE', |
|
execute: function method(id, callback) { |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('DELETE', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/:id', |
|
method: 'PUT', |
|
execute: function method(id, body, callback) { |
|
if (SDK.isFunction(body)) { |
|
callback = body; |
|
body = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/:id'); |
|
url = url.replace(':id', id); |
|
|
|
|
|
var client = SDK.constructHTTP('PUT', url, onLoad, onError); |
|
client.send(body); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
id = body = callback = url = client = null; |
|
} |
|
} |
|
}, |
|
{ |
|
nickname: '/api/appc.labs.soap/weather/weathersoap12/distinct', |
|
path: '/api/appc.labs.soap/weather/weathersoap12/distinct/:field', |
|
method: 'GET', |
|
execute: function method(field, query, callback) { |
|
if (SDK.isFunction(query)) { |
|
callback = query; |
|
query = {}; |
|
} |
|
|
|
var url = SDK.getURL('/api/appc.labs.soap/weather/weathersoap12/distinct/:field'); |
|
url = url.replace(':field', field); |
|
if (query) { |
|
url = SDK.appendQuery(url, query); |
|
} |
|
|
|
// TODO: Can we instead expose caching using hooks, or similar? |
|
var cachePolicy = this.cachePolicy || { type: NoCache }; |
|
// TODO: Should we consider headers for the cache hash as well? |
|
// If we're using one of the policies that can use the cache... |
|
if (!!(cachePolicy.type & (CacheElseNetwork | CacheThenNetwork | CacheOnly))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
// CacheElseNetwork or CacheOnly? Then we can return. |
|
if (cachePolicy.type !== CacheThenNetwork) { |
|
return cached; |
|
} |
|
// CacheThenNetwork would carry on. |
|
} |
|
// CacheOnly will never hit the network; it wants to return, even if we don't find results. |
|
if (cachePolicy.type === CacheOnly) { |
|
callback(new Error('No results have been cached yet.'), null, null); |
|
return; |
|
} |
|
} |
|
|
|
var client = SDK.constructHTTP('GET', url, onLoad, onError); |
|
client.send(); |
|
|
|
function onLoad() { |
|
if (!callback) { |
|
return; |
|
} |
|
var body = this.responseText; |
|
if (/^application\/(.*\\+)?json/.test(this.getResponseHeader('Content-Type'))) { |
|
try { |
|
body = JSON.parse(body); |
|
if (body.key && body[body.key] !== undefined) { |
|
body = body[body.key]; |
|
} |
|
} |
|
catch (e) { |
|
console.error('Failed to parse the body from the server:'); |
|
console.error(body); |
|
console.error(e); |
|
} |
|
} |
|
if (this.status >= 200 && this.status <= 299) { |
|
if (!!(cachePolicy.type & (CacheElseNetwork | NetworkElseCache | CacheThenNetwork | NetworkOnly))) { |
|
SDK.writeCache(url, cachePolicy.duration, body); |
|
// TODO: When we do a findAll, cache findOne, too. |
|
// TODO: Non-GETs should bust the cache for find, right? |
|
} |
|
callback(null, body, client); |
|
} |
|
else { |
|
callback(body, null, client); |
|
} |
|
clean(); |
|
} |
|
|
|
function onError(e) { |
|
if (!callback) { |
|
return; |
|
} |
|
if (!!(cachePolicy.type & (NetworkElseCache))) { |
|
var cached = SDK.readCache(url); |
|
if (cached) { |
|
callback(null, cached, null); |
|
clean(); |
|
return; |
|
} |
|
} |
|
callback(e.error, null, client); |
|
clean(); |
|
} |
|
|
|
function clean() { |
|
field = query = callback = url = client = null; |
|
} |
|
} |
|
} |
|
] |
|
}; |