0.1.1 • Published 10 years ago

node-tistory v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

node-tistory

node-tistoryTistory의 오픈 API를 사용하기 위한 Node.js 모듈이다.

Install global module

node-tistory는 global로 설치하기 위해서 다음과 같이 npm install -g로 설치할 수 있다.

npm install -g node-tistory

글로벌 설치한 후 tistory 명령어를 사용할 수 있다.

tistory -help

Install local module

npm install node-tistory

local module로 설치할 경우 다음과 같이 사용할 수 있다.

var Tistory = require('node-tistory');

Global configuration file

node-tistory$HOME/.tistory.json 파일을 글로벌 설정 파일로 읽어들인다. node-tistory를 사용할 때 필요한 옵션정보를 .tistory.json에 미리 저장해두면 항상 이 설정 파일을 먼저 읽어서 옵션정보로 설정한다.

echo '{
    "targetUrl": "Tistory URL",
    "access_token": "Tistory API access_token",
    "output": "json"
}' > ~/.tistory.json

Tistory API

Tistory에서 제공하고 있는 오픈 API 가이드 를 참고하면 된다.

node-tistory API interface

node-tistory 에서는 Tistory의 오픈 API를 간단하게 바로 사용할 수 있도록 메소드 형태의 interface를 제공하고 있다.

모듈인터페이스Tistory API설명
bloginfo/apis/blog/info블로그 정보
postlist/apis/post/list글 목록
read/apis/post/read글 보기
write/apis/post/write글 쓰기
modify/apis/post/modify글 수정
attach/apis/post/attach파일첨부
categorylist/apis/category/list분류 목록
find분류 검색

모든 interface 메소드는 params, callback을 인자값으로 사용한다. params는 Object 형태이고 callback은 err,body,res 값을 받는 함수 형태이다. params의 key는 Tistory 오픈 API의 Request Parameter의 이름과 동일하다.

e.g. 티스토리 블로그 http://blog.saltfactory.net 정보 보기

var params = {
  targetUrl:'blog.satlfactory.net'
};

var callback = function(err, body, res){
  console.log(body);
};

tistory.blog.info(params, callback);

e.g. http://blog.saltfactory.net의 글 목록보기

var params = {
  page: 1,
  count: 10
};

tistory.post.list(params, function(err, body, res){
  console.log(body);
});

node-tistory interface parameters

node-tistory의 인터페이스의 파라미터는 Object 형태로 지정한다.

var params = {
  'targetUrl':'blog.saltfactory.net'
};

tistory.blog.info (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlStringhttp://saltfactory.tistory.com 과 같이 1차 도메인 경우 saltfactory, http://blog.saltfactory.net 과 같이 2차 도메인일 경우 blog.saltfactory.net필수
output'json','xml'기본값 'json'옵션
없음없음파라미터 없이 콜백함수만 사용 가능없음

tistory.post.list (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlString블로그 URL필수
output'json','xml'기본값 'json'옵션
pageNumber해당 페이지 글 목록, 기본값 1옵션
count1~30페이지당 글 갯수, 기본값 10옵션
categoryIdNumber분류에 해당하는 글 목록, 기본값 전체옵션
sort'id' or 'date''id'는 글번호, 'date'는 작성날짜, 기본값 id옵션

tistory.post.read (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlString블로그 URL필수
postIdNumber글 번호필수
output'json','xml'기본값 'json'옵션

tistory.post.write (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlString블로그 URL필수
titleString글 제목필수
contentString글 내용옵션
visibility0,1,2,30:비공개, 1:보호, 2:공개, 3:발행, 생략시 0옵션
publishedStringUNIX_TIMESTAMP() 예약발송옵션
tagString,를 사용하여 여러개 태그 문자열옵션
output'json','xml'기본값 'json'옵션

tistory.post.modify (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlString블로그 URL필수
postIdNumber수정할 글 번호필수
titleString글 제목필수
contentString글 내용옵션
visibility0,1,2,30:비공개, 1:보호, 2:공개, 3:발행, 생략시 0옵션
publishedStringUNIX_TIMESTAMP() 예약발송옵션
tagString,를 사용하여 여러개 태그 문자열옵션
output'json','xml'기본값 'json'옵션

tistory.post.attach (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlString블로그 URL필수
uploadedfileString파일경로필수
output'json','xml'기본값 'json'옵션

tistory.category.list (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlString블로그 URL필수
output'json','xml'기본값 'json'옵션

tistory.category.find (params, callback)

params설명필요
access_tokenStringOAuth 2.0 인증 후 획득한 access_token필수
targetUrlString블로그 URL필수
nameString분류명필수
output'json','xml'기본값 'json'옵션

Tistory의 모든 API는 access_token, targetUrl 그리고 output 파라미터를 사용하기 때문에 node-tistory의 global configuration file인 $HOME/.tistory.json에 다음과 같이 저장해두면 파라미터로 설정하지 않아도 된다.

{
  "targetUrl": "blog.saltfactory.net",
  "access_token": "access_token",
  "output": "json"
}
var params = {
  page:1,
  count:10
};

tistory.post.list(params, function(err,body){
  console.log(body);
});

tistory command

node-tistorynpm install -g로 설치를 하면 tistory 명령어를 사용할 수 있다. 만약 $HOME/.tistory.json 파일에 설정이 저장된 상태라고 생각하면 명령어 사용은 다음과 같다.

명령어 옵션설명
-help, --h도움말
-prettyindent 추가해서 JSON 프린트
파라미터 옵션설명
-파라미터명파라미터의 이름 앞에 -를 붙이고 뒤에 값을 지정

tistory.blog.info

tistory blog info -pretty

tistory.post.list

tistory post list -page 1 -count 10 -output json

tistory.post.read

tistory post read 105 --pretty

tistory.post.write

tistory post write -title 안녕하세요 -content 테스트입니다. -tag 태그1,태그2

tistory.post.modify

tistory post write -postId 105 -title 안녕하세요 -content 테스트입니다. -tag 태그1,태그2

tistory.post.attach

tistory post attach -file /Users/saltfactory/Documents/test.png

tistory.category.list

tistory category list --pretty

tistory.category.find

tistory category find Node.js --pretty

Copyright and License

The MIT License (MIT)

Copyright (c) 2014 SungKwang Song

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.