-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create simple post and category functions using with Tistory API
- Loading branch information
1 parent
34beaad
commit 391aafe
Showing
10 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Created by saltfactory on 7/15/14. | ||
*/ | ||
var Tistory = require('../lib/tistory'), | ||
logger = require('./logger'), | ||
options = require('./example-options') | ||
|
||
var tistory = new Tistory(options); | ||
//tistory.category.list(null, | ||
// function (err, body) { | ||
// var json = JSON.parse(body); | ||
// logger.debug(json.tistory.item.categories) | ||
// }, {targetUrl: 'rubygalaxy'}); | ||
|
||
|
||
tistory.category.findCategoryId('Ruby', function(err, categoryId){ | ||
if(err){ | ||
logger.error(err.message); | ||
} else { | ||
logger.info("categoryId: " + categoryId); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Created by saltfactory on 7/15/14. | ||
*/ | ||
var tracer = require('tracer') | ||
.colorConsole( | ||
{ | ||
format: [ | ||
"{{timestamp}} (in {{file}}:{{line}}) <{{title}}> {{message}} ", //default format | ||
{ | ||
error: "{{timestamp}} (in {{file}}:{{line}}) <{{title}}> {{message}} \nCall Stack:\n{{stack}}" // error format | ||
} | ||
], | ||
dateformat: "HH:MM:ss.L", | ||
preprocess: function (data) { | ||
data.title = data.title.toUpperCase(); | ||
} | ||
}); | ||
|
||
module.exports = tracer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var Tistory = require('../lib/tistory'), | ||
logger = require('./logger'), | ||
options = require('./example-options'); | ||
|
||
var tistory = new Tistory(options); | ||
|
||
var callback = function (err, body) { | ||
if (err) { | ||
logger.error(err); | ||
} else { | ||
logger.debug(body); | ||
var json = JSON.parse(body); | ||
logger.info(json.tistory); | ||
} | ||
}; | ||
|
||
//tistory.post.list({ | ||
// page: 1, //default:1 | ||
// count: 10, //default:10, max:30 | ||
//// categoryId: //default all categories | ||
// sort: 'id' //default:id(글번호) , date(날짜) | ||
//}, callback); | ||
tistory.post.list({page: 1}, callback); | ||
|
||
//tistory.post.read({postId: 12}, callback); | ||
// | ||
//tistory.post.write({ | ||
// visibility: 0, //default: 0(비공개), 1(보호), 2(공개), 3(발행), 생략시 비공개 | ||
//// published: //UNIX_TIMESTAMP() 값을 넣을 경우, 예약발행 | ||
// categoryId: 0, //default:0 (생략시 분류없음) | ||
// tag: 'nodejs, node-tistory', | ||
// title: 'test', | ||
// content: '본문' | ||
//}, callback); | ||
// | ||
//tistory.post.update({ | ||
// postId: 11, | ||
// visibility: 0, //default: 0(비공개), 1(보호), 2(공개), 3(발행), 생략시 비공개 | ||
// categoryId: 0, //default:0 (생략시 분류없음) | ||
// tag: 'nodejs, node-tistory', | ||
// title: 'test', | ||
// content: '본문 수정' | ||
//}, callback); | ||
// | ||
//tistory.post.attach({uploadedfile: '/Users/saltfactory/Downloads/square.png'}, callback); | ||
// | ||
//tistory.post.delete({postId: 11}, callback); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Created by saltfactory on 7/15/14. | ||
*/ | ||
var request = require('./request'), | ||
util = require('util'); | ||
|
||
/** | ||
* Category | ||
* | ||
* @param options | ||
* @constructor | ||
*/ | ||
function Category(options) { | ||
this.options = options || {}; | ||
} | ||
|
||
Category.prototype.list = function (params, callback, options) { | ||
|
||
var options = util._extend(this.options, options); | ||
var url = options.baseUrl + '/category/list'; | ||
|
||
request.post(url, options, params, callback); | ||
}; | ||
|
||
Category.prototype.findCategoryId = function (name, callback, options) { | ||
this.list(null, function (err, body) { | ||
var json = JSON.parse(body); | ||
var categories = json.tistory.item.categories.category; | ||
|
||
var categoryId; | ||
|
||
categories.forEach(function (category) { | ||
if (category.name == name) { | ||
categoryId = category.id; | ||
} | ||
}); | ||
|
||
if (categoryId == undefined){ | ||
callback(new Error('Not found category')); | ||
} else { | ||
callback(err, categoryId); | ||
} | ||
|
||
|
||
|
||
}, options); | ||
} | ||
|
||
|
||
module.exports = Category; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Created by saltfactory on 7/15/14. | ||
*/ | ||
var Tistory = require('./tistory'); | ||
|
||
exports = module.exports = Tistory; | ||
exports.Strategy = Tistory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Created by saltfactory on 7/15/14. | ||
*/ | ||
var request = require('./request'), | ||
util = require('util'); | ||
/** | ||
* Post | ||
* | ||
* @param options | ||
* @constructor | ||
*/ | ||
function Post(options) { | ||
this.options = options || {}; | ||
} | ||
|
||
/** | ||
* list | ||
* | ||
* @param options | ||
* @param callback | ||
*/ | ||
Post.prototype.list = function (params, callback, options) { | ||
|
||
options = util._extend(this.options, options); | ||
|
||
var url = options.baseUrl + '/post/list'; | ||
|
||
request.post(url, options, params, callback); | ||
}; | ||
|
||
/** | ||
* write | ||
* | ||
* @param params | ||
* @param callback | ||
* @param options | ||
*/ | ||
Post.prototype.write = function (params, callback, options) { | ||
var options = extend(this.options, options); | ||
var url = options.baseUrl + '/post/write'; | ||
|
||
request.post(url, options, params, callback); | ||
}; | ||
|
||
/** | ||
* update | ||
* | ||
* @param params | ||
* @param callback | ||
* @param options | ||
*/ | ||
Post.prototype.update = function (params, callback, options) { | ||
var options = extend(this.options, options); | ||
var url = options.baseUrl + '/post/modify'; | ||
|
||
request.post(url, options, params, callback); | ||
}; | ||
|
||
/** | ||
* delete | ||
* | ||
* @param params | ||
* @param callback | ||
* @param options | ||
*/ | ||
Post.prototype.delete = function (params, callback, options) { | ||
var options = extend(this.options, options); | ||
var url = options.baseUrl + '/post/delete'; | ||
|
||
request.post(url, options, params, callback); | ||
}; | ||
|
||
/** | ||
* attach | ||
* | ||
* @param params | ||
* @param callback | ||
* @param option | ||
*/ | ||
Post.prototype.attach = function (params, callback, options) { | ||
var options = extend(this.options, options); | ||
var url = options.baseUrl + '/post/attach'; | ||
|
||
request.form(url, options, params, callback); | ||
|
||
//// params.uploadedfile = fs.createReadStream(params.uploadedfile); | ||
//// _post(url, options, params, callback); | ||
// | ||
// var r = request.post(url, function (err, reponse, body) { | ||
// callback(err, body); | ||
// }); | ||
// | ||
// var form = r.form() | ||
// form.append('access_token', options.accessToken); | ||
// form.append('targetUrl', options.targetUrl); | ||
// form.append('output', options.output); | ||
// form.append('uploadedfile', fs.createReadStream(params.uploadedfile)); | ||
//// form.append('remote_file', request('http://google.com/doodle.png')) | ||
// | ||
}; | ||
|
||
/** | ||
* read | ||
* | ||
* @param params | ||
* @param callback | ||
* @param options | ||
*/ | ||
Post.prototype.read = function (params, callback, options) { | ||
var options = extend(this.options, options); | ||
var url = options.baseUrl + '/post/read'; | ||
|
||
request.post(url, options, params, callback); | ||
}; | ||
|
||
module.exports = Post; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Created by saltfactory on 7/15/14. | ||
*/ | ||
var request = require('request'), | ||
util = require('util'), | ||
fs = require('fs'); | ||
|
||
|
||
exports.post = function(url, options, params, callback) { | ||
|
||
var form = { | ||
access_token: options.accessToken, | ||
targetUrl: options.targetUrl, | ||
output: options.output | ||
}; | ||
|
||
form = util._extend(form, params); | ||
|
||
request.post(url, {form: form}, function (err, res, body) { | ||
callback(err, body) | ||
}); | ||
}; | ||
|
||
/** | ||
* form | ||
* | ||
* @param url | ||
* @param options | ||
* @param params | ||
* @param callback | ||
*/ | ||
exports.form = function(url, options, params, callback) { | ||
var r = request.post(url, function (err, reponse, body) { | ||
callback(err, body); | ||
}); | ||
|
||
var form = r.form() | ||
form.append('access_token', options.accessToken); | ||
form.append('targetUrl', options.targetUrl); | ||
form.append('output', options.output); | ||
|
||
var keys = Object.keys(params); | ||
keys.forEach(function (key) { | ||
form.append(key, params[key]); | ||
if (key == 'uploadedfile'){ | ||
form.append('uploadedfile', fs.createReadStream(params.uploadedfile)); | ||
} | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Created by saltfactory on 7/15/14. | ||
*/ | ||
var util = require('util'), | ||
Post = require('./post'), | ||
Category = require('./category'); | ||
|
||
function Tistory(options) { | ||
this.options = util._extend({}, options); | ||
this.options.output = options.output || 'json' | ||
this.options.baseUrl = 'https://www.tistory.com/apis/'; | ||
this.post = new Post(this.options); | ||
this.category = new Category(this.options); | ||
} | ||
|
||
module.exports = Tistory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "node-tistory", | ||
"version": "0.1.0", | ||
"description": "Tistory Client module", | ||
"main": "lib/tistory", | ||
"scripts": { | ||
"test": "tistory-test.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/saltfactory/node-tistory.git" | ||
}, | ||
"keywords": [ | ||
"node", | ||
"nodejs", | ||
"api", | ||
"tistory", | ||
"saltfactory" | ||
], | ||
"author": "SungKwang Song", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/saltfactory/node-tistory/issues" | ||
}, | ||
"homepage": "https://github.com/saltfactory/node-tistory", | ||
"devDependencies":{ | ||
"tracer":"latest" | ||
}, | ||
"dependencies":{ | ||
"request":"latest" | ||
} | ||
|
||
} |