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

yhsd-api

v2.1.2

Published

Youhaosuda API SDK for node.

Downloads

23

Readme

yhsd-api-node

友好速搭 API SDK for Node(>= v6) 支持Promise依赖bluebird

Build status Coverage Status Dependency Status

安装

$ npm install --save yhsd-api

授权

var Yhsd = require('yhsd-api');

/**
 * 初始化
 * @param {object} options
 * @param {string} options.appKey 应用的appKey
 * @param {string} options.appSecret 应用的appSecret
 * @param {string} options.callbackUrl 用于开放应用,应用管理后台设置的回调地址
 * @param {string} options.redirectUrl 用于开放应用,可选,自定义回调地址,默认同 callbackUrl
 * @param {Array} options.scope 用于开放应用,可选,权限范围,默认为 ['read_basic']
 * @param {Boolean} options.private 可选,是否为私有应用,默认为 false
 * @param {string} options.protocol 可选,'http'或者'https',默认'https'
 * @param {string} options.host 可选,授权接口域名,默认'apps.youhaosuda.com'
 * @constructor
 */
var auth = new Yhsd.Auth(options);

/**
 * 验证 Hmac
 * @param {object} queryObj 回调地址的参数对象
 * @return {boolean}
 */
auth.verifyHmac(queryObj);

/**
 * 获取应用授权页面地址,用于开放应用
 * @param {string} shopKey
 * @param {string} [state]
 * @return {string}
 */
auth.getAuthorizeUrl(shopKey, state);

/**
 * 获取 token
 * @param {string} [code],用于开放应用
 * @returns {Object<Promise>}
 */
auth.getToken(code);

详见 https://docs.youhaosuda.com/app/s/553e33880abc3e6f3e000026

例子

var Yhsd = require('yhsd-api');
var auth = new Yhsd.Auth({
    appKey: '8fce436b6fe74d5c8e2317**********',
    appSecret: '3c91e9bd912145de953e0d**********',
    private: true
});
auth.getToken().then(function (token) {
    console.log(token);
});

使用 API

var Yhsd = require('yhsd-api');

/**
 * 初始化
 * @param {string} token
 * @param {object} option
 * @param {string} option.protocol 可选,'http'或者'https',默认'https'
 * @param {string} option.host 可选,开发 API 接口域名,默认'api.youhaosuda.com'
 * @param {function} option.getRequestCount 获取请求数函数
 * @param {function} option.saveRequestCount 存储请求数函数
 * @constructor
 */
var api = new Yhsd.Api(token);

/**
 * 发送 GET 请求
 * @param {string} path
 * @param {object} [query]
 * @returns {Object<Promise>}
 */
api.get(path, query);

/**
 * 发送 PUT 请求
 * @param {string} path
 * @param {object} data
 * @returns {Object<Promise>}
 */
api.put(path, data);

/**
 * 发送 POST 请求
 * @param {string} path
 * @param {object} data
 * @returns {Object<Promise>}
 */
api.post(path, data);

/**
 * 发送 DELETE 请求
 * @param {string} path
 * @returns {Object<Promise>}
 */
api.delete(path);

详见 https://docs.youhaosuda.com/app/553e335f0abc3e6f3e000023

例子

var Yhsd = require('yhsd-api');
var reqCountMap = {};
var api = new Yhsd.Api('2be799bf87144c2fbb881a**********',{
  getRequestCount: function (token){
    return reqCountMap[token];
  },
  saveRequestCount: function (token, count){
    reqCountMap[token] = count;
    return count;
  }
});
// 获取顾客列表
api.get('customers', { fields: 'id,name' }).then(function (data) {
	console.log(data);
});
// 获取指定顾客
api.get('customers/100').then(function (data) {
    console.log(data);
});

WebHook

var Yhsd = require('yhsd-api');

/**
 * 初始化
 * @param {string} webHookToken
 * @constructor
 */
var webHook = new Yhsd.WebHook(webHookToken);

/**
 * 验证 Hmac
 * @param {string} hmac
 * @param {string} bodyData 响应体数据
 * @return {boolean}
 */
webHook.verifyHmac(hmac, bodyData);