1ot-api 中文文档教程

发布于 5年前 浏览 24 项目主页 更新于 3年前

1ot nodejs connector

https://1ot.com api

Installation

yarn

```shell 脚本 的连接器 yarn 添加 1ot-api

### npm

shell 脚本 npm 安装 1ot-api

## Usage

javascript import Connector, { primaryStatuses, secondaryStatuses } from '1ot-api'

const username = '...' const password = '...'

;(async () => { const connector = new Connector(/* tokenData 如果它被保存 */)

// Happen every time new access token received
connector.on('token', (tokenData) => {
    const { accessToken, expiresIn, refreshToken } = tokenData
    // store token data for reuse
})

await connector.auth(username, password)

const sims = await connector.getSims({ groupName: 'Test group' })

for (let sim of sims) {
    const {
        status: { primary, secondary }
    } = sim
    if (primary === primaryStatuses.ON) {
        if (secondary === secondaryStatuses.LIVE) {
            // put sim to sleep mode
            await sim.deactivate()
        } else {
            // resume sim from sleep mode
            await sim.activate()
        }
    }
}

})()

## Description

打字稿 import Connector from '1ot-api'

const connector = new Connector(tokenData?: { accessToken: string, expiresIn: Date, refreshToken: string })

### Common methods

打字稿 /*

  • GET /auth
  • when accessToken will be expired, token refreshes automatically */ const result: boolean = await connector.auth(username: string, password: string)

// GET /getaccount余额 const balance = await connector.account.balance()

// GET /getaccount组 const groups = await connector.account.getGroups()

/*

  • GET /getavailableprofiles
  • Account must supports esims / const profiles = await connector.getProfiles() / if groupName is defined - GET /getgroupalerts others - GET /getaccountalerts */ const alerts = await connector.getAlerts(params?: { groupName?: string })
### Sims selection

打字稿 import { Sim } from '1ot-api'

// GET /get_sim const sim: Sim = await connector.getSim(params: { iccid?: string, eid?: string})

/*

  • Alternative way, without loading sim data
  • Usefull for actions on known sims */ const sim: Sim = new Sim({iccid?: string, eid?: string}) // It's not necessary await sim.load()

/* 如果定义了 iccid 或 eid - GET /getsims 如果定义了 groupName - GET /getgpoupsims 其他 - GET /getaccount_sims / 常量模拟人生:{ / 找到,限制,总数,偏移量 */ 模拟人生:数组} = await connector.getSims(参数?:{ 偏移量?:数字= 0, iccid?: (字符串|数组<字符串>), eid?: (string|Array), 组名?:字符串 })

/*

  • Selecting all sims in several requests if it needed (more than 1000 sims)
  • Filtering - same as getSim */ const sims: Sims = await connector.getAllSims(filter?: { iccid?: (string|Array), eid?: (string|Array), groupName?: string })
### Sim info

打字稿 // GET /getsim警报 const alerts = await sim.getAlerts(params?: { offset?: number = 0, onlyUnread?: boolean = false, markAsRead?: boolean = false })

// GET /getsimcost const cost = await sim.getCost(date?: Date)

// GET /getsim会话 const sessions = await sim.getSessions({ offset?: number = 0, from?: number, to?: number })

### Actions

打字稿 // 放置/关闭 await sim.close()

/*

  • PUT /diagnostics
  • Only when feature is enabled in App Store */ await sim.diagnostics()

// PUT /esim_profile await sim.esimProfile(profile: string, action: string)

// PUT /重置 等待 sim.reset()

// PUT /resume 等待 sim.resume()

// PUT /sendSms await sim.sendSms(sms: string)

// PUT /setdatalimit 等待 sim.setDataLimit(dataLimit: number)

// PUT /set_group await sim.setGroupt(groupName: string)

// PUT /set_name await sim.setName(name: string)

// PUT /暂停 等待 sim.suspend()

// PUT /test 等待 sim.test()

// PUT /activate 等待 sim.activate()

// PUT /deactivate 等待 sim.deactivate()

For Sims object (`connector.getAllSims()`) all actions are available (will be apply for every sim inside). For example:

打字稿 const sims = await connector.getAllSims({ groupName: '温度传感器'}) 等待 sims.suspend() ```

