Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/commands/implementations/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const Command = require('../command-interface');
const CommandOutput = require('../command-output');

function getLatestVideo(input, services) {
return services.youtube
return services.dggApi
.getLatestUploadedVideo()
.then(
(latestVideo) =>
new CommandOutput(
null,
`"${latestVideo.snippet.title}" posted ${moment(
latestVideo.snippet.publishedAt,
).fromNow()} https://youtu.be/${latestVideo.snippet.resourceId.videoId}`,
`"${latestVideo.title}" posted ${moment(
latestVideo.publishDate,
).fromNow()} https://youtu.be/${latestVideo.id}`,
),
)
.catch((err) => new CommandOutput(err, "Oops. Something didn't work. Check the logs."));
Expand Down
7 changes: 1 addition & 6 deletions lib/configuration/sample.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,13 @@
"username": "yourUsername",
"password": "yourPassword"
},
"youtube": {
"YOUTUBE_API_KEY": "",
"YOUTUBE_CHANNEL": "",
"liveViewerCountTimeToLiveSeconds": 300
},
"googleCalendar": {
"GOOGLE_CALENDAR_API_KEY": "xxxxxxxxxxxx",
"GOOGLE_CALENDAR_ID": "xxxxxxxxxxxxx",
"SCHEDULE_LINK": "https://destiny.gg/schedule"
},
"dggApi": {
"url": "https://www.destiny.gg/api/info/stream"
"baseUrl": "https://www.destiny.gg"
},
"redditVote": {
"enabled": false,
Expand Down
14 changes: 13 additions & 1 deletion lib/services/dgg-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DggApi {

getStreamInfo() {
return axios
.get(this.config.url, {
.get(`${this.config.baseUrl}/api/info/stream`, {
headers: {
Accept: 'application/json',
},
Expand All @@ -20,6 +20,18 @@ class DggApi {
})
.catch((err) => this.log.error('Error retrieving data from dgg api.', err));
}

getListOfUploadedVideos() {
return axios
.get(`${this.config.baseUrl}/api/info/videos`, {
headers: { Accept: 'application/json' },
})
.then((res) => res.data.data);
}

getLatestUploadedVideo() {
return this.getListOfUploadedVideos().then((videos) => videos[0]);
}
}

module.exports = DggApi;
2 changes: 0 additions & 2 deletions lib/services/service-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const SpamDetection = require('./spam-detection');
const ScheduledCommands = require('./message-scheduler');
const gulagService = require('./gulag');
const LastFm = require('./lastfm');
const YouTube = require('./youtube.js');
const GoogleCal = require('./schedule.js');
const RoleCache = require('./role-cache.js');
const DggApi = require('./dgg-api');
Expand Down Expand Up @@ -38,7 +37,6 @@ class Services {
this.scheduledCommands = new ScheduledCommands(serviceConfigurations.schedule);
this.gulag = gulagService;
this.lastfm = new LastFm(serviceConfigurations.lastFm);
this.youtube = new YouTube(serviceConfigurations.youtube);
this.schedule = new GoogleCal(serviceConfigurations.googleCalendar);
this.fakeScheduler = new FakeScheduler(serviceConfigurations.schedule);
this.dggApi = new DggApi(serviceConfigurations.dggApi, this.logger);
Expand Down
160 changes: 0 additions & 160 deletions lib/services/youtube.js

This file was deleted.

34 changes: 34 additions & 0 deletions tests/lib/services/dgg-api.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const assert = require('assert');
const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru();
const mockResponses = require('./mocks/dgg-api-responses.json');

describe('DggApi Tests', () => {
const config = { baseUrl: 'https://www.destiny.gg' };

let axiosGet;
let DggApi;
let dggApi;

beforeEach(function () {
axiosGet = sinon.stub();
DggApi = proxyquire('../../../lib/services/dgg-api', {
axios: { default: { get: axiosGet } },
});
dggApi = new DggApi(config);
});

it('Gets the channel\'s uploaded videos', function () {
axiosGet.withArgs(`${config.baseUrl}/api/info/videos`).resolves({ data: mockResponses.videos });
return dggApi.getListOfUploadedVideos().then((response) => {
assert.deepStrictEqual(response, mockResponses.videos.data);
});
});

it('Gets the latest uploaded video', function () {
axiosGet.withArgs(`${config.baseUrl}/api/info/videos`).resolves({ data: mockResponses.videos });
return dggApi.getLatestUploadedVideo().then((response) => {
assert.deepStrictEqual(response, mockResponses.videos.data[0]);
});
});
});
33 changes: 33 additions & 0 deletions tests/lib/services/mocks/dgg-api-responses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"videos": {
"status": "success",
"data": [
{
"id": "uenf3uYDKBE",
"title": "POLITICON - DESTINY REACTS",
"mediumThumbnailUrl": "https://i.ytimg.com/vi/uenf3uYDKBE/mqdefault.jpg",
"highThumbnailUrl": "https://i.ytimg.com/vi/uenf3uYDKBE/hqdefault.jpg",
"streamViewers": null,
"streamStartTime": null,
"streamEndTime": null,
"url": "https://www.youtube.com/watch?v=uenf3uYDKBE",
"thumbnailHref": "https://i.ytimg.com/vi/uenf3uYDKBE/hqdefault.jpg",
"publishDate": "2018-10-22T11:10:49+00:00",
"embedUrl": "/bigscreen?vid=uenf3uYDKBE"
},
{
"id": "abcdef12345",
"title": "Second video",
"mediumThumbnailUrl": "",
"highThumbnailUrl": "",
"streamViewers": null,
"streamStartTime": null,
"streamEndTime": null,
"url": "https://www.youtube.com/watch?v=abcdef12345",
"thumbnailHref": "",
"publishDate": "2018-10-21T11:10:49+00:00",
"embedUrl": "/bigscreen?vid=abcdef12345"
}
]
}
}
Loading
Loading