Code coverage report for wechat-enterprise/lib/api_menu.js

Statements: 100% (19 / 19)      Branches: 100% (0 / 0)      Functions: 100% (6 / 6)      Lines: 100% (19 / 19)      Ignored: none     

All files » wechat-enterprise/lib/ » api_menu.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 1381 1 1 1                                                                                                 1 1           1 1 1                                                                     1 1           1 1 1                                         1 1           1 1 1    
var urllib = require('urllib');
var util = require('./util');
var wrapper = util.wrapper;
var postJSON = util.postJSON;
 
/**
 * 创建自定义菜单
 * 详细请看:<http://qydev.weixin.qq.com/wiki/index.php?title=创建应用菜单>
 *
 * Menu:
 * ```
 * {
 *  "button":[
 *    {
 *      "type":"click",
 *      "name":"今日歌曲",
 *      "key":"V1001_TODAY_MUSIC"
 *    },
 *    {
 *      "name":"菜单",
 *      "sub_button":[
 *        {
 *          "type":"view",
 *          "name":"搜索",
 *          "url":"http://www.soso.com/"
 *        },
 *        {
 *          "type":"click",
 *          "name":"赞一下我们",
 *          "key":"V1001_GOOD"
 *        }]
 *      }]
 *    }
 *  ]
 * }
 * ```
 * Examples:
 * ```
 * api.createMenu(menu, callback);
 * ```
 * Callback:
 *
 * - `err`, 调用失败时得到的异常
 * - `result`, 调用正常时得到的对象
 *
 * Result:
 * ```
 * {"errcode":0,"errmsg":"ok"}
 * ```
 * @param {Object} menu 菜单对象
 * @param {Function} callback 回调函数
 */
exports.createMenu = function (menu, callback) {
  this.preRequest(this._createMenu, arguments);
};
 
/*!
 * 创建自定义菜单的未封装版本
 */
exports._createMenu = function (menu, callback) {
  var url = this.prefix + 'menu/create?agentid=' + this.agentid + '&access_token=' + this.token.accessToken;
  urllib.request(url, postJSON(menu), wrapper(callback));
};
 
/**
 * 获取菜单
 * 详细请看:<http://qydev.weixin.qq.com/wiki/index.php?title=获取菜单列表>
 *
 * Examples:
 * ```
 * api.getMenu(callback);
 * ```
 * Callback:
 *
 * - `err`, 调用失败时得到的异常
 * - `result`, 调用正常时得到的对象
 *
 * Result:
 * ```
 * // 结果示例
 * {
 *  "menu": {
 *    "button":[
 *      {"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","sub_button":[]},
 *      {"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","sub_button":[]},
 *      {"name":"菜单","sub_button":[
 *        {"type":"view","name":"搜索","url":"http://www.soso.com/","sub_button":[]},
 *        {"type":"view","name":"视频","url":"http://v.qq.com/","sub_button":[]},
 *        {"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]
 *      }
 *    ]
 *  }
 * }
 * ```
 * @param {Function} callback 回调函数
 */
exports.getMenu = function (callback) {
  this.preRequest(this._getMenu, arguments);
};
 
/*!
 * 获取自定义菜单的未封装版本
 */
exports._getMenu = function (callback) {
  var url = this.prefix + 'menu/get?agentid=' + this.agentid + '&access_token=' + this.token.accessToken;
  urllib.request(url, {dataType: 'json'}, wrapper(callback));
};
 
/**
 * 删除自定义菜单
 * 详细请看:<http://mp.weixin.qq.com/wiki/index.php?title=自定义菜单删除接口>
 * Examples:
 * ```
 * api.removeMenu(callback);
 * ```
 * Callback:
 *
 * - `err`, 调用失败时得到的异常
 * - `result`, 调用正常时得到的对象
 *
 * Result:
 * ```
 * {"errcode":0,"errmsg":"ok"}
 * ```
 * @param {Function} callback 回调函数
 */
exports.removeMenu = function (callback) {
  this.preRequest(this._removeMenu, arguments);
};
 
/*!
 * 删除自定义菜单的未封装版本
 */
exports._removeMenu = function (callback) {
  var url = this.prefix + 'menu/delete?agentid=' + this.agentid + '&access_token=' + this.token.accessToken;
  urllib.request(url, {dataType: 'json'}, wrapper(callback));
};