Skip to content

Commit

Permalink
release 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
deflis committed Oct 8, 2015
1 parent a61ed7f commit 5b3d08e
Show file tree
Hide file tree
Showing 14 changed files with 780 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
lib
espowered

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules


4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "docs"]
path = docs
url = https://github.com/deflis/node-narou.git
branch = gh-pages
Empty file modified README.md
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions docs
Submodule docs added at 1fa729
8 changes: 8 additions & 0 deletions esdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"source": "./src",
"destination": "./out",
"test": {
"type": "mocha",
"source": "./test"
}
}
45 changes: 45 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import gulp from "gulp";
import babel from "gulp-babel";
import sourcemaps from "gulp-sourcemaps";
import mocha from "gulp-mocha";
import esdoc from "gulp-esdoc";
import espower from "gulp-espower";
import runSequence from "run-sequence";

const srcFiles = ['src/**/*.js'];
const testFiles = ['test/**/*.js'];
const espoweredDir = './espowered';
const destDir = './lib';

gulp.task('build', ['babel', 'esdoc']);
gulp.task('watch', ['build'], () =>
gulp.watch(srcFiles, ['build', 'test'])
);
gulp.task('test', ['mocha']);

gulp.task('babel', () =>
gulp.src(srcFiles)
.pipe(sourcemaps.init('src/'))
.pipe(babel())
.pipe(sourcemaps.write())
.pipe(gulp.dest(destDir))
);

gulp.task('esdoc', () =>
gulp.src('./src')
.pipe(esdoc({ destination: "./docs" }))
);

gulp.task('espower', () =>
gulp.src(testFiles)
.pipe(sourcemaps.init('test/'))
.pipe(babel())
.pipe(espower())
.pipe(sourcemaps.write())
.pipe(gulp.dest(espoweredDir))
);

gulp.task('mocha', ['babel', 'espower'], () =>
gulp.src(`${espoweredDir}/**/*.js`)
.pipe(mocha())
);
53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "narou",
"version": "0.0.1",
"description": "Narou API Wrapper",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"build": "gulp build",
"watch": "gulp watch",
"test": "gulp test",
"esdoc": "gulp esdoc"
},
"author": "deflis <deflis@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/deflis/node-narou.git"
},
"dependencies": {
"request": "^2.64.0",
"stream-buffers": "^2.2.0"
},
"devDependencies": {
"babel": "^5.8.23",
"esdoc": "^0.4.0",
"esdoc-importpath-plugin": "0.0.1",
"gulp": "^3.9.0",
"gulp-babel": "^5.2.1",
"gulp-esdoc": "^0.1.0",
"gulp-espower": "^1.0.1",
"gulp-mocha": "^2.1.3",
"gulp-sourcemaps": "^1.6.0",
"mocha": "^2.3.3",
"power-assert": "^1.0.1",
"run-sequence": "^1.1.4",
"source-map-support": "^0.3.2"
},
"plugins": [
{
"name": "esdoc-importpath-plugin",
"option": {
"replaces": [
{
"from": "^src/",
"to": "lib"
}
]
}
}
]
}
57 changes: 57 additions & 0 deletions src/fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

/**
* {@link SearchBuilder#fields}メソッドにパラメータを指定する際のヘルパー。
* @typedef {Object} Fields
* @property {number} title 小説名
* @property {string} ncode Nコード
* @property {string} userid 作者のユーザID(数値)
* @property {string} writer 作者名
* @property {string} story 小説のあらすじ
* @property {string} genre ジャンル
* @property {string} keyword キーワード
* @property {string} general_firstup 初回掲載日
* @property {string} general_lastup 最終掲載日
* @property {string} noveltype 連載の場合は1、短編の場合は2
* @property {string} end 連載の場合は1、短編の場合は2
* @property {string} general_all_no 全掲載話数です。短編の場合は1です。
* @property {string} length 全掲載話数です。短編の場合は1です。
* @property {string} time 読了時間(分単位)です。読了時間は小説文字数÷500を切り上げした数値です。
* @property {string} isstop 長期連載中は1、それ以外は0です。
* @property {string} pc_or_k 1はケータイのみ、2はPCのみ、3はPCとケータイで投稿された作品です。対象は投稿と次話投稿時のみで、どの端末で執筆されたかを表すものではありません。
* @property {string} global_point 総合得点(=(ブックマーク数×2)+評価点)
* @property {string} fav_novel_cnt ブックマーク数
* @property {string} review_cnt レビュー数
* @property {string} all_point 評価点
* @property {string} all_hyoka_cnt 評価者数
* @property {string} sasie_cnt 挿絵の数
* @property {string} kaiwaritu 会話率
* @property {string} novelupdated_at 小説の更新日時
* @property {string} updated_at 最終更新日時(注意:システム用で小説更新時とは関係ありません)
*/
export default {
title: "t",
ncode: "n",
userid: "u",
writer: "w",
story: "s",
genre: "g",
keyword: "k",
general_firstup: "gf",
general_lastup: "gl",
noveltype: "nt",
end: "e",
general_all_no: "ga",
length: "l",
time: "ti",
isstop: "i",
pc_or_k: "p",
global_point: "gp",
fav_novel_cnt: "f",
review_cnt: "r",
all_point: "a",
all_hyoka_cnt: "ah",
sasie_cnt: "sa",
kaiwaritu: "ka",
novelupdated_at: "nu",
updated_at: "ua"
}
38 changes: 38 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import SearchBuilder from "./search-builder";
import SearchBuilderR18 from"./search-builder-r18";
import fields from "./fields";

