UNPKG

3.96 kBSource Map (JSON)View Raw
1{"version":3,"names":[],"mappings":"","sources":["Search.js"],"sourcesContent":["/**\n * @file\n * @copyright 2013 Michael Aufreiter (Development Seed) and 2016 Yahoo Inc.\n * @license Licensed under {@link https://spdx.org/licenses/BSD-3-Clause-Clear.html BSD-3-Clause-Clear}.\n * Github.js is freely distributable.\n */\n\nimport Requestable from './Requestable';\nimport debug from 'debug';\nconst log = debug('github:search');\n\n/**\n * Wrap the Search API\n */\nclass Search extends Requestable {\n /**\n * Create a Search\n * @param {Object} defaults - defaults for the search\n * @param {Requestable.auth} [auth] - information required to authenticate to Github\n * @param {string} [apiBase=https://api.github.com] - the base Github API URL\n */\n constructor(defaults, auth, apiBase) {\n super(auth, apiBase);\n this.__defaults = this._getOptionsWithDefaults(defaults);\n }\n\n /**\n * Available search options\n * @see https://developer.github.com/v3/search/#parameters\n * @typedef {Object} Search.Params\n * @param {string} q - the query to make\n * @param {string} sort - the sort field, one of `stars`, `forks`, or `updated`.\n * Default is [best match](https://developer.github.com/v3/search/#ranking-search-results)\n * @param {string} order - the ordering, either `asc` or `desc`\n */\n /**\n * Perform a search on the GitHub API\n * @private\n * @param {string} path - the scope of the search\n * @param {Search.Params} [withOptions] - additional parameters for the search\n * @param {Requestable.callback} [cb] - will receive the results of the search\n * @return {Promise} - the promise for the http request\n */\n _search(path, withOptions = {}, cb = undefined) {\n let requestOptions = {};\n Object.keys(this.__defaults).forEach((prop) => {\n requestOptions[prop] = this.__defaults[prop];\n });\n Object.keys(withOptions).forEach((prop) => {\n requestOptions[prop] = withOptions[prop];\n });\n\n log(`searching ${path} with options:`, requestOptions);\n return this._requestAllPages(`/search/${path}`, requestOptions, cb);\n }\n\n /**\n * Search for repositories\n * @see https://developer.github.com/v3/search/#search-repositories\n * @param {Search.Params} [options] - additional parameters for the search\n * @param {Requestable.callback} [cb] - will receive the results of the search\n * @return {Promise} - the promise for the http request\n */\n forRepositories(options, cb) {\n return this._search('repositories', options, cb);\n }\n\n /**\n * Search for code\n * @see https://developer.github.com/v3/search/#search-code\n * @param {Search.Params} [options] - additional parameters for the search\n * @param {Requestable.callback} [cb] - will receive the results of the search\n * @return {Promise} - the promise for the http request\n */\n forCode(options, cb) {\n return this._search('code', options, cb);\n }\n\n /**\n * Search for issues\n * @see https://developer.github.com/v3/search/#search-issues\n * @param {Search.Params} [options] - additional parameters for the search\n * @param {Requestable.callback} [cb] - will receive the results of the search\n * @return {Promise} - the promise for the http request\n */\n forIssues(options, cb) {\n return this._search('issues', options, cb);\n }\n\n /**\n * Search for users\n * @see https://developer.github.com/v3/search/#search-users\n * @param {Search.Params} [options] - additional parameters for the search\n * @param {Requestable.callback} [cb] - will receive the results of the search\n * @return {Promise} - the promise for the http request\n */\n forUsers(options, cb) {\n return this._search('users', options, cb);\n }\n}\n\nmodule.exports = Search;\n"],"file":"Search.js"}
\No newline at end of file