stream-rally
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -6,3 +6,3 @@ "use strict"; | ||
describe('Twitch Service', () => { | ||
it('Should get stream riotgames', () => { | ||
xit('Should get stream shroud and NICKMERCS', () => { | ||
const twitch = new Twitch_1.default('mcqijt1d0a7vigass8xf2hzfqz1s2i', '6oyzr36m00fiw13y3iwymdc31pixlf'); | ||
@@ -20,2 +20,12 @@ return twitch.getStreams([ | ||
}); | ||
it('Should get Aion', () => { | ||
const twitch = new Twitch_1.default('mcqijt1d0a7vigass8xf2hzfqz1s2i', '6oyzr36m00fiw13y3iwymdc31pixlf'); | ||
return twitch.getStreamsByGame('Aion') | ||
.then((streams) => { | ||
console.log(streams); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
}); | ||
}); |
@@ -8,2 +8,3 @@ import { AxiosPromise } from 'axios'; | ||
getStreams: (streamOrStreams: string | string[]) => AxiosPromise<any[]>; | ||
getStreamsByGameId: (gameId: string | number, limit?: number) => AxiosPromise<any[]>; | ||
getUsers: (userOrUsers: string | string[]) => AxiosPromise<any[]>; | ||
@@ -15,5 +16,5 @@ protected getGames: (params: { | ||
getGamesById: (games: (string | number)[]) => AxiosPromise<any[]>; | ||
getGamesByName: (games: string[]) => AxiosPromise<any[]>; | ||
getGamesByName: (games: string | string[]) => AxiosPromise<any[]>; | ||
getNumFollowers: (userId: string) => AxiosPromise<number>; | ||
} | ||
export default TwitchAPI; |
@@ -29,2 +29,10 @@ "use strict"; | ||
}; | ||
this.getStreamsByGameId = (gameId, limit = 10) => { | ||
const params = { | ||
game_id: gameId, | ||
first: limit, | ||
}; | ||
return this.request().get('/streams', { params }) | ||
.then(response => response.data); | ||
}; | ||
this.getUsers = (userOrUsers) => { | ||
@@ -31,0 +39,0 @@ const params = { |
import Service from './Service'; | ||
import TwitchObject from '../StreamObjects/TwitchObject'; | ||
declare class Twitch extends Service { | ||
@@ -6,4 +7,5 @@ private api; | ||
constructor(clientId: string, clientSecret: string); | ||
getStreams: (stream: string | string[]) => any; | ||
getStreamsByGame: (gameName: string, limit?: number) => Promise<TwitchObject[]>; | ||
getStreams: (stream: string | string[]) => Promise<TwitchObject[]>; | ||
} | ||
export default Twitch; |
@@ -11,7 +11,33 @@ "use strict"; | ||
this.service = 'twitch'; | ||
this.getStreamsByGame = (gameName, limit = 10) => { | ||
return this.api.getGamesByName(gameName) | ||
.then((data) => data.data) | ||
.then((games) => Number(games[0].id)) | ||
.then((gameId) => { | ||
return this.api.getStreamsByGameId(gameId, limit) | ||
.then(data => data.data) | ||
.then((streams) => { | ||
const userIds = streams.map((stream) => stream.user_id); | ||
return Promise.all([ | ||
this.api.getUsers(userIds), | ||
Promise.all(userIds.map((userId) => this.api.getNumFollowers(userId))), | ||
]).then((result) => { | ||
const users = result[0]; | ||
const followers = result[1]; | ||
return streams.map((stream, key) => { | ||
return new TwitchObject_1.default({ | ||
stream, | ||
// ts-ignore | ||
user: users[key], | ||
game: { name: gameName }, | ||
followers: followers[key], | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
this.getStreams = (stream) => { | ||
const getStreams = this.api.getStreams(stream); | ||
const getUsers = this.api.getUsers(stream); | ||
return Promise.all([ | ||
getStreams, getUsers, | ||
this.api.getStreams(stream), this.api.getUsers(stream), | ||
]).then((result) => { | ||
@@ -18,0 +44,0 @@ const streams = result[0].data; |
{ | ||
"name": "stream-rally", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A Node.js module to aggregate (or rally) and manipulate streams from different services into a single list.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39063
1163