npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xizhibei/getui-rest-sdk

v1.0.0

Published

Getui rest api for node.js, in TypeScript

Downloads

8

Readme

Getui Rest SDK

Build Status npm version Dependency Status npm Greenkeeper badge

Getting Started

详细原接口文档:http://docs.getui.com/server/rest/start/

除了原文档中的接口,其中另外还提供了 pushMessageByTag 方法,可以用来发送按 tag 或者说按 topic 方式推送数据。

Installing

npm i @xizhibei/getui-rest-sdk --save

建议使用 vscode 开发,typing 代码提示更加完善

Usage

以下样例均使用 TypeScript 展示,可轻易修改为 ES6

初始化
const option: GetuiOption = {
  appId: APP_ID,
  appSecret: APP_SECRET,
  appKey: APP_KEY,
  masterSecret: MASTER_SECRET,
};

const gt = new Getui(option);
初始化透传模板
const alert = new Alert();
alert.title = 'Title: push test';
alert.body = `Body: push test`;

const payload = JSON.stringify({
  message: `Payload message: push message test`,
});

const apnsInfo = new ApnsInfo();
apnsInfo.alert = alert;
apnsInfo.customMsg = { payload };

const template = new TransmissionTemplate();
template.transmissionContent = payload;
单个推送
const message = new SingleMessage();
message.template = template;
message.apnsInfo = apnsInfo;

const target = <Target>{
  cid: GETUI_CID,
};

const ret = await gt.pushMessageToSingle(message, target);
APP推送
const message = new AppMessage();
message.template = template;
message.apnsInfo = apnsInfo;
message.conditions = [
  new Condition(ConditionKey.TAG, [testTag], CondOptType.OR),
  new Condition(ConditionKey.Region, [Region.北京市], CondOptType.OR),
  new Condition(ConditionKey.PHONE_TYPE, [PhoneType.IOS], CondOptType.OR),
];

const ret = await gt.pushMessageToApp(message)
按 tag 推送
const message = new TagMessage();
message.template = template;
message.apnsInfo = apnsInfo;
message.tag = testTag;

const ret = await gt.pushMessageByTag(message);

更多样例,请见测试代码

Test

测试基于 nock 来模拟服务器,但是你可以设置环境变量与真实个推服务器测试进行交互,以下测试账号数据需要用你自己的

export GETUI_APP_ID=<app id>
export GETUI_APP_SECRET=<app secret>
export GETUI_APP_KEY=<app key>
export GETUI_MASTER_SECRET=<master secret>
export GETUI_CID=<cid>
export GETUI_TEST_TAG=<tag>

export GETUI_TEST_USE_REAL_CONNECTION=true

export DEBUG=getui

npm test

TODO

  • 测试代码完善

License

This project is licensed under the MIT License - see the LICENSE file for details