|
1 | | -import * as Observable from 'tns-core-modules/data/observable' |
2 | | -import * as Page from 'tns-core-modules/ui/page' |
3 | | -import * as fs from 'tns-core-modules/file-system' |
4 | | -import * as dialogs from 'tns-core-modules/ui/dialogs' |
5 | | -import * as Https from 'nativescript-https' |
| 1 | +import * as Observable from 'tns-core-modules/data/observable'; |
| 2 | +import * as Page from 'tns-core-modules/ui/page'; |
| 3 | +import * as fs from 'tns-core-modules/file-system'; |
| 4 | +import * as dialogs from 'tns-core-modules/ui/dialogs'; |
| 5 | +import * as Https from 'nativescript-https'; |
6 | 6 |
|
7 | 7 | export function onNavigatingTo(args: Page.NavigatedData) { |
8 | | - let page = args.object as Page.Page |
9 | | - page.bindingContext = Observable.fromObject({ enabled: false }) |
| 8 | + let page = args.object as Page.Page; |
| 9 | + page.bindingContext = Observable.fromObject({enabled: false}); |
10 | 10 | } |
11 | 11 |
|
12 | 12 | function getRequest(url: string, allowLargeResponse = false) { |
13 | | - Https.request({ |
14 | | - url, |
15 | | - method: 'GET', |
16 | | - allowLargeResponse |
17 | | - }).then(function(response) { |
18 | | - console.log('Https.request response', response) |
19 | | - }).catch(function(error) { |
20 | | - console.error('Https.request error', error) |
21 | | - dialogs.alert(error) |
22 | | - }) |
| 13 | + Https.request( |
| 14 | + { |
| 15 | + url, |
| 16 | + method: 'GET', |
| 17 | + allowLargeResponse |
| 18 | + }) |
| 19 | + .then(response => console.log('Https.request response', response)) |
| 20 | + .catch(error => { |
| 21 | + console.error('Https.request error', error); |
| 22 | + dialogs.alert(error); |
| 23 | + }); |
23 | 24 | } |
24 | 25 |
|
25 | 26 | function postRequest(url: string, body: any) { |
26 | | - Https.request({ |
27 | | - url, |
28 | | - method: 'POST', |
29 | | - body |
30 | | - }).then(function(response) { |
31 | | - console.log('Https.request response', response) |
32 | | - }).catch(function(error) { |
33 | | - console.error('Https.request error', error) |
34 | | - dialogs.alert(error) |
35 | | - }) |
36 | | -} |
37 | | - |
38 | | -export function postHttpbin() { postRequest('https://httpbin.org/post', {"foo": "bar", "baz": undefined, "plaz": null}) } |
39 | | -export function getHttpbin() { getRequest('https://httpbin.org/get') } |
40 | | -export function getHttpbinLargeResponse() { getRequest('https://httpbin.org/bytes/100000', true) } |
41 | | -export function getMockbin() { getRequest('https://mockbin.com/request') } |
| 27 | + Https.request( |
| 28 | + { |
| 29 | + url, |
| 30 | + method: 'POST', |
| 31 | + body |
| 32 | + }) |
| 33 | + .then(response => console.log('Https.request response', response)) |
| 34 | + .catch(error => { |
| 35 | + console.error('Https.request error', error); |
| 36 | + dialogs.alert(error); |
| 37 | + }); |
| 38 | +} |
| 39 | + |
| 40 | +export function postHttpbin() { |
| 41 | + postRequest('https://httpbin.org/post', {"foo": "bar", "baz": undefined, "plaz": null}); |
| 42 | +} |
| 43 | + |
| 44 | +export function getHttpbin() { |
| 45 | + getRequest('https://httpbin.org/get'); |
| 46 | +} |
| 47 | + |
| 48 | +export function getHttpbinLargeResponse() { |
| 49 | + getRequest('https://httpbin.org/bytes/100000', true); |
| 50 | +} |
| 51 | + |
| 52 | +export function getMockbin() { |
| 53 | + getRequest('https://mockbin.com/request'); |
| 54 | +} |
42 | 55 |
|
43 | 56 | export function enableSSLPinning(args: Observable.EventData) { |
44 | | - let dir = fs.knownFolders.currentApp().getFolder('assets') |
45 | | - let certificate = dir.getFile('httpbin.org.cer').path |
46 | | - Https.enableSSLPinning({ host: 'httpbin.org', certificate }) |
47 | | - let context = (args.object as Page.View).bindingContext as Observable.Observable |
48 | | - context.set('enabled', true) |
| 57 | + let dir = fs.knownFolders.currentApp().getFolder('assets'); |
| 58 | + let certificate = dir.getFile('httpbin.org.cer').path; |
| 59 | + Https.enableSSLPinning({host: 'httpbin.org', certificate}); |
| 60 | + let context = (args.object as Page.View).bindingContext as Observable.Observable; |
| 61 | + context.set('enabled', true); |
49 | 62 | } |
50 | 63 |
|
51 | 64 | export function disableSSLPinning(args: Observable.EventData) { |
52 | | - Https.disableSSLPinning() |
53 | | - let context = (args.object as Page.View).bindingContext as Observable.Observable |
54 | | - context.set('enabled', false) |
| 65 | + Https.disableSSLPinning(); |
| 66 | + let context = (args.object as Page.View).bindingContext as Observable.Observable; |
| 67 | + context.set('enabled', false); |
55 | 68 | } |
56 | 69 |
|
57 | 70 |
|
0 commit comments