1.3.0 • Published 5 years ago

icafe-api v1.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

icafe-api

NPM version Prettier Conventional Commits

nodejs's sdk for icafe api,对于 icafe 官方 web api 的封装

Installation

npm install icafe-api
# or use yarn
yarn add icafe-api

Usage

import { BatchCreate } from 'icafe-api'

BatchCreate.fetch({
  spaceId: 'icafe-api'
  username: '',
  password: '',
  issues: [
    {
      title: 'test', //主题
      detail: '我是新建的卡片<p>另起一段换行<br></p>', //内容
      type: 'Bug', //类型
      parent: 40, //上级卡片序号,成为父卡片的子卡片
      fields: {
        负责人: 'wudanping,guoxu07', //中文名或邮箱名
        流程状态: '新建', //流程状态名
        属性名: '属性值', //属性名对应属性值
        估算工时: '0.1' //(举例属性名对应属性值 )
      },
      notifyEmails: ['wudanping@baidu.com', 'lihang11@baidu,com'], //要通知的邮件地址
      creator: '创建人的邮箱前缀,如不传则是当前api用户',
      comment: '评论' //需给卡片添加的评论内容
    },
    {
      title: '主题',
      detail: '内容',
      type: '类型',
      parent: 上级卡片序号,
      fields: {
        负责人: '中文名或邮箱名',
        流程状态: '流程状态名',
        属性名: '属性值'
      },
      notifyEmails: ['要通知的邮件地址', '要通知的邮件地址'],
      creator: '创建人的邮箱前缀,如不传则是当前api用户',
      comment: '评论'
    }
  ]
}).end((err, res) => {
  // res.body
})

BatchCreate.fetch(/* ... */)
  .then(res => {
    // res.body
  })

如何设置用户名、密码等默认参数

设置默认值在 环境变量 中或读取 git config username 或 package.json icafe 字段 (优先级逐渐升高) 中, 其中 icafe 用户名和密码, 在 http://icafe.baidu.com/users/virtual 中查看.

注意: 上述网站中的密码不能直接使用,需要经过 decodeURIComponent('password') 后, 才能赋值使用

如:

{
  "icafe": {
    "spaceId": "icafe-api",
    "username": "yucong02",
    "password": "..."
  }
}
{
  username: process.env.ICAFE_USERNAME,
  password: process.env.ICAFE_PASSWORD,
  spaceId: process.env.ICAFE_SPACE_ID
  ...fromPkg
}

或者直接修改

import { FetchAble } from 'icafe-api'

// 注意!这种方式会影响其他地方的 defaultData
FetchAble.defaultData = {
  // ...
}

因此,推荐创建独立环境来覆写 default Data

import { create } from 'icafe-api'

const { BatchCreate } = create({
  data: {
    //...
  }
})

BatchCreate.fetch() // ....

timeout

两种方式进行设置

  • 每个分别设置
BatchCreate.fetch(
  {
    // ...
    issues: []
  },
  {
    // mill second (default: 10000)
    timeout: 10000
  }
)
  • 全局设置
FetchAble.defaultOptions = {
  timeout: 10000
}

API

create

创建独立环境

Parameters

Returns {FetchAble: Function, BatchCreate: FetchAble, Card: FetchAble, CardUpdate: FetchAble, Comment: FetchAble, History: FetchAble, Plan: FetchAble, PlanCreate: FetchAble, Plans: FetchAble, PlanUpdateDate: FetchAble, ProcessStatus: FetchAble}

FetchAbleOptions

Type: {}

Parameters

  • data {object} (optional, default {})
  • context {string} (optional, default 'http://icafe.baidu.com/api')
  • options {object} (optional, default {})

BatchCreate

批量新建卡片

Examples

BatchCreate.fetch({ spaceId: 'icafe-api', username: 'abc', password: 'abc' })

Card

卡片相关 注意!链接中的 u 对应 username, pw 对应 password

Examples

Card.fetch({ spaceId: 'icafe-api', sequence: null, username: '', password: '' })

CardUpdate

修改单张卡片 注意!链接中的 u 对应 username, pw 对应 password

Examples

CardUpdate.fetch({
  spaceId: 'icafe-api',
  username: 'abc',
  password: 'abc',
  sequence: '106',
  fields: ['所属计划=12345', '估时=1']
})

Comment

获取卡片评论

Examples

Comment.fetch({ spaceId: 'icafe-api', username: 'abc', password: 'abc', sequence: '106' })

History

查询 Issue(卡片)历史

Examples

History.fetch({
  spaceId: 'icafe-api',
  username: 'abc',
  password: 'abc',
  sequences: ['106']
})

Plan

查询单个计划

Examples

Plan.fetch({
  spaceId: 'icafe-api',
  username: 'abc',
  password: 'abc'
  // ...
})

PlanCreate

新建单个计划

Examples

PlanCreate.fetch({
  spaceId: 'icafe-api',
  username: 'abc',
  password: 'abc'
  // ...
})

Plans

获取空间内所有计划

Examples

Plans.fetch({
  spaceId: 'icafe-api',
  username: 'abc',
  password: 'abc'
})

PlanUpdateDate

编辑计划的时间

Examples

PlanUpdateDate.fetch({
  spaceId: 'icafe-api',
  username: 'abc',
  password: 'abc',
  planBoxId: 'xx'
  // ...
})

ProcessStatus

查询 Issue(卡片)流程状态

Examples

ProcessStatus.fetch({
  spaceId: 'icafe-api',
  username: 'abc',
  password: 'abc',
  sequence: '106'
})

Development

Swagger

use test2doc for generating swagger after test.

npm test
http-server .
# visit `swagger-ui.html`

Authors

This library is written and maintained by imcuttle, moyuyc95@gmail.com.

License

MIT