()
| 291 | |
| 292 | |
| 293 | function init() { |
| 294 | isSurge = () => { |
| 295 | return undefined === this.$httpClient ? false : true |
| 296 | } |
| 297 | isQuanX = () => { |
| 298 | return undefined === this.$task ? false : true |
| 299 | } |
| 300 | getdata = (key) => { |
| 301 | if (isSurge()) return $persistentStore.read(key) |
| 302 | if (isQuanX()) return $prefs.valueForKey(key) |
| 303 | } |
| 304 | setdata = (key, val) => { |
| 305 | if (isSurge()) return $persistentStore.write(key, val) |
| 306 | if (isQuanX()) return $prefs.setValueForKey(key, val) |
| 307 | } |
| 308 | msg = (title, subtitle, body) => { |
| 309 | if (isSurge()) $notification.post(title, subtitle, body) |
| 310 | if (isQuanX()) $notify(title, subtitle, body) |
| 311 | } |
| 312 | log = (message) => console.log(message) |
| 313 | get = (url, cb) => { |
| 314 | if (isSurge()) { |
| 315 | $httpClient.get(url, cb) |
| 316 | } |
| 317 | if (isQuanX()) { |
| 318 | url.method = 'GET' |
| 319 | $task.fetch(url).then((resp) => cb(null, {}, resp.body)) |
| 320 | } |
| 321 | } |
| 322 | post = (options, callback) => { |
| 323 | if (isQuanX()) { |
| 324 | if (typeof options == "string") options = { url: options } |
| 325 | options["method"] = "POST" |
| 326 | $task.fetch(options).then(response => { |
| 327 | response["status"] = response.statusCode |
| 328 | callback(null, response, response.body) |
| 329 | }, reason => callback(reason.error, null, null)) |
| 330 | } |
| 331 | if (isSurge()) $httpClient.post(options, callback) |
| 332 | } |
| 333 | done = (value = {}) => { |
| 334 | $done(value) |
| 335 | } |
| 336 | return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done } |
| 337 | } |
| 338 | |
| 339 | |
| 340 |
no test coverage detected
searching dependent graphs…