Add axios and kingoftime module for HTTP requests

This commit is contained in:
Adam Millerchip 2023-04-15 01:39:52 +09:00
parent 0b021187b8
commit 28bbc93f2b
3 changed files with 37 additions and 3 deletions

View file

@ -18,7 +18,8 @@
],
"dependencies": {
"@oclif/core": "^2",
"@oclif/plugin-help": "^5"
"@oclif/plugin-help": "^5",
"axios": "^1.3.5"
},
"devDependencies": {
"@oclif/test": "^2.3.14",

View file

@ -1,5 +1,6 @@
import {Command} from '@oclif/core'
import {tokenFlags} from '../tokenFlags'
import {checkin} from '../kingoftime'
export default class Checkout extends Command {
static description = 'Check in'
@ -12,7 +13,6 @@ export default class Checkout extends Command {
public async run(): Promise<void> {
const {flags} = await this.parse(Checkout)
console.log(`token: ${flags.token}`)
console.log(`userToken: ${flags.userToken}`)
await checkin(flags.token, flags['user-token'])
}
}

33
src/kingoftime.ts Normal file
View file

@ -0,0 +1,33 @@
import axios from 'axios';
const CHECK_IN_ID = 'qmXXCxw9WEWN3X/YrkMWuQ=='
const CHECK_OUT_ID = 'j8ekmJaw6W3M4w3i6hlSIQ=='
async function kingoftime(operationId: string, token: string, userToken: string) {
const response = await axios({
method: 'post',
//url: 'https://s2.kingtime.jp/gateway/bprgateway',
url: 'https://httpbin.org/anything',
headers: {
'Accept': 'application/json, text/javascript, */*; q=0.01'
},
data: new URLSearchParams({
'id': operationId,
'highAccuracyFlg': 'false',
'credential_code': '40',
'user_token': userToken,
'version': '1.4.2',
'token': token
})
})
console.log(response.data)
}
export async function checkin(token: string, userToken: string): Promise<void> {
await kingoftime(CHECK_IN_ID, token, userToken)
}
export async function checkout(token: string, userToken: string): Promise<void> {
await kingoftime(CHECK_OUT_ID, token, userToken)
}