3.0.2 • Published 7 years ago

coding-sdk v3.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Coding SDK

github npm npm codecov Travis-CI codebeat badge

已经疯狂得不能用代码行数(总计56行,包含空行和debug)来衡量该项目了,代码仅有 1,375字节(净化后)。

五十六个民族五十六朵花。啦啦啦~

TOC

安装

yarn add coding-sdk
# or npm i -S coding-sdk

本项目中使用 camelCase 驼峰命名法则。

Scope 说明

scope 参数应传入数组如: ['user', 'project', 'team']

scope 名称说明授权
user授权获取用户信息(用户名称,头像,tag,email,动态 )
user:email授权获取用户的email )
notification授权读取通知信息,包含email通知读写
social授权读取冒泡列表,好友列表
social:tweet授权发送冒泡,冒泡操作(点赞、评论、删除)读写
social:message授权读取、发送私信、私信语音读写
project授权项目信息、项目列表,仓库信息,公钥列表、成员,任务列表
project:members授权项目管理者增、删、改项目成员,退出项目读写
project:task授权任务操作,包含增、删、改读写
project:file授权文件,包含增、删、改读写
project:depot获取 commit 信息,分支操作,MR/PR, LineNotes, fork, webhook 等操作读写
project:key授权操作部署公钥、个人公钥读写
team获取团队相关基本信息

Oauth 使用 示例

const SDK = require('coding-sdk');
// 初始化实例:
const coding = new SDK({
  clientId: 'xxx',
  clientSecret: 'xxx',
  callback: 'http://localhost/coding/callback'
});

// 获取 OAuth 鉴权链接 URL
console.log(coding.url());
// 如: https://coding.net/oauth_authorize.html?client_id=xxx&redirect_uri=xxx&response_type=code&scope=user
// 登录后跳转回 callback URL,获取其中的 code 字段

// 注意包裹在 async 内, 或者用 Promise.then(res=>{ console.log(res.data) }) 来获取返回 json 结果
const { data } = await coding.get('oauth/access_token', {
  grant_type: 'authorization_code',
  code: 'xxxxxx'
});
/*
{ access_token: 'xxxxx',
  refresh_token: 'xxxxx',
  expires_in: '864000' }
*/

Token 使用 示例

const coding = new SDK({
  user: 'willin',
  token: 'xxxxxx'
});

const { data } = await coding.delete('user/XXX/project/XXX/task/XXX');
/*
{ code: 0, data: true }
*/

一些公开接口 使用 示例

const coding = new SDK();

const { data } = await coding.get('user/key/willin')
/*
{
  code: 0,
  data: { ... }
}
*/

补充示例

获取 OAuth 登录地址

coding.url();

获取 access_token

const data = await coding.get('oauth/access_token', {
  grantType: 'authorization_code',
  code: 'xxxxxx'
}).then(res=>res.data);
/*
返回数据格式:
{
  access_token: "xxxxxxx",
  refresh_token: "xxxxxx",
  expires_in: "86382817"
}
*/

License

Apache 2.0

通过支付宝捐赠:

qr

3.0.2

7 years ago

3.0.1

8 years ago

3.0.0

8 years ago

1.0.0

8 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.1.1

9 years ago