diff --git a/README.md b/README.md
index d4d03e6..68d8c55 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-JavaScript library for Typetalk
+JavaScript client library for Typetalk
======================
[typetalk-js](https://github.com/shoito/typetalk-js) aims to provide a complete, asynchronous client library for the [Typetalk API](http://developers.typetalk.in/api.html).
@@ -24,7 +24,7 @@ Support Promises
Use a polyfill script tag:
-
+
The global variable Promise becomes available after the above script tag.
@@ -46,7 +46,7 @@ and then include it in your pages with ``
See also
-- [Typetalk for Developers](http://developers.typetalk.in/index.html)
+- [Typetalk for Developers](https://developer.nulab-inc.com/docs/typetalk)
- [typetalk-js API documentation](http://shoito.github.io/typetalk-js/Typetalk.html)
### Setup (Client Credentials as Grant Type)
@@ -56,7 +56,7 @@ See also
var typetalk = new Typetalk({
'client_id': 'YOUR_CLIENT_ID__CLIENT_CREDENTIALS',
'client_secret': 'YOUR_CLIENT_SECRET__CLIENT_CREDENTIALS',
- 'scope': 'topic.read,topic.post,my'
+ 'scope': 'topic.read,topic.post,topic.write,topic.delete,my'
});
### Setup (Authorization Code as Grant Type)
@@ -65,7 +65,7 @@ See also
'client_id': 'YOUR_CLIENT_ID__AUTHORIZATION_CODE',
'client_secret': 'YOUR_CLIENT_SECRET__AUTHORIZATION_CODE',
'redirect_uri': 'https://YOUR_APP_DOMAIN/provider_cb',
- 'scope': 'topic.read,topic.post,my'
+ 'scope': 'topic.read,topic.post,topic.write,topic.delete,my'
});
### Get access token using client credentials
@@ -102,7 +102,7 @@ See also
## See also
- [Typetalk](http://www.typetalk.in)
-- [Typetalk for Developers](http://developers.typetalk.in/)
+- [Typetalk for Developers](https://developer.nulab-inc.com/docs/typetalk/)
- [JavaScript Promises: There and Back Again](http://www.html5rocks.com/en/tutorials/es6/promises/)
- [Promise](https://www.promisejs.org/)
diff --git a/bower.json b/bower.json
index 474f5f8..2f8699e 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "typetalk-js",
- "version": "0.1.3",
+ "version": "0.2.0",
"main": "typetalk.js",
"ignore": [
"**/.*",
@@ -19,6 +19,6 @@
"dependencies": {
},
"devDependencies": {
- "bluebird": "~1.2.4"
+ "promise": "~5.0.0"
}
}
diff --git a/example/client.js b/example/client.js
index f08e5c2..b6d5238 100644
--- a/example/client.js
+++ b/example/client.js
@@ -1,6 +1,6 @@
// Setup
// npm install typetalk-js --save
-var Promise = require('bluebird'),
+var Promise = require('promise'),
Typetalk = require('typetalk-js');
var typetalk = new Typetalk({
diff --git a/package.json b/package.json
index 7e4f298..0ef75aa 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "typetalk-js",
"title": "typetalk-js",
"description": "JavaScript library for Typetalk",
- "version": "0.1.3",
+ "version": "0.2.0",
"main": "typetalk.js",
"homepage": "https://github.com/shoito/typetalk-js",
"author": {
@@ -30,18 +30,18 @@
}
],
"dependencies": {
- "bluebird": "~1.2.4",
+ "promise": "~5.0.0",
"xmlhttprequest": "~1.6.0"
},
"devDependencies": {
- "grunt": "~0.4.4",
- "grunt-contrib-clean": "~0.5.0",
- "grunt-jsdoc": "~0.5.4",
+ "grunt": "~0.4.5",
+ "grunt-contrib-clean": "~0.6.0",
+ "grunt-jsdoc": "~0.5.7",
"grunt-contrib-jshint": "~0.10.0",
- "grunt-contrib-uglify": "~0.4.0",
- "load-grunt-tasks": "~0.4.0",
+ "grunt-contrib-uglify": "~0.5.1",
+ "load-grunt-tasks": "~0.6.0",
"matchdep": "~0.3.0",
- "jsdoc": "~3.2.2"
+ "jsdoc": "~3.3.0-alpha9"
},
"scripts": {
"build": "npm install && grunt",
diff --git a/typetalk.js b/typetalk.js
index bca3013..abd4b9c 100644
--- a/typetalk.js
+++ b/typetalk.js
@@ -1,4 +1,3 @@
-// typetalk-js v0.1.1
// License: MIT
'use strict';
@@ -9,7 +8,7 @@
*/
if (typeof window === 'undefined') {
- var Promise = Promise || require('bluebird');
+ var Promise = Promise || require('promise');
var XMLHttpRequest = XMLHttpRequest || require('xmlhttprequest').XMLHttpRequest;
}
@@ -23,7 +22,7 @@ if (typeof window === 'undefined') {
clientId,
clientSecret,
redirectUri,
- scope = 'topic.read';
+ scope = 'topic.read'; // @see {@link http://developer.nulab-inc.com/docs/typetalk/auth#scope}
/**
* Typetalk API client
@@ -37,7 +36,7 @@ if (typeof window === 'undefined') {
* @param {String} [options.access_token] - access token
* @param {String} [options.refresh_token] - refresh token
* @param {Number} [options.timeout=3000] - timeout(ms)
- * @see {@link http://developers.typetalk.in/oauth.html}
+ * @see {@link https://developer.nulab-inc.com/docs/typetalk/auth}
*/
function Typetalk(options) {
self = this;
@@ -200,7 +199,7 @@ if (typeof window === 'undefined') {
* @param {String} [options.client_secret] - client secret
* @param {String} [options.scope] - scope
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/oauth.html#client}
+ * @see {@link https://developer.nulab-inc.com/docs/typetalk/auth#client}
*/
Typetalk.prototype.getAccessTokenUsingClientCredentials = function(options) {
options = options || {};
@@ -219,7 +218,7 @@ if (typeof window === 'undefined') {
* @param {String} [options.client_id] - client id
* @param {String} [options.scope] - scope
* @param {String} [options.redirect_uri] - redirect uri
- * @see {@link http://developers.typetalk.in/oauth.html#code}
+ * @see {@link https://developer.nulab-inc.com/docs/typetalk/auth#code}
*/
Typetalk.prototype.requestAuthorization = function(options) {
options = options || {};
@@ -239,7 +238,7 @@ if (typeof window === 'undefined') {
* @param {String} [options.client_secret] - client secret
* @param {String} [options.redirect_uri] - redirect uri
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/oauth.html#code}
+ * @see {@link https://developer.nulab-inc.com/docs/typetalk/auth#code}
*/
Typetalk.prototype.getAccessTokenUsingAuthorizationCode = function(code, options) {
options = options || {};
@@ -260,7 +259,7 @@ if (typeof window === 'undefined') {
* @param {String} [options.client_secret] - client secret
* @param {String} [options.refresh_token] - refresh token
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/oauth.html#refresh}
+ * @see {@link https://developer.nulab-inc.com/docs/typetalk/auth#refresh}
*/
Typetalk.prototype.refreshAccessToken = function(options) {
options = options || {};
@@ -276,7 +275,7 @@ if (typeof window === 'undefined') {
* @memberof Typetalk
* @method
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-profile}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-profile}
*/
Typetalk.prototype.getMyProfile = function() {
return requestApi(Typetalk.API_BASE_URL + 'profile', 'GET', null);
@@ -287,7 +286,7 @@ if (typeof window === 'undefined') {
* @memberof Typetalk
* @method
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-topics}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-topics}
*/
Typetalk.prototype.getMyTopics = function() {
return requestApi(Typetalk.API_BASE_URL + 'topics', 'GET', null);
@@ -303,7 +302,7 @@ if (typeof window === 'undefined') {
* @param {Number} [options.from] - references Post ID
* @param {String} [options.direction] - "backward" or "forward"
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-messages}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-messages}
*/
Typetalk.prototype.getTopicMessages = function(topicId, options) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '?' + toQueryString(options), 'GET', null);
@@ -320,7 +319,7 @@ if (typeof window === 'undefined') {
* @param {String} [options.fileKeys[0-5]] - attachment file key, maximum count: 5
* @param {Number} [options.talkIds[0-5]] - Talk IDs that you want to put the message in, maximum count: 5
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#post-message}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/post-message}
*/
Typetalk.prototype.postMessage = function(topicId, message, options) {
options = options || {};
@@ -335,7 +334,7 @@ if (typeof window === 'undefined') {
* @param {Number} topicId - Topic ID
* @param {Binaly} file - max file size: 10MB
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#upload-attachment}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/upload-attachment}
*/
Typetalk.prototype.uploadAttachmentFile = function(topicId, file) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId), 'POST', {'file': file}, {'Content-Type': 'multipart/form-data'});
@@ -347,7 +346,7 @@ if (typeof window === 'undefined') {
* @method
* @param {Number} topicId - Topic ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-topic-members}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-topic-members}
*/
Typetalk.prototype.getTopicMembers = function(topicId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/members/status', 'GET', null);
@@ -360,7 +359,7 @@ if (typeof window === 'undefined') {
* @param {Number} topicId - Topic ID
* @param {Number} postId - Post ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-message}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-message}
*/
Typetalk.prototype.getMessage = function(topicId, postId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/posts/' + encodeURIComponent(postId), 'GET', null);
@@ -373,7 +372,7 @@ if (typeof window === 'undefined') {
* @param {Number} topicId - Topic ID
* @param {Number} postId - Post ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#remove-message}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/remove-message}
*/
Typetalk.prototype.removeMessage = function(topicId, postId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/posts/' + encodeURIComponent(postId), 'DELETE', null);
@@ -386,7 +385,7 @@ if (typeof window === 'undefined') {
* @param {Number} topicId - Topic ID
* @param {Number} postId - Post ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#like-message}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/like-message}
*/
Typetalk.prototype.likeMessage = function(topicId, postId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/posts/' + encodeURIComponent(postId) + '/like', 'POST', {'Content-Type': 'application/x-www-form-urlencoded'});
@@ -399,7 +398,7 @@ if (typeof window === 'undefined') {
* @param {Number} topicId - Topic ID
* @param {Number} postId - Post ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#unlike-message}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/unlike-message}
*/
Typetalk.prototype.unlikeMessage = function(topicId, postId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/posts/' + encodeURIComponent(postId) + '/like', 'DELETE', null);
@@ -411,7 +410,7 @@ if (typeof window === 'undefined') {
* @method
* @param {Number} topicId - Topic ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#favorite-topics}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/favorite-topics}
*/
Typetalk.prototype.favoriteTopic = function(topicId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/favorite', 'POST', {'Content-Type': 'application/x-www-form-urlencoded'});
@@ -423,7 +422,7 @@ if (typeof window === 'undefined') {
* @method
* @param {Number} topicId - Topic ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#unfavorite-topics}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/unfavorite-topics}
*/
Typetalk.prototype.unfavoriteTopic = function(topicId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/favorite', 'DELETE', null);
@@ -434,7 +433,7 @@ if (typeof window === 'undefined') {
* @memberof Typetalk
* @method
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-notifications}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-notifications}
*/
Typetalk.prototype.getNotificationList = function() {
return requestApi(Typetalk.API_BASE_URL + 'notifications', 'GET', null);
@@ -445,7 +444,7 @@ if (typeof window === 'undefined') {
* @memberof Typetalk
* @method
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-notification-status}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-notification-status}
*/
Typetalk.prototype.getNotificationCount = function() {
return requestApi(Typetalk.API_BASE_URL + 'notifications/status', 'GET', null);
@@ -456,7 +455,7 @@ if (typeof window === 'undefined') {
* @memberof Typetalk
* @method
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#open-notification}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/open-notification}
*/
Typetalk.prototype.readNotification = function() {
return requestApi(Typetalk.API_BASE_URL + 'notifications/open', 'PUT', null);
@@ -470,12 +469,12 @@ if (typeof window === 'undefined') {
* @param {Object} [options] - Form parameters
* @param {Number} [options.postId] - Post ID ( if no parameter, read all posts )
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#open-notification}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/save-read-topic}
*/
Typetalk.prototype.readMessagesInTopic = function(topicId, options) {
options = options || {};
options.topicId = topicId;
- return requestApi(Typetalk.API_BASE_URL + 'bookmark/save', 'POST', toQueryString(options), {'Content-Type': 'application/x-www-form-urlencoded'});
+ return requestApi(Typetalk.API_BASE_URL + 'bookmarks', 'PUT', toQueryString(options), {'Content-Type': 'application/x-www-form-urlencoded'});
};
/**
@@ -486,7 +485,7 @@ if (typeof window === 'undefined') {
* @param {Number} [options.from] - Mention ID
* @param {Boolean} [options.unread] - true: only unread mentions, false: all mentions
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#get-mentions}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-mentions}
*/
Typetalk.prototype.getMentionList = function(options) {
options = options || {};
@@ -499,7 +498,7 @@ if (typeof window === 'undefined') {
* @method
* @param {Number} mentionId - Mention ID
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#save-read-mention}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/save-read-mention}
*/
Typetalk.prototype.readMention = function(mentionId) {
return requestApi(Typetalk.API_BASE_URL + 'mentions/' + encodeURIComponent(mentionId), 'PUT', null);
@@ -512,7 +511,7 @@ if (typeof window === 'undefined') {
* @param {Number} teamId - Team ID
* @param {Number} inviteTeamId - Team invitation ID (invites.teams[x].id in Get notification list)
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#accept-team-invite}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/accept-team-invite}
*/
Typetalk.prototype.acceptTeamInvitation = function(teamId, inviteTeamId) {
return requestApi(Typetalk.API_BASE_URL + 'teams/' + encodeURIComponent(teamId) + '/members/invite/' + encodeURIComponent(inviteTeamId) + '/accept', 'POST', {'Content-Type': 'application/x-www-form-urlencoded'});
@@ -525,7 +524,7 @@ if (typeof window === 'undefined') {
* @param {Number} teamId - Team ID
* @param {Number} inviteTeamId - Team invitation ID (invites.teams[x].id in Get notification list)
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#decline-team-invite}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/decline-team-invite}
*/
Typetalk.prototype.declineTeamInvitation = function(teamId, inviteTeamId) {
return requestApi(Typetalk.API_BASE_URL + 'teams/' + encodeURIComponent(teamId) + '/members/invite/' + encodeURIComponent(inviteTeamId) + '/decline', 'POST', {'Content-Type': 'application/x-www-form-urlencoded'});
@@ -538,7 +537,7 @@ if (typeof window === 'undefined') {
* @param {Number} topicId - Topic ID
* @param {Number} inviteTeamId - Topic invitation ID (invites.topics[x].id in Get notification list)
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#accept-team-invite}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/accept-team-invite}
*/
Typetalk.prototype.acceptTopicInvitation = function(topicId, inviteTopicId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/members/invite/' + encodeURIComponent(inviteTopicId) + '/accept', 'POST', {'Content-Type': 'application/x-www-form-urlencoded'});
@@ -551,19 +550,169 @@ if (typeof window === 'undefined') {
* @param {Number} topicId - Topic ID
* @param {Number} inviteTeamId - Topic invitation ID (invites.topics[x].id in Get notification list)
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
- * @see {@link http://developers.typetalk.in/api.html#decline-team-invite}
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/decline-team-invite}
*/
Typetalk.prototype.declineTopicInvitation = function(topicId, inviteTopicId) {
return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/members/invite/' + encodeURIComponent(inviteTopicId) + '/decline', 'POST', {'Content-Type': 'application/x-www-form-urlencoded'});
};
+ /**
+ * Create topic
+ * @memberof Typetalk
+ * @method
+ * @param {String} name - Topic Name
+ * @param {Object} [options] - Form parameters
+ * @param {Number} [options.teamId] - Team ID
+ * @param {String} [options.inviteMembers[0..N]] - account.name or e-mail address
+ * @param {String} [options.inviteMessage - Invite message
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/create-topic}
+ */
+ Typetalk.prototype.createTopic = function(name, options) {
+ options = options || {};
+ options.name = name;
+ return requestApi(Typetalk.API_BASE_URL + 'topics', 'POST', toQueryString(options), {'Content-Type': 'application/x-www-form-urlencoded'});
+ };
+
+ /**
+ * Update topic
+ * @memberof Typetalk
+ * @method
+ * @param {Number} topicId - Topic ID
+ * @param {Object} [options] - Form parameters
+ * @param {String} [options.name] - Topic Name (not to use in team if team ID is empty string)
+ * @param {Number} [options.teamId - Team ID
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/update-topic}
+ */
+ Typetalk.prototype.updateTopic = function(topicId, options) {
+ return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId), 'PUT', toQueryString(options), {'Content-Type': 'application/x-www-form-urlencoded'});
+ };
+
+ /**
+ * Delete topic
+ * @memberof Typetalk
+ * @method
+ * @param {Number} topicId - Topic ID
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/update-topic}
+ */
+ Typetalk.prototype.deleteTopic = function(topicId) {
+ return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId), 'DELETE', null);
+ };
+
+ /**
+ * Get topic details
+ * @memberof Typetalk
+ * @method
+ * @param {Number} topicId - Topic ID
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-topic-details}
+ */
+ Typetalk.prototype.getTopicDetails = function(topicId) {
+ return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/details', 'GET', null);
+ };
+
+ /**
+ * Invite members to topic
+ * @memberof Typetalk
+ * @method
+ * @param {Number} topicId - Topic ID
+ * @param {Object} [options] - Form parameters
+ * @param {String} [options.inviteMembers[0..N]] - account.name or e-mail address
+ * @param {String} [options.inviteMessage - Invite message
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/invite-topic-member}
+ */
+ Typetalk.prototype.inviteTopicMember = function(topicId, options) {
+ return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/members/invite', 'POST', toQueryString(options), {'Content-Type': 'application/x-www-form-urlencoded'});
+ };
+
+ /**
+ * Remove members and invites from topic
+ * @memberof Typetalk
+ * @method
+ * @param {Number} topicId - Topic ID
+ * @param {Object} [options] - Form parameters
+ * @param {Number} [options.removeInviteIds[0..N]] - Invite ID (invites[x].id in get-topic-details)
+ * @param {Number} [options.removeMemberIds[0..N]] - Account ID (accounts[x].id in get-topic-details)
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/remove-topic-member}
+ */
+ Typetalk.prototype.removeTopicMember = function(topicId, options) {
+ return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/members/remove', 'POST', toQueryString(options), {'Content-Type': 'application/x-www-form-urlencoded'});
+ };
+
+ /**
+ * Get my teams
+ * @memberof Typetalk
+ * @method
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-teams}
+ */
+ Typetalk.prototype.getTeams = function() {
+ return requestApi(Typetalk.API_BASE_URL + 'teams', 'GET', null);
+ };
+
+ /**
+ * Get my friends
+ * @memberof Typetalk
+ * @method
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-friends}
+ */
+ Typetalk.prototype.getFriends = function() {
+ return requestApi(Typetalk.API_BASE_URL + 'search/friends', 'GET', null);
+ };
+
+ /**
+ * Search accounts
+ * @memberof Typetalk
+ * @method
+ * @param {String} nameOrEmailAddress - account.name or e-mail address
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/search-accounts}
+ */
+ Typetalk.prototype.searchAccounts = function(nameOrEmailAddress) {
+ return requestApi(Typetalk.API_BASE_URL + 'search/accounts?nameOrEmailAddress=' + encodeURIComponent(nameOrEmailAddress), 'GET', null);
+ };
+
+ /**
+ * Get talk list
+ * @memberof Typetalk
+ * @method
+ * @param {Number} topicId - Topic ID
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-talks}
+ */
+ Typetalk.prototype.getTalks = function(topicId) {
+ return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/talks', 'GET', null);
+ };
+
+ /**
+ * Get messages in talk
+ * @memberof Typetalk
+ * @method
+ * @param {Number} topicId - Topic ID
+ * @param {Number} talkId - Talk ID
+ * @param {Object} [options] - Form parameters
+ * @param {Number} [options.count] - default value: 20, maximum: 100
+ * @param {Number} [options.from] - references Post ID
+ * @param {String} [options.direction] - "backward" or "forward"
+ * @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
+ * @see {@link http://developer.nulab-inc.com/docs/typetalk/api/1/get-talk}
+ */
+ Typetalk.prototype.getTalk = function(topicId, talkId, options) {
+ return requestApi(Typetalk.API_BASE_URL + 'topics/' + encodeURIComponent(topicId) + '/talks/' + encodeURIComponent(talkId) + '/posts', 'GET', toQueryString(options));
+ };
+
return Typetalk;
})();
if (typeof module !== 'undefined') {
module.exports = Typetalk;
} else {
- //
+ //
this.Typetalk = Typetalk;
}
}).call(this);
diff --git a/typetalk.min.js b/typetalk.min.js
index 80c632d..fe9b993 100644
--- a/typetalk.min.js
+++ b/typetalk.min.js
@@ -1,3 +1,3 @@
-// typetalk-js v0.1.1
+// typetalk-js v0.2.0
// License: MIT
-"use strict";if("undefined"==typeof window)var Promise=Promise||require("bluebird"),XMLHttpRequest=XMLHttpRequest||require("xmlhttprequest").XMLHttpRequest;(function(){var a=function(){function a(a){b=this,a=a||{},b.accessToken=a.access_token,b.refreshToken=a.refresh_token,b.timeout=a.timeout||3e3,c=a.client_id,d=a.client_secret,e=a.redirect_uri,f=a.scope||f}a.API_BASE_URL="https://typetalk.in/api/v1/",a.OAUTH_BASE_URL="https://typetalk.in/oauth2/";var b,c,d,e,f="topic.read",g=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},h=function(c){return new Promise(function(d,e){var f=new XMLHttpRequest;f.onload=function(){200===f.status?d(JSON.parse(f.responseText)):e(JSON.parse(f.responseText))},f.onerror=e,f.open("POST",a.OAUTH_BASE_URL+"access_token"),f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.timeout=b.timeout,f.send(c)})},i=function(a,c,d,e){return new Promise(function(f,g){var h=new XMLHttpRequest;h.onload=function(){if(200===h.status)f(JSON.parse(h.responseText));else if(400===h.status||401===h.status){var a=h.getResponseHeader("WWW-Authenticate")||"",b=a.match(/error="(\w+)"/)||[],c=a.match(/error_description="(\w+)"/)||[],d=b.length>1?b[1]:h.statusText,e=c.length>1?c[1]:"";g({status:h.status,error:d,error_description:e})}else g({status:h.status,error:h.statusText,error_description:"An error has occurred while requesting api"})},h.onerror=g,h.open(c,a),e&&e["Content-Type"]&&h.setRequestHeader("Content-Type",e["Content-Type"]),h.setRequestHeader("Authorization","Bearer "+encodeURIComponent(b.accessToken)),h.timeout=b.timeout,h.send(d)})};return a.prototype.authorizeChromeApp=function(d){return d=d||{},new Promise(function(g,h){if(!chrome||!chrome.identity)return void h(new Error("chrome.identity API is unsupported"));var i=a.OAUTH_BASE_URL+"authorize?client_id="+encodeURIComponent(c||d.client_id)+"&redirect_uri="+encodeURIComponent(e||d.redirect_uri)+"&scope="+encodeURIComponent(f||d.scope)+"&response_type=code";chrome.identity.launchWebAuthFlow({url:i,interactive:!0},function(a){if("undefined"==typeof a)return void h(new Error("Cannot get response url"));var c=a.match(/code=(.+)/)[1];return"undefined"==typeof c?void h(new Error("authorization code is required")):void b.getAccessTokenUsingAuthorizationCode(c).then(function(a){g(a)},function(a){h(a)})})})},a.prototype.hasToken=function(){return!!b.accessToken&&!!b.refreshToken},a.prototype.clearToken=function(){b.accessToken=null,b.refreshToken=null},a.prototype.validateAccessToken=function(){return b.getMyProfile()},a.prototype.getAccessTokenUsingClientCredentials=function(a){a=a||{};var b="client_id="+encodeURIComponent(c||a.client_id)+"&client_secret="+encodeURIComponent(d||a.client_secret)+"&grant_type=client_credentials&scope="+encodeURIComponent(f||a.scope);return h(b)},a.prototype.requestAuthorization=function(b){b=b||{};var d="client_id="+encodeURIComponent(c||b.client_id)+"&redirect_uri="+encodeURIComponent(e||b.redirect_uri)+"&scope="+encodeURIComponent(f||b.scope)+"&response_type=code";location.href=a.OAUTH_BASE_URL+"authorize?"+d},a.prototype.getAccessTokenUsingAuthorizationCode=function(a,b){b=b||{};var f="client_id="+encodeURIComponent(c||b.client_id)+"&client_secret="+encodeURIComponent(d||b.client_secret)+"&redirect_uri="+encodeURIComponent(e||b.redirect_uri)+"&grant_type=authorization_code&code="+encodeURIComponent(a);return h(f)},a.prototype.refreshAccessToken=function(a){a=a||{};var e="client_id="+encodeURIComponent(c||a.client_id)+"&client_secret="+encodeURIComponent(d||a.client_secret)+"&grant_type=refresh_token&refresh_token="+encodeURIComponent(b.refreshToken||a.refresh_token);return h(e)},a.prototype.getMyProfile=function(){return i(a.API_BASE_URL+"profile","GET",null)},a.prototype.getMyTopics=function(){return i(a.API_BASE_URL+"topics","GET",null)},a.prototype.getTopicMessages=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"?"+g(c),"GET",null)},a.prototype.postMessage=function(b,c,d){return d=d||{},d.message=c,i(a.API_BASE_URL+"topics/"+encodeURIComponent(b),"POST",g(d),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.uploadAttachmentFile=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b),"POST",{file:c},{"Content-Type":"multipart/form-data"})},a.prototype.getTopicMembers=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/status","GET",null)},a.prototype.getMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c),"GET",null)},a.prototype.removeMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c),"DELETE",null)},a.prototype.likeMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c)+"/like","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.unlikeMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c)+"/like","DELETE",null)},a.prototype.favoriteTopic=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/favorite","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.unfavoriteTopic=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/favorite","DELETE",null)},a.prototype.getNotificationList=function(){return i(a.API_BASE_URL+"notifications","GET",null)},a.prototype.getNotificationCount=function(){return i(a.API_BASE_URL+"notifications/status","GET",null)},a.prototype.readNotification=function(){return i(a.API_BASE_URL+"notifications/open","PUT",null)},a.prototype.readMessagesInTopic=function(b,c){return c=c||{},c.topicId=b,i(a.API_BASE_URL+"bookmark/save","POST",g(c),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.getMentionList=function(b){return b=b||{},i(a.API_BASE_URL+"mentions?"+g(b),"GET",null)},a.prototype.readMention=function(b){return i(a.API_BASE_URL+"mentions/"+encodeURIComponent(b),"PUT",null)},a.prototype.acceptTeamInvitation=function(b,c){return i(a.API_BASE_URL+"teams/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/accept","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.declineTeamInvitation=function(b,c){return i(a.API_BASE_URL+"teams/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/decline","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.acceptTopicInvitation=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/accept","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.declineTopicInvitation=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/decline","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a}();"undefined"!=typeof module?module.exports=a:this.Typetalk=a}).call(this);
\ No newline at end of file
+"use strict";if("undefined"==typeof window)var Promise=Promise||require("promise"),XMLHttpRequest=XMLHttpRequest||require("xmlhttprequest").XMLHttpRequest;(function(){var a=function(){function a(a){b=this,a=a||{},b.accessToken=a.access_token,b.refreshToken=a.refresh_token,b.timeout=a.timeout||3e3,c=a.client_id,d=a.client_secret,e=a.redirect_uri,f=a.scope||f}a.API_BASE_URL="https://typetalk.in/api/v1/",a.OAUTH_BASE_URL="https://typetalk.in/oauth2/";var b,c,d,e,f="topic.read",g=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")},h=function(c){return new Promise(function(d,e){var f=new XMLHttpRequest;f.onload=function(){200===f.status?d(JSON.parse(f.responseText)):e(JSON.parse(f.responseText))},f.onerror=e,f.open("POST",a.OAUTH_BASE_URL+"access_token"),f.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),f.timeout=b.timeout,f.send(c)})},i=function(a,c,d,e){return new Promise(function(f,g){var h=new XMLHttpRequest;h.onload=function(){if(200===h.status)f(JSON.parse(h.responseText));else if(400===h.status||401===h.status){var a=h.getResponseHeader("WWW-Authenticate")||"",b=a.match(/error="(\w+)"/)||[],c=a.match(/error_description="(\w+)"/)||[],d=b.length>1?b[1]:h.statusText,e=c.length>1?c[1]:"";g({status:h.status,error:d,error_description:e})}else g({status:h.status,error:h.statusText,error_description:"An error has occurred while requesting api"})},h.onerror=g,h.open(c,a),e&&e["Content-Type"]&&h.setRequestHeader("Content-Type",e["Content-Type"]),h.setRequestHeader("Authorization","Bearer "+encodeURIComponent(b.accessToken)),h.timeout=b.timeout,h.send(d)})};return a.prototype.authorizeChromeApp=function(d){return d=d||{},new Promise(function(g,h){if(!chrome||!chrome.identity)return void h(new Error("chrome.identity API is unsupported"));var i=a.OAUTH_BASE_URL+"authorize?client_id="+encodeURIComponent(c||d.client_id)+"&redirect_uri="+encodeURIComponent(e||d.redirect_uri)+"&scope="+encodeURIComponent(f||d.scope)+"&response_type=code";chrome.identity.launchWebAuthFlow({url:i,interactive:!0},function(a){if("undefined"==typeof a)return void h(new Error("Cannot get response url"));var c=a.match(/code=(.+)/)[1];return"undefined"==typeof c?void h(new Error("authorization code is required")):void b.getAccessTokenUsingAuthorizationCode(c).then(function(a){g(a)},function(a){h(a)})})})},a.prototype.hasToken=function(){return!!b.accessToken&&!!b.refreshToken},a.prototype.clearToken=function(){b.accessToken=null,b.refreshToken=null},a.prototype.validateAccessToken=function(){return b.getMyProfile()},a.prototype.getAccessTokenUsingClientCredentials=function(a){a=a||{};var b="client_id="+encodeURIComponent(c||a.client_id)+"&client_secret="+encodeURIComponent(d||a.client_secret)+"&grant_type=client_credentials&scope="+encodeURIComponent(f||a.scope);return h(b)},a.prototype.requestAuthorization=function(b){b=b||{};var d="client_id="+encodeURIComponent(c||b.client_id)+"&redirect_uri="+encodeURIComponent(e||b.redirect_uri)+"&scope="+encodeURIComponent(f||b.scope)+"&response_type=code";location.href=a.OAUTH_BASE_URL+"authorize?"+d},a.prototype.getAccessTokenUsingAuthorizationCode=function(a,b){b=b||{};var f="client_id="+encodeURIComponent(c||b.client_id)+"&client_secret="+encodeURIComponent(d||b.client_secret)+"&redirect_uri="+encodeURIComponent(e||b.redirect_uri)+"&grant_type=authorization_code&code="+encodeURIComponent(a);return h(f)},a.prototype.refreshAccessToken=function(a){a=a||{};var e="client_id="+encodeURIComponent(c||a.client_id)+"&client_secret="+encodeURIComponent(d||a.client_secret)+"&grant_type=refresh_token&refresh_token="+encodeURIComponent(b.refreshToken||a.refresh_token);return h(e)},a.prototype.getMyProfile=function(){return i(a.API_BASE_URL+"profile","GET",null)},a.prototype.getMyTopics=function(){return i(a.API_BASE_URL+"topics","GET",null)},a.prototype.getTopicMessages=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"?"+g(c),"GET",null)},a.prototype.postMessage=function(b,c,d){return d=d||{},d.message=c,i(a.API_BASE_URL+"topics/"+encodeURIComponent(b),"POST",g(d),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.uploadAttachmentFile=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b),"POST",{file:c},{"Content-Type":"multipart/form-data"})},a.prototype.getTopicMembers=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/status","GET",null)},a.prototype.getMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c),"GET",null)},a.prototype.removeMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c),"DELETE",null)},a.prototype.likeMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c)+"/like","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.unlikeMessage=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/posts/"+encodeURIComponent(c)+"/like","DELETE",null)},a.prototype.favoriteTopic=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/favorite","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.unfavoriteTopic=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/favorite","DELETE",null)},a.prototype.getNotificationList=function(){return i(a.API_BASE_URL+"notifications","GET",null)},a.prototype.getNotificationCount=function(){return i(a.API_BASE_URL+"notifications/status","GET",null)},a.prototype.readNotification=function(){return i(a.API_BASE_URL+"notifications/open","PUT",null)},a.prototype.readMessagesInTopic=function(b,c){return c=c||{},c.topicId=b,i(a.API_BASE_URL+"bookmarks","PUT",g(c),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.getMentionList=function(b){return b=b||{},i(a.API_BASE_URL+"mentions?"+g(b),"GET",null)},a.prototype.readMention=function(b){return i(a.API_BASE_URL+"mentions/"+encodeURIComponent(b),"PUT",null)},a.prototype.acceptTeamInvitation=function(b,c){return i(a.API_BASE_URL+"teams/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/accept","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.declineTeamInvitation=function(b,c){return i(a.API_BASE_URL+"teams/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/decline","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.acceptTopicInvitation=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/accept","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.declineTopicInvitation=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/invite/"+encodeURIComponent(c)+"/decline","POST",{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.createTopic=function(b,c){return c=c||{},c.name=b,i(a.API_BASE_URL+"topics","POST",g(c),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.updateTopic=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b),"PUT",g(c),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.deleteTopic=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b),"DELETE",null)},a.prototype.getTopicDetails=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/details","GET",null)},a.prototype.inviteTopicMember=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/invite","POST",g(c),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.removeTopicMember=function(b,c){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/members/remove","POST",g(c),{"Content-Type":"application/x-www-form-urlencoded"})},a.prototype.getTeams=function(){return i(a.API_BASE_URL+"teams","GET",null)},a.prototype.getFriends=function(){return i(a.API_BASE_URL+"search/friends","GET",null)},a.prototype.searchAccounts=function(b){return i(a.API_BASE_URL+"search/accounts?nameOrEmailAddress="+encodeURIComponent(b),"GET",null)},a.prototype.getTalks=function(b){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/talks","GET",null)},a.prototype.getTalk=function(b,c,d){return i(a.API_BASE_URL+"topics/"+encodeURIComponent(b)+"/talks/"+encodeURIComponent(c)+"/posts","GET",g(d))},a}();"undefined"!=typeof module?module.exports=a:this.Typetalk=a}).call(this);
\ No newline at end of file