Added simple-cw-node.d.ts and tests

This commit is contained in:
Masahiro Wakame 2013-12-06 16:12:57 +09:00
parent 6792863658
commit 22ec65950a
3 changed files with 120 additions and 0 deletions

View File

@ -208,6 +208,7 @@ List of Definitions
* [Sencha Touch](http://www.sencha.com/products/touch/) (by [Brian Kotek](https://github.com/brian428))
* [SharePoint](http://sptypescript.codeplex.com) (by [Stanislav Vyshchepan](http://gandjustas.blogspot.ru) and [Andrey Markeev](http://markeev.com))
* [SignalR](http://www.asp.net/signalr) (by [Boris Yankov](https://github.com/borisyankov))
* [simple-cw-node](https://github.com/astronaughts/simple-cw-node) (by [vvakame](https://github.com/vvakame))
* [Sinon](http://sinonjs.org/) (by [William Sears](https://github.com/mrbigdog2u))
* [SlickGrid](https://github.com/mleibman/SlickGrid) (by [Josh Baldwin](https://github.com/jbaldwin))
* [socket.io](http://socket.io) (by [William Orr](https://github.com/worr))

View File

@ -0,0 +1,33 @@
/// <reference path="../node/node.d.ts" />
/// <reference path="./simple-cw-node.d.ts" />
import CW = require('simple-cw-node');
var client = CW();
var Deferred:any = client.Deferred;
// initialize.
client.init({ token: 'YOUR_TOKEN' });
// get your info.
client.get('me', (err, res) => {
console.log(arguments);
});
// create room.
client.post('rooms', {
name: 'room',
members_admin_ids: '123456789,987654321',
description: 'description'
}, (err, res) => {
console.log('created.');
});
client
.get('me')
.done((res:any) => {
console.log(res.body)
})
.fail((err:any) => {
console.error(err);
});

86
simple-cw-node/simple-cw-node.d.ts vendored Normal file
View File

@ -0,0 +1,86 @@
// Type definitions for simple-cw-node
// Project: https://github.com/astronaughts/simple-cw-node
// Definitions by: vvakame <https://github.com/vvakame>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../superagent/superagent.d.ts" />
declare module "simple-cw-node" {
import superagent = require("superagent");
// TODO 1. update superagent with generics
// TODO 2. create underscore.deffered .d.ts file
// TODO 3. refactor & improve specialized parameter methods
// Merged declaration, ChatWork is both a callable function and a namespace
function ChatWork():ChatWork.ChatWork;
module ChatWork {
interface ChatWorkInitOptions {
token:string;
}
interface ChatWork {
apiVersion:string;
sdkVersion:string;
token:string;
Deferred: any; // _.Deferred
when: any; // _.when
init(options:ChatWorkInitOptions):void;
// http://developer.chatwork.com/ja/endpoint_me.html
get(api:"me", callback:(err:Error, res:superagent.Response)=>void):void;
// http://developer.chatwork.com/ja/endpoint_my.html
get(api:"my/status", callback:(err:Error, res:superagent.Response)=>void):void;
get(api:"my/tasks", callback:(err:Error, res:superagent.Response)=>void):void;
// http://developer.chatwork.com/ja/endpoint_contacts.html
get(api:"contacts", callback:(err:Error, res:superagent.Response)=>void):void;
// http://developer.chatwork.com/ja/endpoint_rooms.html
get(api:"rooms", callback:(err:Error, res:superagent.Response)=>void):void;
post(api:"rooms", args:any, callback:(err:Error, res:superagent.Response)=>void):void;
// can't create specialized parameter
// specialized parameter required compile-time constant string literal
// GET /rooms/{room_id}
// PUT /rooms/{room_id}
// DELETE /rooms/{room_id}
// GET /rooms/{room_id}/members
// PUT /rooms/{room_id}/members
// GET /rooms/{room_id}/messages <- not implemented yet
// POST /rooms/{room_id}/messages
// GET /rooms/{room_id}/messages/{message_id}
// GET /rooms/{room_id}/tasks
// POST /rooms/{room_id}/tasks
// GET /rooms/{room_id}/tasks/{task_id}
// GET /rooms/{room_id}/files
// GET /rooms/{room_id}/files/{file_id}
// General functions
api(method:string, api:string):any; // return same type as _.Deferred()
api(method:string, api:string, callback:(err:Error, res:superagent.Response)=>void):void;
api(method:string, api:string, args:any, callback:(err:Error, res:superagent.Response)=>void):void;
get(api:string):any; // return same type as _.Deferred()
get(api:string, callback:(err:Error, res:superagent.Response)=>void):void;
get(api:string, args:any, callback:(err:Error, res:superagent.Response)=>void):void;
post(api:string):any; // return same type as _.Deferred()
post(api:string, callback:(err:Error, res:superagent.Response)=>void):void;
post(api:string, args:any, callback:(err:Error, res:superagent.Response)=>void):void;
put(api:string):any; // return same type as _.Deferred()
put(api:string, callback:(err:Error, res:superagent.Response)=>void):void;
put(api:string, args:any, callback:(err:Error, res:superagent.Response)=>void):void;
del(api:string):any; // return same type as _.Deferred()
del(api:string, callback:(err:Error, res:superagent.Response)=>void):void;
del(api:string, args:any, callback:(err:Error, res:superagent.Response)=>void):void;
}
}
export = ChatWork;
}