1ot nodejs connector

Connector for https://1ot.com api

Installation

yarn

```shell script yarn add 1ot-api

### npm

shell script npm install 1ot-api

## Usage

javascript import Connector, { primaryStatuses, secondaryStatuses } from '1ot-api'

const username = '…' const password = '…'

;(async () => { const connector = new Connector(/* tokenData if it was saved */)

// Happen every time new access token received
connector.on('token', (tokenData) => {
    const { accessToken, expiresIn, refreshToken } = tokenData
    // store token data for reuse
})

await connector.auth(username, password)

const sims = await connector.getSims({ groupName: 'Test group' })

for (let sim of sims) {
    const {
        status: { primary, secondary }
    } = sim
    if (primary === primaryStatuses.ON) {
        if (secondary === secondaryStatuses.LIVE) {
            // put sim to sleep mode
            await sim.deactivate()
        } else {
            // resume sim from sleep mode
            await sim.activate()
        }
    }
}

})()

## Description

typescript import Connector from '1ot-api'

const connector = new Connector(tokenData?: { accessToken: string, expiresIn: Date, refreshToken: string })

### Common methods

typescript /*

  • GET /auth
  • when accessToken will be expired, token refreshes automatically */ const result: boolean = await connector.auth(username: string, password: string)

// GET /getaccountbalance const balance = await connector.account.balance()

// GET /getaccountgroups const groups = await connector.account.getGroups()

/*

  • GET /getavailableprofiles
  • Account must supports esims / const profiles = await connector.getProfiles() / if groupName is defined - GET /getgroupalerts others - GET /getaccountalerts */ const alerts = await connector.getAlerts(params?: { groupName?: string })
### Sims selection

typescript import { Sim } from '1ot-api'

// GET /get_sim const sim: Sim = await connector.getSim(params: { iccid?: string, eid?: string})

/*

  • Alternative way, without loading sim data
  • Usefull for actions on known sims */ const sim: Sim = new Sim({iccid?: string, eid?: string}) // It's not necessary await sim.load()

/* if iccid or eid are defined - GET /getsims if groupName is defined - GET /getgpoupsims others - GET /getaccount_sims / const sims: { / found, limit, total, offset */ sims: Array} = await connector.getSims(params?: { offset?: number = 0, iccid?: (string|Array), eid?: (string|Array), groupName?: string })

/*

  • Selecting all sims in several requests if it needed (more than 1000 sims)
  • Filtering - same as getSim */ const sims: Sims = await connector.getAllSims(filter?: { iccid?: (string|Array), eid?: (string|Array), groupName?: string })
### Sim info

typescript // GET /getsimalerts const alerts = await sim.getAlerts(params?: { offset?: number = 0, onlyUnread?: boolean = false, markAsRead?: boolean = false })

// GET /getsimcost const cost = await sim.getCost(date?: Date)

// GET /getsimsessions const sessions = await sim.getSessions({ offset?: number = 0, from?: number, to?: number })

### Actions

typescript // PUT /close await sim.close()

/*

  • PUT /diagnostics
  • Only when feature is enabled in App Store */ await sim.diagnostics()

// PUT /esim_profile await sim.esimProfile(profile: string, action: string)

// PUT /reset await sim.reset()

// PUT /resume await sim.resume()

// PUT /sendSms await sim.sendSms(sms: string)

// PUT /setdatalimit await sim.setDataLimit(dataLimit: number)

// PUT /set_group await sim.setGroupt(groupName: string)

// PUT /set_name await sim.setName(name: string)

// PUT /suspend await sim.suspend()

// PUT /test await sim.test()

// PUT /activate await sim.activate()

// PUT /deactivate await sim.deactivate()

For Sims object (`connector.getAllSims()`) all actions are available (will be apply for every sim inside). For example:

typescript const sims = await connector.getAllSims({ groupName: 'Temperature sensors'}) await sims.suspend() ```

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文