Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add types for twitter-stream-channels 1.0.0 #19725

Merged
merged 1 commit into from Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
134 changes: 134 additions & 0 deletions 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 <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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only removeAllListeners, should not a generic "StreamChannelsOptions" interface



/**
* 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 changes: 22 additions & 0 deletions types/twitter-stream-channels/tsconfig.json
@@ -0,0 +1,22 @@
{
"compilerOptions": {
Copy link
Contributor

@aozgaa aozgaa Sep 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a tslint.json with dts-gen.

EDIT: misread the file name.

"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"
]
}
14 changes: 14 additions & 0 deletions 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})