/**
* なろうAPI
* @global
*/
export default class Index {

/**
* {@link SearchBuilder#fields}メソッドにパラメータを指定する際のヘルパー。
* @type {Fields}
*/
static get fields() { return fields; };

/**
* 検索
* @param {string} [word] - 検索ワード
* @returns {SearchBuilder}
*/
static search(word = null) {
var builder = new SearchBuilder();
if (word != null) builder.word(word);
return builder;
};

/**
* 検索
* @param {string} [word] - 検索ワード
* @returns {SearchBuilder}
*/
static searchR18(word = null) {
var builder = new SearchBuilderR18();
if (word != null) builder.word(word);
return builder;
};
}
84 changes: 84 additions & 0 deletions src/narou-search-results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

/**
* なろう小説API検索結果
* @class NarouSearchResults
*/
export default class {
/**
* @constractor
* @private
*/
constructor(result, params) {
let count = result.shift().allcount;

let limit = 20;
if (params.hasOwnProperty("lim")) {
limit = params.lim;
}

let start = 0;
if (params.hasOwnProperty("start")) {
start = params.start;
}

/**
* 検索結果数
* @type {number}
*/
this.allcount = count;
/**
* 結果表示上限数
* @type {number}
*/
this.limit = limit;
/**
* 結果表示開始数
* @type {number}
*/
this.start = start;
/**
* 結果表示ページ数
* @type {number}
*/
this.page = start / limit;
/**
* 結果数
* @type {number}
*/
this.length = result.length;
/**
* 検索結果
* @type {NarouSearchResult[]}
*/
this.values = result;
}
};

/**
* @typedef {Object} NarouSearchResult
* @property {number} title 小説名
* @property {string} ncode Nコード
* @property {number} userid 作者のユーザID(数値)
* @property {string} writer 作者名
* @property {string} story 小説のあらすじ
* @property {number} genre ジャンル
* @property {string} keyword キーワード
* @property {string} general_firstup 初回掲載日 YYYY-MM-DD HH:MM:SSの形式
* @property {string} general_lastup 最終掲載日 YYYY-MM-DD HH:MM:SSの形式
* @property {number} noveltype 連載の場合は1、短編の場合は2
* @property {number} end 連載の場合は1、短編の場合は2
* @property {number} general_all_no 全掲載話数です。短編の場合は1です。
* @property {number} length 全掲載話数です。短編の場合は1です。
* @property {number} time 読了時間(分単位)です。読了時間は小説文字数÷500を切り上げした数値です。
* @property {number} isstop 長期連載中は1、それ以外は0です。
* @property {number} pc_or_k 1はケータイのみ、2はPCのみ、3はPCとケータイで投稿された作品です。対象は投稿と次話投稿時のみで、どの端末で執筆されたかを表すものではありません。
* @property {number} global_point 総合得点(=(ブックマーク数×2)+評価点)
* @property {number} fav_novel_cnt ブックマーク数
* @property {number} review_cnt レビュー数
* @property {number} all_point 評価点
* @property {number} all_hyoka_cnt 評価者数
* @property {number} sasie_cnt 挿絵の数
* @property {number} kaiwaritu 会話率
* @property {number} novelupdated_at 小説の更新日時
* @property {number} updated_at 最終更新日時(注意:システム用で小説更新時とは関係ありません)
*/
55 changes: 55 additions & 0 deletions src/narou.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import request from 'request';
import zlib from 'zlib';
import {WritableStreamBuffer} from 'stream-buffers';
import NarouSearchResults from './narou-search-results.js';

/**
* なろう小説APIへのリクエストを実行する
* @class NarouNovel
* @private
*/
export default class NarouNovel {

/**
* なろう小説APIへの検索リクエストを実行する
* @param params クエリパラメータ
* @param endpoint APIエンドポイント
* @returns {Promise<NarouSearchResults>} 検索結果
*/
static execute(params, endpoint = 'http://api.syosetu.com/novelapi/api/') {

let query = Object.assign(params, {out: 'json'});

var req = request({
method: 'GET',
url: endpoint,
qs: query,
});
var stream = new WritableStreamBuffer();


if (query.gzip) {
req = req.pipe(zlib.createUnzip());
}

var pipe = req.pipe(stream);

var promise = new Promise((resolve, failure) =>
pipe.on('error', e => failure(e))
.on('finish', () => resolve(stream.getContents()))
);

return promise
.then((text) => JSON.parse(text))
.then((json) => new NarouSearchResults(json, params));
}

static executeNovel(params) {
return this.execute(params, 'http://api.syosetu.com/novelapi/api/');
}

static executeNovel18(params) {
return this.execute(params, 'http://api.syosetu.com/novel18api/api/');
}
}

Loading

0 comments on commit 5b3d08e

Please sign in to comment.