mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 03:02:04 +08:00
add types for twitter-stream-channels 1.0.0
This commit is contained in:
134
types/twitter-stream-channels/index.d.ts
vendored
Normal file
134
types/twitter-stream-channels/index.d.ts
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
// Type definitions for twitter-stream-channels 1.0.0
|
||||
// Project: https://github.com/topheman/twitter-stream-channels
|
||||
// Definitions by: Adrian Bardan <https://github.com/adrianbardan>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
/// <reference types="twit" />
|
||||
|
||||
declare module 'twitter-stream-channels' {
|
||||
|
||||
import * as Twit from 'twit';
|
||||
|
||||
namespace TwitterStreamChannels {
|
||||
|
||||
export namespace StreamChannels {
|
||||
|
||||
export interface Channels {
|
||||
}
|
||||
|
||||
export interface StreamChannelsOptions {
|
||||
track?: Object,
|
||||
follow?: string,
|
||||
locations?: string,
|
||||
enableChannelsEvents?: boolean,
|
||||
enableRootChannelsEvent?: boolean,
|
||||
enableKeywordsEvents?: boolean
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class StreamChannels extends NodeJS.EventEmitter {
|
||||
|
||||
/**
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/StreamChannels.js#L25
|
||||
*/
|
||||
constructor(apiClient: Twit, options: StreamChannels.StreamChannelsOptions);
|
||||
|
||||
/**
|
||||
* Call this function to restart the stream after you called `.stop()` on it.
|
||||
*
|
||||
* Note: there is no need to call `.start()` to begin streaming. ` TwitterStreamChannels.streamChannels` calls .start() for you.
|
||||
* @method start
|
||||
* @returns {StreamChannels}
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/StreamChannels.js#L120
|
||||
*/
|
||||
start(): StreamChannels;
|
||||
|
||||
/**
|
||||
* Closes the opened stream with Twitter
|
||||
* @method stop
|
||||
* @param {StreamChannelsOptions} [options]
|
||||
* @param {StreamChannelsOptions} [options.removeAllListeners=false] If true removes all the listeners set on the stream
|
||||
* @returns {StreamChannels}
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/StreamChannels.js#L120
|
||||
*/
|
||||
stop(options?: StreamChannels.StreamChannelsOptions): StreamChannels;
|
||||
|
||||
|
||||
/**
|
||||
* Returns your channel description
|
||||
* @method getChannels
|
||||
* @returns {StreamChannels.channels}
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/StreamChannels.js#L145
|
||||
*/
|
||||
getChannels(): StreamChannels.Channels;
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of the keywords you're tracking (duplicates were removed)
|
||||
* @method getTrackedKeywords
|
||||
* @returns {Array}
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/StreamChannels.js#L145
|
||||
*/
|
||||
getTrackedKeywords(): Array<string>;
|
||||
|
||||
|
||||
/**
|
||||
* Returns an object key/value - key:your channels - value:the full text search RegExp for the keywords of this channel
|
||||
* @method getchannelsKeywordsLowerCasedRegExp
|
||||
* @returns {StreamChannels.channels}
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/StreamChannels.js#L163
|
||||
*/
|
||||
getChannelsKeywordsLowerCasedRegExp(): StreamChannels.Channels;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @class TwitterStreamChannels
|
||||
* @param {Object} credentials
|
||||
* @param {String} credentials.consumer_key
|
||||
* @param {String} credentials.consumer_secret
|
||||
* @param {String} credentials.access_token
|
||||
* @param {String} credentials.access_token_secret
|
||||
* @return {TwitterStreamChannels}
|
||||
*/
|
||||
|
||||
class TwitterStreamChannels {
|
||||
/**
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/TwitterStreamChannels.js#L69
|
||||
*/
|
||||
constructor(config: {});
|
||||
|
||||
/**
|
||||
* Returns a Twitter API client on which you can do pretty much what you want.
|
||||
* More here https://github.com/ttezel/twit
|
||||
* @method getApiClient
|
||||
* @returns {Twit}
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/TwitterStreamChannels.js#L113
|
||||
*/
|
||||
getApiClient(): Twit;
|
||||
|
||||
/**
|
||||
* Opens a Twitter Stream and returns you an other one on which you'll be able to attach events for each channels
|
||||
* @method streamChannels
|
||||
* @param {Object} options You can use the same filter options as described in the Twitter stream API for `statuses/filter` https://dev.twitter.com/docs/api/1.1/post/statuses/filter
|
||||
* @param {Object|Array} options.track Pass an object describing your channels. If you don't want to use channels, you can pass directly an array of keywords.
|
||||
* @param {String} [options.follow] A comma separated list of user IDs, indicating the users to return statuses for in the stream
|
||||
* @param {String} [options.locations] Specifies a set of bounding boxes to track. More about how to format this parameter here : https://dev.twitter.com/docs/streaming-apis/parameters#locations
|
||||
* @param {Boolean} [options.enableChannelsEvents=true] If true, will fire the events like 'channels/channelName'
|
||||
* @param {Boolean} [options.enableRootChannelsEvent=true] If true, will fire the event 'channels'
|
||||
* @param {Boolean} [options.enableKeywordsEvents=false] If true, will fire the events 'keywords/keywordName' (disabled by default)
|
||||
* @return {StreamChannels}
|
||||
* @see https://github.com/topheman/twitter-stream-channels/blob/master/lib/TwitterStreamChannels.js#L131
|
||||
*/
|
||||
streamChannels(options: TwitterStreamChannels.StreamChannels.StreamChannelsOptions): TwitterStreamChannels.StreamChannels;
|
||||
|
||||
}
|
||||
|
||||
|
||||
export = TwitterStreamChannels;
|
||||
}
|
||||
22
types/twitter-stream-channels/tsconfig.json
Normal file
22
types/twitter-stream-channels/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"twitter-stream-channels-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import * as TwitterStreamChannels from "twitter-stream-channels";
|
||||
|
||||
const tsc = new TwitterStreamChannels({
|
||||
consumer_key: '',
|
||||
consumer_secret: '',
|
||||
app_only_auth: true,
|
||||
});
|
||||
|
||||
let channels = {
|
||||
"js-frameworks": ['angularjs', 'jquery', 'backbone', 'emberjs'],
|
||||
"web": ['javascript', 'nodejs', 'html5', 'css', 'angularjs']
|
||||
};
|
||||
|
||||
tsc.streamChannels({track: channels})
|
||||
Reference in New Issue
Block a user