diff --git a/types/twitter-stream-channels/index.d.ts b/types/twitter-stream-channels/index.d.ts new file mode 100644 index 0000000000..486b02edaf --- /dev/null +++ b/types/twitter-stream-channels/index.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +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; + + + /** + * 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; +} diff --git a/types/twitter-stream-channels/tsconfig.json b/types/twitter-stream-channels/tsconfig.json new file mode 100644 index 0000000000..720a88392b --- /dev/null +++ b/types/twitter-stream-channels/tsconfig.json @@ -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" + ] +} \ No newline at end of file diff --git a/types/twitter-stream-channels/twitter-stream-channels-tests.ts b/types/twitter-stream-channels/twitter-stream-channels-tests.ts new file mode 100644 index 0000000000..6943356cf7 --- /dev/null +++ b/types/twitter-stream-channels/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})