Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from shoito/apidoc
Browse files Browse the repository at this point in the history
fix jsdoc comment
  • Loading branch information
shoito committed May 6, 2014
2 parents 5d89eb6 + b74ded2 commit 2372e6a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 66 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typetalk-js",
"version": "0.1.2",
"version": "0.1.3",
"main": "typetalk.js",
"ignore": [
"**/.*",
Expand Down
16 changes: 0 additions & 16 deletions component.json

This file was deleted.

3 changes: 2 additions & 1 deletion example/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ var Promise = require('bluebird'),

var typetalk = new Typetalk({
'client_id': 'YOUR_CLIENT_ID__CLIENT_CREDENTIALS',
'client_secret': 'YOUR_CLIENT_SECRET__CLIENT_CREDENTIALS'
'client_secret': 'YOUR_CLIENT_SECRET__CLIENT_CREDENTIALS',
'scope': 'my'
});

typetalk.getAccessTokenUsingClientCredentials().then(function(data) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "typetalk-js",
"title": "typetalk-js",
"description": "JavaScript library for Typetalk",
"version": "0.1.2",
"version": "0.1.3",
"main": "typetalk.js",
"homepage": "https://github.com/shoito/typetalk-js",
"author": {
Expand Down
109 changes: 64 additions & 45 deletions typetalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,25 @@ if (typeof window === 'undefined') {
clientId,
clientSecret,
redirectUri,
scope = 'topic.read,topic.post,my';
scope = 'topic.read';

/**
* Typetalk API client
* @global
* @class Typetalk
* @param {Object} options - API parameters
* @param {String} options.client_id - client id
* @param {String} options.client_secret - client secret
* @param {String} [options.scope=topic.read,topic.post,my] - scope
* @param {Object} [options] - API parameters
* @param {String} [options.client_id] - client id
* @param {String} [options.client_secret] - client secret
* @param {String} [options.scope=topic.read] - scope
* @param {String} [options.redirect_uri] - redirect uri
* @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}
*/
function Typetalk(options) {
['client_id', 'client_secret'].forEach(function(field) {
if (typeof options[field] === 'undefined') {
throw new Error(field + ' is required');
}
});

self = this;
options = options || {};
self.accessToken = options.access_token;
self.refreshToken = options.refresh_token;
self.timeout = options.timeout || 3000;
Expand Down Expand Up @@ -123,18 +118,23 @@ if (typeof window === 'undefined') {
* Starts an auth flow at the typetalk oauth2 URL.
* @memberof Typetalk
* @method
* @param {Object} [options] - oAuth2 parameters
* @param {String} [options.client_id] - client id
* @param {String} [options.scope] - scope
* @param {String} [options.redirect_uri] - redirect uri
* @return {Promise} promise object - It will resolve with `response` data or fail with `error` object
*/
Typetalk.prototype.authorizeChromeApp = function() {
Typetalk.prototype.authorizeChromeApp = function(options) {
options = options || {};
return new Promise(function(resolve, reject) {
if (!(chrome && chrome.identity)) {
reject(new Error('chrome.identity API is unsupported'));
return;
}

var authorizeUrl = Typetalk.OAUTH_BASE_URL + 'authorize?client_id=' + encodeURIComponent(clientId) +
'&redirect_uri=' + encodeURIComponent(redirectUri) +
'&scope=' + encodeURIComponent(scope) + '&response_type=code';
var authorizeUrl = Typetalk.OAUTH_BASE_URL + 'authorize?client_id=' + encodeURIComponent(clientId || options.client_id) +
'&redirect_uri=' + encodeURIComponent(redirectUri || options.redirect_uri) +
'&scope=' + encodeURIComponent(scope || options.scope) + '&response_type=code';
chrome.identity.launchWebAuthFlow(
{'url': authorizeUrl, 'interactive': true},
function(responseUrl) {
Expand Down Expand Up @@ -193,27 +193,37 @@ if (typeof window === 'undefined') {
* Get access token using authorization code
* @memberof Typetalk
* @method
* @param {Object} [options] - oAuth2 parameters
* @param {String} [options.client_id] - client id
* @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}
*/
Typetalk.prototype.getAccessTokenUsingClientCredentials = function() {
var param = 'client_id=' + encodeURIComponent(clientId) +
'&client_secret=' + encodeURIComponent(clientSecret) +
Typetalk.prototype.getAccessTokenUsingClientCredentials = function(options) {
options = options || {};
var param = 'client_id=' + encodeURIComponent(clientId || options.client_id) +
'&client_secret=' + encodeURIComponent(clientSecret || options.client_secret) +
'&grant_type=client_credentials' +
'&scope=' + encodeURIComponent(scope);
'&scope=' + encodeURIComponent(scope || options.scope);
return requestAccessToken(param);
};

/**
* Redirect users to request Typetalk access
* @memberof Typetalk
* @method
* @param {Object} [options] - oAuth2 parameters
* @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}
*/
Typetalk.prototype.requestAuthorization = function() {
var param = 'client_id=' + encodeURIComponent(clientId) +
'&redirect_uri=' + encodeURIComponent(redirectUri) +
'&scope=' + encodeURIComponent(scope) +
Typetalk.prototype.requestAuthorization = function(options) {
options = options || {};
var param = 'client_id=' + encodeURIComponent(clientId || options.client_id) +
'&redirect_uri=' + encodeURIComponent(redirectUri || options.redirect_uri) +
'&scope=' + encodeURIComponent(scope || options.scope) +
'&response_type=code';
location.href = Typetalk.OAUTH_BASE_URL + 'authorize?' + param;
};
Expand All @@ -222,13 +232,18 @@ if (typeof window === 'undefined') {
* Get an access token using authorization code
* @memberof Typetalk
* @method
* @param {Object} [options] - oAuth2 parameters
* @param {String} [options.client_id] - client id
* @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}
*/
Typetalk.prototype.getAccessTokenUsingAuthorizationCode = function(code) {
var param = 'client_id=' + encodeURIComponent(clientId) +
'&client_secret=' + encodeURIComponent(clientSecret) +
'&redirect_uri=' + encodeURIComponent(redirectUri) +
Typetalk.prototype.getAccessTokenUsingAuthorizationCode = function(code, options) {
options = options || {};
var param = 'client_id=' + encodeURIComponent(clientId || options.client_id) +
'&client_secret=' + encodeURIComponent(clientSecret || options.client_secret) +
'&redirect_uri=' + encodeURIComponent(redirectUri || options.redirect_uri) +
'&grant_type=authorization_code' +
'&code=' + encodeURIComponent(code);
return requestAccessToken(param);
Expand All @@ -238,15 +253,19 @@ if (typeof window === 'undefined') {
* Get an access token using authorization code
* @memberof Typetalk
* @method
* @param {?String} refreshToken - your refresh token
* @param {Object} [options] - oAuth2 parameters and refresh token
* @param {String} [options.client_id] - client id
* @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}
*/
Typetalk.prototype.refreshAccessToken = function(refreshToken) {
var param = 'client_id=' + encodeURIComponent(clientId) +
'&client_secret=' + encodeURIComponent(clientSecret) +
Typetalk.prototype.refreshAccessToken = function(options) {
options = options || {};
var param = 'client_id=' + encodeURIComponent(clientId || options.client_id) +
'&client_secret=' + encodeURIComponent(clientSecret || options.client_secret) +
'&grant_type=refresh_token' +
'&refresh_token=' + encodeURIComponent(refreshToken || self.refreshToken);
'&refresh_token=' + encodeURIComponent(self.refreshToken || options.refresh_token);
return requestAccessToken(param);
};

Expand Down Expand Up @@ -277,10 +296,10 @@ if (typeof window === 'undefined') {
* @memberof Typetalk
* @method
* @param {Number} topicId - Topic ID
* @param {?Object} options - Query parameters
* @param {?Number} options.count - default value: 20, maximum: 100
* @param {?Number} options.from - references Post ID
* @param {?String} options.direction - "backward" or "forward"
* @param {Object} [options] - Query 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://developers.typetalk.in/api.html#get-messages}
*/
Expand All @@ -294,10 +313,10 @@ if (typeof window === 'undefined') {
* @method
* @param {Number} topicId - Topic ID
* @param {String} message - your message, maximum length: 4096
* @param {?Object} options - Form parameters
* @param {?Number} options.replyTo - references Post ID
* @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
* @param {Object} [options] - Form parameters
* @param {Number} [options.replyTo] - references Post ID
* @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}
*/
Expand Down Expand Up @@ -446,8 +465,8 @@ if (typeof window === 'undefined') {
* @memberof Typetalk
* @method
* @param {Number} topicId - Topic ID
* @param {?Object} options - Form parameters
* @param {?Number} options.postId - Post ID ( if no parameter, read all posts )
* @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}
*/
Expand All @@ -461,9 +480,9 @@ if (typeof window === 'undefined') {
* Get mention list
* @memberof Typetalk
* @method
* @param {?Object} options - Form parameters
* @param {?Number} options.from - Mention ID
* @param {?Boolean} options.unread - true: only unread mentions, false: all mentions
* @param {Object} [options] - Form parameters
* @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}
*/
Expand Down
Loading

0 comments on commit 2372e6a

Please sign in to comment.