-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.ts
91 lines (79 loc) · 2.37 KB
/
demo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { SeniverseV3 } from '../v3'
const test = async () => {
const seniverseV3 = new SeniverseV3({
encryption: {
uid: '',
// add your api key
key: '' || process.env.SENIVERSE_API_KEY,
ttl: 10000,
enabled: false
},
cache: {
max: 1000,
ttl: 'auto',
enabled: true
},
query: {
language: 'zh-Hans',
timeouts: [3000, 3000]
},
returnRaw: false
})
let result: any
result = await seniverseV3.weather.daily.data({ days: 2, start: -1, location: 'beijing' })
console.log('\n============= result =============')
console.log(JSON.stringify(result))
console.log('\n')
result = await seniverseV3.weather.now.data({ days: 2, start: -1, location: 'beijing' })
console.log('\n============= result =============')
console.log(JSON.stringify(result))
console.log('\n')
result = await seniverseV3.air.daily.data({ days: 2, start: -1, location: 'beijing' })
console.log('\n============= result =============')
console.log(JSON.stringify(result))
console.log('\n')
result = await seniverseV3.life.chineseCalendar.data({ days: 2, start: -1 })
console.log('\n============= result =============')
console.log(JSON.stringify(result))
console.log('\n')
// cached
await seniverseV3.weather.daily.data({ days: 2, start: -1, location: 'beijing' })
await seniverseV3.weather.now.data({ days: 2, start: -1, location: 'beijing' })
await seniverseV3.air.daily.data({ days: 2, start: -1, location: 'beijing' })
await seniverseV3.life.chineseCalendar.data({ days: 2, start: -1 })
// use request api
result = await seniverseV3.request(
'/weather/daily',
{ days: 2, start: -1, location: 'beijing' }
)
console.log('\n============= result =============')
console.log(JSON.stringify(result))
console.log('\n')
result = await seniverseV3.request(
'/air/hourly_history',
{ scope: 'city', location: 'beijing' }
)
console.log('\n============= result =============')
console.log(JSON.stringify(result))
console.log('\n')
// jsonp
result = seniverseV3.jsonp(
'/weather/daily',
{
encryption: {
ttl: 1000,
uid: '',
key: '',
},
query: {
callback: 'weatherDaily',
location: 'beijing'
}
}
)
console.log('\n============= result =============')
console.log(result)
console.log('\n')
process.exit(0)
}
test()