11#!/usr/bin/env node
22
3- const io = require ( 'socket.io-client' ) ;
3+ // const io = require('socket.io-client');
44const config = require ( './config' ) ;
5- const events = require ( 'events' ) ;
5+ // const events = require('events');
66const axios = require ( 'axios' ) ;
77
88const store = { apiKey : '' } ;
@@ -14,44 +14,44 @@ const setApiKey = (apiKey) => {
1414/*
1515 * Stream API
1616 */
17- const streamApiStore = { } ;
18-
19- const initSocket = ( apiKey ) => {
20- const uri = config . io . server + '/' + config . io . namespace . allFilings ;
21- const params = {
22- query : { apiKey } ,
23- transports : [ 'websocket' ] , // ensure traffic goes through load balancer
24- } ;
25- streamApiStore . socket = io ( uri , params ) ;
26- streamApiStore . socket . on ( 'connect' , ( ) =>
27- console . log ( 'Socket connected to' , uri ) ,
28- ) ;
29- streamApiStore . socket . on ( 'filing' , handleNewFiling ) ;
30- streamApiStore . socket . on ( 'filings' , handleNewFilings ) ;
31- streamApiStore . socket . on ( 'error' , console . error ) ;
32- } ;
33-
34- const handleNewFiling = ( filing ) => {
35- streamApiStore . eventEmitter . emit ( 'filing' , filing ) ;
36- } ;
37-
38- const handleNewFilings = ( filings ) => {
39- streamApiStore . eventEmitter . emit ( 'filings' , filings ) ;
40- } ;
41-
42- const close = ( ) => {
43- if ( streamApiStore . socket . close ) {
44- streamApiStore . socket . close ( ) ;
45- }
46- } ;
47-
48- const connect = ( apiKey ) => {
49- setApiKey ( apiKey ) ;
50- initSocket ( apiKey ) ;
51- streamApiStore . eventEmitter = new events . EventEmitter ( ) ;
52- modules . streamApi . on = streamApiStore . eventEmitter . on ;
53- return streamApiStore . eventEmitter ;
54- } ;
17+ // const streamApiStore = {};
18+
19+ // const initSocket = (apiKey) => {
20+ // const uri = config.io.server + '/' + config.io.namespace.allFilings;
21+ // const params = {
22+ // query: { apiKey },
23+ // transports: ['websocket'], // ensure traffic goes through load balancer
24+ // };
25+ // streamApiStore.socket = io(uri, params);
26+ // streamApiStore.socket.on('connect', () =>
27+ // console.log('Socket connected to', uri),
28+ // );
29+ // streamApiStore.socket.on('filing', handleNewFiling);
30+ // streamApiStore.socket.on('filings', handleNewFilings);
31+ // streamApiStore.socket.on('error', console.error);
32+ // };
33+
34+ // const handleNewFiling = (filing) => {
35+ // streamApiStore.eventEmitter.emit('filing', filing);
36+ // };
37+
38+ // const handleNewFilings = (filings) => {
39+ // streamApiStore.eventEmitter.emit('filings', filings);
40+ // };
41+
42+ // const close = () => {
43+ // if (streamApiStore.socket.close) {
44+ // streamApiStore.socket.close();
45+ // }
46+ // };
47+
48+ // const connect = (apiKey) => {
49+ // setApiKey(apiKey);
50+ // initSocket(apiKey);
51+ // streamApiStore.eventEmitter = new events.EventEmitter();
52+ // modules.streamApi.on = streamApiStore.eventEmitter.on;
53+ // return streamApiStore.eventEmitter;
54+ // };
5555
5656/*
5757 * Query API
@@ -228,11 +228,11 @@ const getSection = async (filingUrl, section = '1A', returnType = 'text') => {
228228 */
229229const modules = {
230230 setApiKey,
231- streamApi : {
232- setApiKey,
233- connect,
234- close,
235- } ,
231+ // streamApi: {
232+ // setApiKey,
233+ // connect,
234+ // close,
235+ // },
236236 queryApi : {
237237 setApiKey,
238238 getFilings : getFilingsQuery ,
@@ -265,13 +265,15 @@ module.exports = modules;
265265 * Command Line Execution - Stream API
266266 */
267267if ( require . main === module ) {
268- const apiKey = process . argv [ 2 ] ;
269- const emitter = connect ( apiKey ) ;
270- let messageCounter = 0 ;
271-
272- emitter . on ( 'filing' , ( filing ) => {
273- // console.log(JSON.stringify(filing, null, 1))
274- messageCounter ++ ;
275- console . log ( filing . id , filing . formType , filing . filedAt , messageCounter ) ;
276- } ) ;
268+ // const apiKey = process.argv[2];
269+ // const emitter = connect(apiKey);
270+ // let messageCounter = 0;
271+ // emitter.on('filing', (filing) => {
272+ // // console.log(JSON.stringify(filing, null, 1))
273+ // messageCounter++;
274+ // console.log(filing.id, filing.formType, filing.filedAt, messageCounter);
275+ // });
276+ console . log (
277+ 'sec-api npm package working. Please import the package and use the provided methods to interact with the API.' ,
278+ ) ;
277279}
0 commit comments