From cd6484ff0b5a62d08b327923e6da17cb86878fc4 Mon Sep 17 00:00:00 2001
From: Tarun Singh
Date: Mon, 29 Mar 2021 19:03:45 +0530
Subject: [PATCH 01/10] moved youtube base to youtube video base
---
services/youtube/youtube-base.js | 76 --------------------
services/youtube/youtube-comments.service.js | 4 +-
services/youtube/youtube-likes.service.js | 4 +-
services/youtube/youtube-views.service.js | 4 +-
4 files changed, 6 insertions(+), 82 deletions(-)
delete mode 100644 services/youtube/youtube-base.js
diff --git a/services/youtube/youtube-base.js b/services/youtube/youtube-base.js
deleted file mode 100644
index 16a9017283e6d..0000000000000
--- a/services/youtube/youtube-base.js
+++ /dev/null
@@ -1,76 +0,0 @@
-'use strict'
-
-const Joi = require('joi')
-const { BaseJsonService, NotFound } = require('..')
-const { metric } = require('../text-formatters')
-const { nonNegativeInteger } = require('../validators')
-
-const documentation = `
-By using the YouTube badges provided by Shields.io, you are agreeing to be bound by the YouTube Terms of Service. These can be found here:
-https://www.youtube.com/t/terms
`
-
-const schema = Joi.object({
- items: Joi.array()
- .items(
- Joi.object({
- statistics: Joi.object({
- viewCount: nonNegativeInteger,
- likeCount: nonNegativeInteger,
- dislikeCount: nonNegativeInteger,
- commentCount: nonNegativeInteger,
- }).required(),
- })
- )
- .required(),
-}).required()
-
-class YouTubeBase extends BaseJsonService {
- static category = 'social'
-
- static auth = {
- passKey: 'youtube_api_key',
- authorizedOrigins: ['https://www.googleapis.com'],
- isRequired: true,
- }
-
- static defaultBadgeData = {
- label: 'youtube',
- color: 'red',
- namedLogo: 'youtube',
- }
-
- static renderSingleStat({ statistics, statisticName, videoId }) {
- return {
- label: `${statisticName}s`,
- message: metric(statistics[`${statisticName}Count`]),
- style: 'social',
- link: `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`,
- }
- }
-
- async fetch({ videoId }) {
- return this._requestJson(
- this.authHelper.withQueryStringAuth(
- { passKey: 'key' },
- {
- schema,
- url: 'https://www.googleapis.com/youtube/v3/videos',
- options: {
- qs: { id: videoId, part: 'statistics' },
- },
- }
- )
- )
- }
-
- async handle({ videoId }, queryParams) {
- const json = await this.fetch({ videoId })
- if (json.items.length === 0) {
- throw new NotFound({ prettyMessage: 'video not found' })
- }
- const statistics = json.items[0].statistics
- return this.constructor.render({ statistics, videoId }, queryParams)
- }
-}
-
-module.exports = { documentation, YouTubeBase }
diff --git a/services/youtube/youtube-comments.service.js b/services/youtube/youtube-comments.service.js
index 000a03a533eee..682d684cca3fa 100644
--- a/services/youtube/youtube-comments.service.js
+++ b/services/youtube/youtube-comments.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeVideoBase } = require('./youtube-video-base')
-module.exports = class YouTubeComments extends YouTubeBase {
+module.exports = class YouTubeComments extends YouTubeVideoBase {
static route = {
base: 'youtube/comments',
pattern: ':videoId',
diff --git a/services/youtube/youtube-likes.service.js b/services/youtube/youtube-likes.service.js
index 211a8d60e4bbb..0edecb7f0e0a7 100644
--- a/services/youtube/youtube-likes.service.js
+++ b/services/youtube/youtube-likes.service.js
@@ -2,7 +2,7 @@
const Joi = require('joi')
const { metric } = require('../text-formatters')
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeVideoBase } = require('./youtube-video-base')
const documentationWithDislikes = `
${documentation}
@@ -16,7 +16,7 @@ const queryParamSchema = Joi.object({
withDislikes: Joi.equal(''),
}).required()
-module.exports = class YouTubeLikes extends YouTubeBase {
+module.exports = class YouTubeLikes extends YouTubeVideoBase {
static route = {
base: 'youtube/likes',
pattern: ':videoId',
diff --git a/services/youtube/youtube-views.service.js b/services/youtube/youtube-views.service.js
index 2516df780b7ce..f78b83bd426aa 100644
--- a/services/youtube/youtube-views.service.js
+++ b/services/youtube/youtube-views.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeVideoBase } = require('./youtube-video-base')
-module.exports = class YouTubeViews extends YouTubeBase {
+module.exports = class YouTubeViews extends YouTubeVideoBase {
static route = {
base: 'youtube/views',
pattern: ':videoId',
From 7d454d3e6d5b9ff558ef2ba9d27dddb663f36ec7 Mon Sep 17 00:00:00 2001
From: Tarun Singh
Date: Mon, 29 Mar 2021 19:08:05 +0530
Subject: [PATCH 02/10] added youtube channel subscribers shield
---
services/youtube/youtube-channel-base.js | 77 +++++++++++++++++++
.../youtube/youtube-subscribers.service.js | 35 +++++++++
services/youtube/youtube-video-base.js | 76 ++++++++++++++++++
3 files changed, 188 insertions(+)
create mode 100644 services/youtube/youtube-channel-base.js
create mode 100644 services/youtube/youtube-subscribers.service.js
create mode 100644 services/youtube/youtube-video-base.js
diff --git a/services/youtube/youtube-channel-base.js b/services/youtube/youtube-channel-base.js
new file mode 100644
index 0000000000000..30d4eb3cb0fe7
--- /dev/null
+++ b/services/youtube/youtube-channel-base.js
@@ -0,0 +1,77 @@
+'use strict'
+
+const Joi = require('joi')
+const { BaseJsonService, NotFound } = require('..')
+const { metric } = require('../text-formatters')
+const { nonNegativeInteger } = require('../validators')
+
+const documentation = `
+By using the YouTube badges provided by Shields.io, you are agreeing to be bound by the YouTube Terms of Service. These can be found here:
+https://www.youtube.com/t/terms
`
+
+const schema = Joi.object({
+ items: Joi.array()
+ .items(
+ Joi.object({
+ statistics: Joi.object({
+ viewCount: nonNegativeInteger,
+ subscriberCount: nonNegativeInteger,
+ hiddenSubscriberCount: Joi.boolean().required(),
+ videoCount: nonNegativeInteger,
+ }).required(),
+ })
+ )
+ .required(),
+}).required()
+
+class YouTubeChannelBase extends BaseJsonService {
+ static category = 'social'
+
+ static auth = {
+ passKey: 'youtube_api_key',
+ authorizedOrigins: ['https://youtube.googleapis.com'],
+ isRequired: true,
+ }
+
+ static defaultBadgeData = {
+ label: 'youtube',
+ color: 'red',
+ namedLogo: 'youtube',
+ }
+
+ static renderSingleStat({ statistics, statisticName, channelId }) {
+ return {
+ label: `${statisticName}s`,
+ message: metric(statistics[`${statisticName}Count`]),
+ style: 'social',
+ link: `https://www.youtube.com/channel/${encodeURIComponent(channelId)}`,
+ }
+ }
+
+ async fetch({ channelId }) {
+ return this._requestJson(
+ this.authHelper.withQueryStringAuth(
+ { passKey: 'key' },
+ {
+ schema,
+ url: 'https://youtube.googleapis.com/youtube/v3/channels',
+ options: {
+ qs: { id: channelId, part: 'statistics' },
+ },
+ }
+ )
+ )
+ }
+
+ async handle({ channelId }, queryParams) {
+ const json = await this.fetch({ channelId })
+ console.log(JSON.stringify(json))
+ if (json.items.length === 0) {
+ throw new NotFound({ prettyMessage: 'channel not found' })
+ }
+ const statistics = json.items[0].statistics
+ return this.constructor.render({ statistics, channelId }, queryParams)
+ }
+}
+
+module.exports = { documentation, YouTubeChannelBase }
diff --git a/services/youtube/youtube-subscribers.service.js b/services/youtube/youtube-subscribers.service.js
new file mode 100644
index 0000000000000..9a6b52c7f6be9
--- /dev/null
+++ b/services/youtube/youtube-subscribers.service.js
@@ -0,0 +1,35 @@
+'use strict'
+
+const { documentation, YouTubeChannelBase } = require('./youtube-channel-base')
+
+module.exports = class YouTubeSubscribes extends YouTubeChannelBase {
+ static route = {
+ base: 'youtube/channel/subscribers',
+ pattern: ':channelId',
+ }
+
+ static get examples() {
+ const preview = this.render({
+ statistics: { subscriberCount: 14577 },
+ channelId: 'UCTNq28Ah5eyDgsYOA0oHzew',
+ })
+ // link[] is not allowed in examples
+ delete preview.link
+ return [
+ {
+ title: 'YouTube Subscriber Counts',
+ namedParams: { channelId: 'UCTNq28Ah5eyDgsYOA0oHzew' },
+ staticPreview: preview,
+ documentation,
+ },
+ ]
+ }
+
+ static render({ statistics, channelId }) {
+ return super.renderSingleStat({
+ statistics,
+ statisticName: 'subscriber',
+ channelId,
+ })
+ }
+}
diff --git a/services/youtube/youtube-video-base.js b/services/youtube/youtube-video-base.js
new file mode 100644
index 0000000000000..24aa4b60e163d
--- /dev/null
+++ b/services/youtube/youtube-video-base.js
@@ -0,0 +1,76 @@
+'use strict'
+
+const Joi = require('joi')
+const { BaseJsonService, NotFound } = require('..')
+const { metric } = require('../text-formatters')
+const { nonNegativeInteger } = require('../validators')
+
+const documentation = `
+By using the YouTube badges provided by Shields.io, you are agreeing to be bound by the YouTube Terms of Service. These can be found here:
+https://www.youtube.com/t/terms
`
+
+const schema = Joi.object({
+ items: Joi.array()
+ .items(
+ Joi.object({
+ statistics: Joi.object({
+ viewCount: nonNegativeInteger,
+ likeCount: nonNegativeInteger,
+ dislikeCount: nonNegativeInteger,
+ commentCount: nonNegativeInteger,
+ }).required(),
+ })
+ )
+ .required(),
+}).required()
+
+class YouTubeVideoBase extends BaseJsonService {
+ static category = 'social'
+
+ static auth = {
+ passKey: 'youtube_api_key',
+ authorizedOrigins: ['https://www.googleapis.com'],
+ isRequired: true,
+ }
+
+ static defaultBadgeData = {
+ label: 'youtube',
+ color: 'red',
+ namedLogo: 'youtube',
+ }
+
+ static renderSingleStat({ statistics, statisticName, videoId }) {
+ return {
+ label: `${statisticName}s`,
+ message: metric(statistics[`${statisticName}Count`]),
+ style: 'social',
+ link: `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`,
+ }
+ }
+
+ async fetch({ videoId }) {
+ return this._requestJson(
+ this.authHelper.withQueryStringAuth(
+ { passKey: 'key' },
+ {
+ schema,
+ url: 'https://www.googleapis.com/youtube/v3/videos',
+ options: {
+ qs: { id: videoId, part: 'statistics' },
+ },
+ }
+ )
+ )
+ }
+
+ async handle({ videoId }, queryParams) {
+ const json = await this.fetch({ videoId })
+ if (json.items.length === 0) {
+ throw new NotFound({ prettyMessage: 'video not found' })
+ }
+ const statistics = json.items[0].statistics
+ return this.constructor.render({ statistics, videoId }, queryParams)
+ }
+}
+
+module.exports = { documentation, YouTubeVideoBase }
From f825efec6b7b7cb5744b8b64cbf76de670152694 Mon Sep 17 00:00:00 2001
From: Tarun Singh
Date: Mon, 29 Mar 2021 19:08:34 +0530
Subject: [PATCH 03/10] added youtube total channel views shield
---
.../youtube/youtube-channel-views.service.js | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 services/youtube/youtube-channel-views.service.js
diff --git a/services/youtube/youtube-channel-views.service.js b/services/youtube/youtube-channel-views.service.js
new file mode 100644
index 0000000000000..2d95c1a37adb8
--- /dev/null
+++ b/services/youtube/youtube-channel-views.service.js
@@ -0,0 +1,35 @@
+'use strict'
+
+const { documentation, YouTubeChannelBase } = require('./youtube-channel-base')
+
+module.exports = class YouTubeSubscribes extends YouTubeChannelBase {
+ static route = {
+ base: 'youtube/channel/views',
+ pattern: ':channelId',
+ }
+
+ static get examples() {
+ const preview = this.render({
+ statistics: { viewCount: 30543 },
+ channelId: 'UCTNq28Ah5eyDgsYOA0oHzew',
+ })
+ // link[] is not allowed in examples
+ delete preview.link
+ return [
+ {
+ title: 'YouTube Channel Views',
+ namedParams: { channelId: 'UCTNq28Ah5eyDgsYOA0oHzew' },
+ staticPreview: preview,
+ documentation,
+ },
+ ]
+ }
+
+ static render({ statistics, channelId }) {
+ return super.renderSingleStat({
+ statistics,
+ statisticName: 'view',
+ channelId,
+ })
+ }
+}
From 96c184f51160dea8b59577b331f82ae0843dc0d2 Mon Sep 17 00:00:00 2001
From: Tarun Singh
Date: Mon, 29 Mar 2021 19:36:55 +0530
Subject: [PATCH 04/10] tests and imrooved no data logic
---
services/youtube/youtube-channel-base.js | 28 ++++++++++---------
.../youtube/youtube-channel-views.service.js | 2 +-
.../youtube/youtube-channel-views.tester.js | 25 +++++++++++++++++
.../youtube/youtube-subscribers.tester.js | 25 +++++++++++++++++
4 files changed, 66 insertions(+), 14 deletions(-)
create mode 100644 services/youtube/youtube-channel-views.tester.js
create mode 100644 services/youtube/youtube-subscribers.tester.js
diff --git a/services/youtube/youtube-channel-base.js b/services/youtube/youtube-channel-base.js
index 30d4eb3cb0fe7..01d6ce17bec23 100644
--- a/services/youtube/youtube-channel-base.js
+++ b/services/youtube/youtube-channel-base.js
@@ -10,18 +10,20 @@ const documentation = `
https://www.youtube.com/t/terms
`
const schema = Joi.object({
- items: Joi.array()
- .items(
- Joi.object({
- statistics: Joi.object({
- viewCount: nonNegativeInteger,
- subscriberCount: nonNegativeInteger,
- hiddenSubscriberCount: Joi.boolean().required(),
- videoCount: nonNegativeInteger,
- }).required(),
- })
- )
- .required(),
+ pageInfo: Joi.object({
+ totalResults: nonNegativeInteger,
+ resultsPerPage: nonNegativeInteger,
+ }).required(),
+ items: Joi.array().items(
+ Joi.object({
+ statistics: Joi.object({
+ viewCount: nonNegativeInteger,
+ subscriberCount: nonNegativeInteger,
+ hiddenSubscriberCount: Joi.boolean().required(),
+ videoCount: nonNegativeInteger,
+ }).required(),
+ })
+ ),
}).required()
class YouTubeChannelBase extends BaseJsonService {
@@ -66,7 +68,7 @@ class YouTubeChannelBase extends BaseJsonService {
async handle({ channelId }, queryParams) {
const json = await this.fetch({ channelId })
console.log(JSON.stringify(json))
- if (json.items.length === 0) {
+ if (json.pageInfo.totalResults === 0) {
throw new NotFound({ prettyMessage: 'channel not found' })
}
const statistics = json.items[0].statistics
diff --git a/services/youtube/youtube-channel-views.service.js b/services/youtube/youtube-channel-views.service.js
index 2d95c1a37adb8..858674e32b4ff 100644
--- a/services/youtube/youtube-channel-views.service.js
+++ b/services/youtube/youtube-channel-views.service.js
@@ -2,7 +2,7 @@
const { documentation, YouTubeChannelBase } = require('./youtube-channel-base')
-module.exports = class YouTubeSubscribes extends YouTubeChannelBase {
+module.exports = class YouTubeChannelViews extends YouTubeChannelBase {
static route = {
base: 'youtube/channel/views',
pattern: ':channelId',
diff --git a/services/youtube/youtube-channel-views.tester.js b/services/youtube/youtube-channel-views.tester.js
new file mode 100644
index 0000000000000..893a772b7bcbe
--- /dev/null
+++ b/services/youtube/youtube-channel-views.tester.js
@@ -0,0 +1,25 @@
+'use strict'
+
+const t = (module.exports = require('../tester').createServiceTester())
+const { noToken } = require('../test-helpers')
+const { isMetric } = require('../test-validators')
+const noYouTubeToken = noToken(require('./youtube-channel-views.service'))
+
+t.create('channel view count')
+ .skipWhen(noYouTubeToken)
+ .get('/UCTNq28Ah5eyDgsYOA0oHzew.json')
+ .expectBadge({
+ label: 'views',
+ message: isMetric,
+ color: 'red',
+ link: ['https://www.youtube.com/channel/UCTNq28Ah5eyDgsYOA0oHzew'],
+ })
+
+t.create('channel not found')
+ .skipWhen(noYouTubeToken)
+ .get('/doesnotexist.json')
+ .expectBadge({
+ label: 'youtube',
+ message: 'channel not found',
+ color: 'red',
+ })
diff --git a/services/youtube/youtube-subscribers.tester.js b/services/youtube/youtube-subscribers.tester.js
new file mode 100644
index 0000000000000..b0bf8e1e565b4
--- /dev/null
+++ b/services/youtube/youtube-subscribers.tester.js
@@ -0,0 +1,25 @@
+'use strict'
+
+const t = (module.exports = require('../tester').createServiceTester())
+const { noToken } = require('../test-helpers')
+const { isMetric } = require('../test-validators')
+const noYouTubeToken = noToken(require('./youtube-subscribers.service'))
+
+t.create('subscriber count')
+ .skipWhen(noYouTubeToken)
+ .get('/UCTNq28Ah5eyDgsYOA0oHzew.json')
+ .expectBadge({
+ label: 'subscribers',
+ message: isMetric,
+ color: 'red',
+ link: ['https://www.youtube.com/channel/UCTNq28Ah5eyDgsYOA0oHzew'],
+ })
+
+t.create('channel not found')
+ .skipWhen(noYouTubeToken)
+ .get('/doesnotexist.json')
+ .expectBadge({
+ label: 'youtube',
+ message: 'channel not found',
+ color: 'red',
+ })
From 1fdc37d4d98c28ea0886120661157bb9fdcc1632 Mon Sep 17 00:00:00 2001
From: Tarun Singh
Date: Mon, 29 Mar 2021 19:47:16 +0530
Subject: [PATCH 05/10] removed unnecessary console call
---
services/youtube/youtube-channel-base.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/services/youtube/youtube-channel-base.js b/services/youtube/youtube-channel-base.js
index 01d6ce17bec23..bb5ea65f77749 100644
--- a/services/youtube/youtube-channel-base.js
+++ b/services/youtube/youtube-channel-base.js
@@ -67,7 +67,6 @@ class YouTubeChannelBase extends BaseJsonService {
async handle({ channelId }, queryParams) {
const json = await this.fetch({ channelId })
- console.log(JSON.stringify(json))
if (json.pageInfo.totalResults === 0) {
throw new NotFound({ prettyMessage: 'channel not found' })
}
From 9d4c8fc6fbb76f1e0bcd99058ad9b4e0a4f8e1ce Mon Sep 17 00:00:00 2001
From: tarun7singh
Date: Wed, 31 Mar 2021 11:55:28 +0530
Subject: [PATCH 06/10] fixed netlify badge by adding new color scheme
---
services/netlify/netlify.service.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/services/netlify/netlify.service.js b/services/netlify/netlify.service.js
index bb53465289441..37485fde708d2 100644
--- a/services/netlify/netlify.service.js
+++ b/services/netlify/netlify.service.js
@@ -54,9 +54,9 @@ module.exports = class Netlify extends BaseSvgScrapingService {
const { buffer } = await this._request({
url,
})
- if (buffer.includes('#EAFAF9')) return { message: 'passing' }
- if (buffer.includes('#FFF3F4')) return { message: 'failing' }
- if (buffer.includes('#FEFAEA')) return { message: 'building' }
+ if (buffer.includes('#0D544F')) return { message: 'passing' }
+ if (buffer.includes('#900B31')) return { message: 'failing' }
+ if (buffer.includes('#AB6F10')) return { message: 'building' }
return { message: 'unknown' }
}
From ad9591bbf8793589deee492641d7ad57305b948d Mon Sep 17 00:00:00 2001
From: tarun7singh
Date: Fri, 2 Apr 2021 10:25:58 +0530
Subject: [PATCH 07/10] Revert "fixed netlify badge by adding new color scheme"
This reverts commit 9d4c8fc6fbb76f1e0bcd99058ad9b4e0a4f8e1ce.
---
services/netlify/netlify.service.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/services/netlify/netlify.service.js b/services/netlify/netlify.service.js
index 37485fde708d2..bb53465289441 100644
--- a/services/netlify/netlify.service.js
+++ b/services/netlify/netlify.service.js
@@ -54,9 +54,9 @@ module.exports = class Netlify extends BaseSvgScrapingService {
const { buffer } = await this._request({
url,
})
- if (buffer.includes('#0D544F')) return { message: 'passing' }
- if (buffer.includes('#900B31')) return { message: 'failing' }
- if (buffer.includes('#AB6F10')) return { message: 'building' }
+ if (buffer.includes('#EAFAF9')) return { message: 'passing' }
+ if (buffer.includes('#FFF3F4')) return { message: 'failing' }
+ if (buffer.includes('#FEFAEA')) return { message: 'building' }
return { message: 'unknown' }
}
From 5dcf2ae8a0d288f4c8caefe4867d175acc37fd6b Mon Sep 17 00:00:00 2001
From: tarun7singh
Date: Sat, 3 Apr 2021 02:29:27 +0530
Subject: [PATCH 08/10] combined channel & video base and other changes
---
services/youtube/youtube-base.js | 119 ++++++++++++++++++
services/youtube/youtube-channel-base.js | 78 ------------
.../youtube/youtube-channel-views.service.js | 8 +-
.../youtube/youtube-channel-views.tester.js | 4 +-
services/youtube/youtube-comments.service.js | 4 +-
services/youtube/youtube-likes.service.js | 4 +-
.../youtube/youtube-subscribers.service.js | 8 +-
.../youtube/youtube-subscribers.tester.js | 4 +-
services/youtube/youtube-video-base.js | 76 -----------
services/youtube/youtube-views.service.js | 4 +-
10 files changed, 137 insertions(+), 172 deletions(-)
create mode 100644 services/youtube/youtube-base.js
delete mode 100644 services/youtube/youtube-channel-base.js
delete mode 100644 services/youtube/youtube-video-base.js
diff --git a/services/youtube/youtube-base.js b/services/youtube/youtube-base.js
new file mode 100644
index 0000000000000..a85762c999058
--- /dev/null
+++ b/services/youtube/youtube-base.js
@@ -0,0 +1,119 @@
+'use strict'
+
+const Joi = require('joi')
+const { BaseJsonService, NotFound } = require('..')
+const { metric } = require('../text-formatters')
+const { nonNegativeInteger } = require('../validators')
+
+const documentation = `
+By using the YouTube badges provided by Shields.io, you are agreeing to be bound by the YouTube Terms of Service. These can be found here:
+https://www.youtube.com/t/terms
`
+
+const channelSchema = Joi.object({
+ pageInfo: Joi.object({
+ totalResults: nonNegativeInteger,
+ resultsPerPage: nonNegativeInteger,
+ }).required(),
+ items: Joi.array().items(
+ Joi.object({
+ statistics: Joi.object({
+ viewCount: nonNegativeInteger,
+ subscriberCount: nonNegativeInteger,
+ hiddenSubscriberCount: Joi.boolean(),
+ videoCount: nonNegativeInteger,
+ }),
+ })
+ ),
+}).required()
+
+const videoSchema = Joi.object({
+ pageInfo: Joi.object({
+ totalResults: nonNegativeInteger,
+ resultsPerPage: nonNegativeInteger,
+ }).required(),
+ items: Joi.array().items(
+ Joi.object({
+ statistics: Joi.object({
+ viewCount: nonNegativeInteger,
+ likeCount: nonNegativeInteger,
+ dislikeCount: nonNegativeInteger,
+ commentCount: nonNegativeInteger,
+ }),
+ })
+ ),
+}).required()
+
+class YouTubeBase extends BaseJsonService {
+ static category = 'social'
+
+ static auth = {
+ passKey: 'youtube_api_key',
+ authorizedOrigins: ['https://www.googleapis.com'],
+ isRequired: true,
+ }
+
+ static defaultBadgeData = {
+ label: 'youtube',
+ color: 'red',
+ namedLogo: 'youtube',
+ }
+
+ static renderSingleStat({ statistics, statisticName, channelId, videoId }) {
+ let link = ''
+ if (channelId) {
+ link = `https://www.youtube.com/channel/${encodeURIComponent(channelId)}`
+ }
+ if (videoId) {
+ link = `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`
+ }
+ return {
+ label: `${statisticName}s`,
+ message: metric(statistics[`${statisticName}Count`]),
+ style: 'social',
+ link,
+ }
+ }
+
+ async fetch({ channelId, videoId }) {
+ let schema, url
+ if (channelId) {
+ schema = channelSchema
+ url = 'https://www.googleapis.com/youtube/v3/channels'
+ }
+ if (videoId) {
+ schema = videoSchema
+ url = `https://www.googleapis.com/youtube/v3/videos`
+ }
+ return this._requestJson(
+ this.authHelper.withQueryStringAuth(
+ { passKey: 'key' },
+ {
+ schema,
+ url,
+ options: {
+ qs: { id: channelId || videoId, part: 'statistics' },
+ },
+ }
+ )
+ )
+ }
+
+ async handle({ channelId, videoId }, queryParams) {
+ const json = await this.fetch({ channelId, videoId })
+ if (json.pageInfo.totalResults === 0) {
+ if (channelId) {
+ throw new NotFound({ prettyMessage: 'channel not found' })
+ }
+ if (videoId) {
+ throw new NotFound({ prettyMessage: 'video not found' })
+ }
+ }
+ const statistics = json.items[0].statistics
+ return this.constructor.render(
+ { statistics, channelId, videoId },
+ queryParams
+ )
+ }
+}
+
+module.exports = { documentation, YouTubeBase }
diff --git a/services/youtube/youtube-channel-base.js b/services/youtube/youtube-channel-base.js
deleted file mode 100644
index bb5ea65f77749..0000000000000
--- a/services/youtube/youtube-channel-base.js
+++ /dev/null
@@ -1,78 +0,0 @@
-'use strict'
-
-const Joi = require('joi')
-const { BaseJsonService, NotFound } = require('..')
-const { metric } = require('../text-formatters')
-const { nonNegativeInteger } = require('../validators')
-
-const documentation = `
-By using the YouTube badges provided by Shields.io, you are agreeing to be bound by the YouTube Terms of Service. These can be found here:
-https://www.youtube.com/t/terms
`
-
-const schema = Joi.object({
- pageInfo: Joi.object({
- totalResults: nonNegativeInteger,
- resultsPerPage: nonNegativeInteger,
- }).required(),
- items: Joi.array().items(
- Joi.object({
- statistics: Joi.object({
- viewCount: nonNegativeInteger,
- subscriberCount: nonNegativeInteger,
- hiddenSubscriberCount: Joi.boolean().required(),
- videoCount: nonNegativeInteger,
- }).required(),
- })
- ),
-}).required()
-
-class YouTubeChannelBase extends BaseJsonService {
- static category = 'social'
-
- static auth = {
- passKey: 'youtube_api_key',
- authorizedOrigins: ['https://youtube.googleapis.com'],
- isRequired: true,
- }
-
- static defaultBadgeData = {
- label: 'youtube',
- color: 'red',
- namedLogo: 'youtube',
- }
-
- static renderSingleStat({ statistics, statisticName, channelId }) {
- return {
- label: `${statisticName}s`,
- message: metric(statistics[`${statisticName}Count`]),
- style: 'social',
- link: `https://www.youtube.com/channel/${encodeURIComponent(channelId)}`,
- }
- }
-
- async fetch({ channelId }) {
- return this._requestJson(
- this.authHelper.withQueryStringAuth(
- { passKey: 'key' },
- {
- schema,
- url: 'https://youtube.googleapis.com/youtube/v3/channels',
- options: {
- qs: { id: channelId, part: 'statistics' },
- },
- }
- )
- )
- }
-
- async handle({ channelId }, queryParams) {
- const json = await this.fetch({ channelId })
- if (json.pageInfo.totalResults === 0) {
- throw new NotFound({ prettyMessage: 'channel not found' })
- }
- const statistics = json.items[0].statistics
- return this.constructor.render({ statistics, channelId }, queryParams)
- }
-}
-
-module.exports = { documentation, YouTubeChannelBase }
diff --git a/services/youtube/youtube-channel-views.service.js b/services/youtube/youtube-channel-views.service.js
index 858674e32b4ff..936f3f44a1e3f 100644
--- a/services/youtube/youtube-channel-views.service.js
+++ b/services/youtube/youtube-channel-views.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeChannelBase } = require('./youtube-channel-base')
+const { documentation, YouTubeBase } = require('./youtube-base')
-module.exports = class YouTubeChannelViews extends YouTubeChannelBase {
+module.exports = class YouTubeChannelViews extends YouTubeBase {
static route = {
base: 'youtube/channel/views',
pattern: ':channelId',
@@ -11,14 +11,14 @@ module.exports = class YouTubeChannelViews extends YouTubeChannelBase {
static get examples() {
const preview = this.render({
statistics: { viewCount: 30543 },
- channelId: 'UCTNq28Ah5eyDgsYOA0oHzew',
+ channelId: 'UC8butISFwT-Wl7EV0hUK0BQ',
})
// link[] is not allowed in examples
delete preview.link
return [
{
title: 'YouTube Channel Views',
- namedParams: { channelId: 'UCTNq28Ah5eyDgsYOA0oHzew' },
+ namedParams: { channelId: 'UC8butISFwT-Wl7EV0hUK0BQ' },
staticPreview: preview,
documentation,
},
diff --git a/services/youtube/youtube-channel-views.tester.js b/services/youtube/youtube-channel-views.tester.js
index 893a772b7bcbe..eab2689fd0ec7 100644
--- a/services/youtube/youtube-channel-views.tester.js
+++ b/services/youtube/youtube-channel-views.tester.js
@@ -7,12 +7,12 @@ const noYouTubeToken = noToken(require('./youtube-channel-views.service'))
t.create('channel view count')
.skipWhen(noYouTubeToken)
- .get('/UCTNq28Ah5eyDgsYOA0oHzew.json')
+ .get('/UC8butISFwT-Wl7EV0hUK0BQ.json')
.expectBadge({
label: 'views',
message: isMetric,
color: 'red',
- link: ['https://www.youtube.com/channel/UCTNq28Ah5eyDgsYOA0oHzew'],
+ link: ['https://www.youtube.com/channel/UC8butISFwT-Wl7EV0hUK0BQ'],
})
t.create('channel not found')
diff --git a/services/youtube/youtube-comments.service.js b/services/youtube/youtube-comments.service.js
index 682d684cca3fa..000a03a533eee 100644
--- a/services/youtube/youtube-comments.service.js
+++ b/services/youtube/youtube-comments.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeVideoBase } = require('./youtube-video-base')
+const { documentation, YouTubeBase } = require('./youtube-base')
-module.exports = class YouTubeComments extends YouTubeVideoBase {
+module.exports = class YouTubeComments extends YouTubeBase {
static route = {
base: 'youtube/comments',
pattern: ':videoId',
diff --git a/services/youtube/youtube-likes.service.js b/services/youtube/youtube-likes.service.js
index 0edecb7f0e0a7..211a8d60e4bbb 100644
--- a/services/youtube/youtube-likes.service.js
+++ b/services/youtube/youtube-likes.service.js
@@ -2,7 +2,7 @@
const Joi = require('joi')
const { metric } = require('../text-formatters')
-const { documentation, YouTubeVideoBase } = require('./youtube-video-base')
+const { documentation, YouTubeBase } = require('./youtube-base')
const documentationWithDislikes = `
${documentation}
@@ -16,7 +16,7 @@ const queryParamSchema = Joi.object({
withDislikes: Joi.equal(''),
}).required()
-module.exports = class YouTubeLikes extends YouTubeVideoBase {
+module.exports = class YouTubeLikes extends YouTubeBase {
static route = {
base: 'youtube/likes',
pattern: ':videoId',
diff --git a/services/youtube/youtube-subscribers.service.js b/services/youtube/youtube-subscribers.service.js
index 9a6b52c7f6be9..13755ca2ec591 100644
--- a/services/youtube/youtube-subscribers.service.js
+++ b/services/youtube/youtube-subscribers.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeChannelBase } = require('./youtube-channel-base')
+const { documentation, YouTubeBase } = require('./youtube-base')
-module.exports = class YouTubeSubscribes extends YouTubeChannelBase {
+module.exports = class YouTubeSubscribes extends YouTubeBase {
static route = {
base: 'youtube/channel/subscribers',
pattern: ':channelId',
@@ -11,14 +11,14 @@ module.exports = class YouTubeSubscribes extends YouTubeChannelBase {
static get examples() {
const preview = this.render({
statistics: { subscriberCount: 14577 },
- channelId: 'UCTNq28Ah5eyDgsYOA0oHzew',
+ channelId: 'UC8butISFwT-Wl7EV0hUK0BQ',
})
// link[] is not allowed in examples
delete preview.link
return [
{
title: 'YouTube Subscriber Counts',
- namedParams: { channelId: 'UCTNq28Ah5eyDgsYOA0oHzew' },
+ namedParams: { channelId: 'UC8butISFwT-Wl7EV0hUK0BQ' },
staticPreview: preview,
documentation,
},
diff --git a/services/youtube/youtube-subscribers.tester.js b/services/youtube/youtube-subscribers.tester.js
index b0bf8e1e565b4..acff789b0c64b 100644
--- a/services/youtube/youtube-subscribers.tester.js
+++ b/services/youtube/youtube-subscribers.tester.js
@@ -7,12 +7,12 @@ const noYouTubeToken = noToken(require('./youtube-subscribers.service'))
t.create('subscriber count')
.skipWhen(noYouTubeToken)
- .get('/UCTNq28Ah5eyDgsYOA0oHzew.json')
+ .get('/UC8butISFwT-Wl7EV0hUK0BQ.json')
.expectBadge({
label: 'subscribers',
message: isMetric,
color: 'red',
- link: ['https://www.youtube.com/channel/UCTNq28Ah5eyDgsYOA0oHzew'],
+ link: ['https://www.youtube.com/channel/UC8butISFwT-Wl7EV0hUK0BQ'],
})
t.create('channel not found')
diff --git a/services/youtube/youtube-video-base.js b/services/youtube/youtube-video-base.js
deleted file mode 100644
index 24aa4b60e163d..0000000000000
--- a/services/youtube/youtube-video-base.js
+++ /dev/null
@@ -1,76 +0,0 @@
-'use strict'
-
-const Joi = require('joi')
-const { BaseJsonService, NotFound } = require('..')
-const { metric } = require('../text-formatters')
-const { nonNegativeInteger } = require('../validators')
-
-const documentation = `
-By using the YouTube badges provided by Shields.io, you are agreeing to be bound by the YouTube Terms of Service. These can be found here:
-https://www.youtube.com/t/terms
`
-
-const schema = Joi.object({
- items: Joi.array()
- .items(
- Joi.object({
- statistics: Joi.object({
- viewCount: nonNegativeInteger,
- likeCount: nonNegativeInteger,
- dislikeCount: nonNegativeInteger,
- commentCount: nonNegativeInteger,
- }).required(),
- })
- )
- .required(),
-}).required()
-
-class YouTubeVideoBase extends BaseJsonService {
- static category = 'social'
-
- static auth = {
- passKey: 'youtube_api_key',
- authorizedOrigins: ['https://www.googleapis.com'],
- isRequired: true,
- }
-
- static defaultBadgeData = {
- label: 'youtube',
- color: 'red',
- namedLogo: 'youtube',
- }
-
- static renderSingleStat({ statistics, statisticName, videoId }) {
- return {
- label: `${statisticName}s`,
- message: metric(statistics[`${statisticName}Count`]),
- style: 'social',
- link: `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`,
- }
- }
-
- async fetch({ videoId }) {
- return this._requestJson(
- this.authHelper.withQueryStringAuth(
- { passKey: 'key' },
- {
- schema,
- url: 'https://www.googleapis.com/youtube/v3/videos',
- options: {
- qs: { id: videoId, part: 'statistics' },
- },
- }
- )
- )
- }
-
- async handle({ videoId }, queryParams) {
- const json = await this.fetch({ videoId })
- if (json.items.length === 0) {
- throw new NotFound({ prettyMessage: 'video not found' })
- }
- const statistics = json.items[0].statistics
- return this.constructor.render({ statistics, videoId }, queryParams)
- }
-}
-
-module.exports = { documentation, YouTubeVideoBase }
diff --git a/services/youtube/youtube-views.service.js b/services/youtube/youtube-views.service.js
index f78b83bd426aa..2516df780b7ce 100644
--- a/services/youtube/youtube-views.service.js
+++ b/services/youtube/youtube-views.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeVideoBase } = require('./youtube-video-base')
+const { documentation, YouTubeBase } = require('./youtube-base')
-module.exports = class YouTubeViews extends YouTubeVideoBase {
+module.exports = class YouTubeViews extends YouTubeBase {
static route = {
base: 'youtube/views',
pattern: ':videoId',
From cb5f0ff2712c7b8bc7942b49788eebb296732901 Mon Sep 17 00:00:00 2001
From: tarun7singh
Date: Sat, 3 Apr 2021 02:34:47 +0530
Subject: [PATCH 09/10] badge name and validation changes
---
services/youtube/youtube-base.js | 2 --
services/youtube/youtube-subscribers.service.js | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/services/youtube/youtube-base.js b/services/youtube/youtube-base.js
index a85762c999058..4b1ab16590cc3 100644
--- a/services/youtube/youtube-base.js
+++ b/services/youtube/youtube-base.js
@@ -19,8 +19,6 @@ const channelSchema = Joi.object({
statistics: Joi.object({
viewCount: nonNegativeInteger,
subscriberCount: nonNegativeInteger,
- hiddenSubscriberCount: Joi.boolean(),
- videoCount: nonNegativeInteger,
}),
})
),
diff --git a/services/youtube/youtube-subscribers.service.js b/services/youtube/youtube-subscribers.service.js
index 13755ca2ec591..1fe1e3ed25780 100644
--- a/services/youtube/youtube-subscribers.service.js
+++ b/services/youtube/youtube-subscribers.service.js
@@ -17,7 +17,7 @@ module.exports = class YouTubeSubscribes extends YouTubeBase {
delete preview.link
return [
{
- title: 'YouTube Subscriber Counts',
+ title: 'YouTube Channel Subscribers',
namedParams: { channelId: 'UC8butISFwT-Wl7EV0hUK0BQ' },
staticPreview: preview,
documentation,
From 18fe9e82268f121994265b1969668aa97ec650cd Mon Sep 17 00:00:00 2001
From: PyvesB
Date: Sat, 3 Apr 2021 12:57:11 +0100
Subject: [PATCH 10/10] Slim down YouTubeBase implementation
---
services/youtube/youtube-base.js | 88 +++++++------------
.../youtube/youtube-channel-views.service.js | 14 ++-
services/youtube/youtube-comments.service.js | 14 ++-
services/youtube/youtube-comments.tester.js | 2 +-
services/youtube/youtube-likes.service.js | 16 ++--
services/youtube/youtube-likes.tester.js | 4 +-
.../youtube/youtube-subscribers.service.js | 10 +--
services/youtube/youtube-views.service.js | 14 ++-
services/youtube/youtube-views.tester.js | 2 +-
9 files changed, 64 insertions(+), 100 deletions(-)
diff --git a/services/youtube/youtube-base.js b/services/youtube/youtube-base.js
index 4b1ab16590cc3..ad2bfd83fc3c6 100644
--- a/services/youtube/youtube-base.js
+++ b/services/youtube/youtube-base.js
@@ -9,34 +9,25 @@ const documentation = `
By using the YouTube badges provided by Shields.io, you are agreeing to be bound by the YouTube Terms of Service. These can be found here:
https://www.youtube.com/t/terms
`
-const channelSchema = Joi.object({
+const schema = Joi.object({
pageInfo: Joi.object({
totalResults: nonNegativeInteger,
resultsPerPage: nonNegativeInteger,
}).required(),
items: Joi.array().items(
Joi.object({
- statistics: Joi.object({
- viewCount: nonNegativeInteger,
- subscriberCount: nonNegativeInteger,
- }),
- })
- ),
-}).required()
-
-const videoSchema = Joi.object({
- pageInfo: Joi.object({
- totalResults: nonNegativeInteger,
- resultsPerPage: nonNegativeInteger,
- }).required(),
- items: Joi.array().items(
- Joi.object({
- statistics: Joi.object({
- viewCount: nonNegativeInteger,
- likeCount: nonNegativeInteger,
- dislikeCount: nonNegativeInteger,
- commentCount: nonNegativeInteger,
- }),
+ statistics: Joi.alternatives(
+ Joi.object({
+ viewCount: nonNegativeInteger,
+ likeCount: nonNegativeInteger,
+ dislikeCount: nonNegativeInteger,
+ commentCount: nonNegativeInteger,
+ }),
+ Joi.object({
+ viewCount: nonNegativeInteger,
+ subscriberCount: nonNegativeInteger,
+ })
+ ),
})
),
}).required()
@@ -56,40 +47,24 @@ class YouTubeBase extends BaseJsonService {
namedLogo: 'youtube',
}
- static renderSingleStat({ statistics, statisticName, channelId, videoId }) {
- let link = ''
- if (channelId) {
- link = `https://www.youtube.com/channel/${encodeURIComponent(channelId)}`
- }
- if (videoId) {
- link = `https://www.youtube.com/watch?v=${encodeURIComponent(videoId)}`
- }
+ static renderSingleStat({ statistics, statisticName, id }) {
return {
label: `${statisticName}s`,
message: metric(statistics[`${statisticName}Count`]),
style: 'social',
- link,
+ link: `https://www.youtube.com/${this.type}/${encodeURIComponent(id)}`,
}
}
- async fetch({ channelId, videoId }) {
- let schema, url
- if (channelId) {
- schema = channelSchema
- url = 'https://www.googleapis.com/youtube/v3/channels'
- }
- if (videoId) {
- schema = videoSchema
- url = `https://www.googleapis.com/youtube/v3/videos`
- }
+ async fetch({ id }) {
return this._requestJson(
this.authHelper.withQueryStringAuth(
{ passKey: 'key' },
{
schema,
- url,
+ url: `https://www.googleapis.com/youtube/v3/${this.constructor.type}s`,
options: {
- qs: { id: channelId || videoId, part: 'statistics' },
+ qs: { id, part: 'statistics' },
},
}
)
@@ -97,21 +72,24 @@ class YouTubeBase extends BaseJsonService {
}
async handle({ channelId, videoId }, queryParams) {
- const json = await this.fetch({ channelId, videoId })
+ const id = channelId || videoId
+ const json = await this.fetch({ id })
if (json.pageInfo.totalResults === 0) {
- if (channelId) {
- throw new NotFound({ prettyMessage: 'channel not found' })
- }
- if (videoId) {
- throw new NotFound({ prettyMessage: 'video not found' })
- }
+ throw new NotFound({
+ prettyMessage: `${this.constructor.type} not found`,
+ })
}
const statistics = json.items[0].statistics
- return this.constructor.render(
- { statistics, channelId, videoId },
- queryParams
- )
+ return this.constructor.render({ statistics, id }, queryParams)
}
}
-module.exports = { documentation, YouTubeBase }
+class YouTubeVideoBase extends YouTubeBase {
+ static type = 'video'
+}
+
+class YouTubeChannelBase extends YouTubeBase {
+ static type = 'channel'
+}
+
+module.exports = { documentation, YouTubeVideoBase, YouTubeChannelBase }
diff --git a/services/youtube/youtube-channel-views.service.js b/services/youtube/youtube-channel-views.service.js
index 936f3f44a1e3f..27712d5c83ebf 100644
--- a/services/youtube/youtube-channel-views.service.js
+++ b/services/youtube/youtube-channel-views.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeChannelBase } = require('./youtube-base')
-module.exports = class YouTubeChannelViews extends YouTubeBase {
+module.exports = class YouTubeChannelViews extends YouTubeChannelBase {
static route = {
base: 'youtube/channel/views',
pattern: ':channelId',
@@ -11,7 +11,7 @@ module.exports = class YouTubeChannelViews extends YouTubeBase {
static get examples() {
const preview = this.render({
statistics: { viewCount: 30543 },
- channelId: 'UC8butISFwT-Wl7EV0hUK0BQ',
+ id: 'UC8butISFwT-Wl7EV0hUK0BQ',
})
// link[] is not allowed in examples
delete preview.link
@@ -25,11 +25,7 @@ module.exports = class YouTubeChannelViews extends YouTubeBase {
]
}
- static render({ statistics, channelId }) {
- return super.renderSingleStat({
- statistics,
- statisticName: 'view',
- channelId,
- })
+ static render({ statistics, id }) {
+ return super.renderSingleStat({ statistics, statisticName: 'view', id })
}
}
diff --git a/services/youtube/youtube-comments.service.js b/services/youtube/youtube-comments.service.js
index 000a03a533eee..679605684cc6a 100644
--- a/services/youtube/youtube-comments.service.js
+++ b/services/youtube/youtube-comments.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeVideoBase } = require('./youtube-base')
-module.exports = class YouTubeComments extends YouTubeBase {
+module.exports = class YouTubeComments extends YouTubeVideoBase {
static route = {
base: 'youtube/comments',
pattern: ':videoId',
@@ -11,7 +11,7 @@ module.exports = class YouTubeComments extends YouTubeBase {
static get examples() {
const preview = this.render({
statistics: { commentCount: 209 },
- videoId: 'wGJHwc5ksMA',
+ id: 'wGJHwc5ksMA',
})
// link[] is not allowed in examples
delete preview.link
@@ -25,11 +25,7 @@ module.exports = class YouTubeComments extends YouTubeBase {
]
}
- static render({ statistics, videoId }) {
- return super.renderSingleStat({
- statistics,
- statisticName: 'comment',
- videoId,
- })
+ static render({ statistics, id }) {
+ return super.renderSingleStat({ statistics, statisticName: 'comment', id })
}
}
diff --git a/services/youtube/youtube-comments.tester.js b/services/youtube/youtube-comments.tester.js
index 0d9930a11810a..dfdbde45d49c2 100644
--- a/services/youtube/youtube-comments.tester.js
+++ b/services/youtube/youtube-comments.tester.js
@@ -12,7 +12,7 @@ t.create('video comment count')
label: 'comments',
message: isMetric,
color: 'red',
- link: ['https://www.youtube.com/watch?v=wGJHwc5ksMA'],
+ link: ['https://www.youtube.com/video/wGJHwc5ksMA'],
})
t.create('video not found')
diff --git a/services/youtube/youtube-likes.service.js b/services/youtube/youtube-likes.service.js
index 211a8d60e4bbb..e2133cd392c1a 100644
--- a/services/youtube/youtube-likes.service.js
+++ b/services/youtube/youtube-likes.service.js
@@ -2,7 +2,7 @@
const Joi = require('joi')
const { metric } = require('../text-formatters')
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeVideoBase } = require('./youtube-base')
const documentationWithDislikes = `
${documentation}
@@ -16,7 +16,7 @@ const queryParamSchema = Joi.object({
withDislikes: Joi.equal(''),
}).required()
-module.exports = class YouTubeLikes extends YouTubeBase {
+module.exports = class YouTubeLikes extends YouTubeVideoBase {
static route = {
base: 'youtube/likes',
pattern: ':videoId',
@@ -26,16 +26,14 @@ module.exports = class YouTubeLikes extends YouTubeBase {
static get examples() {
const previewLikes = this.render({
statistics: { likeCount: 7 },
- videoId: 'abBdk8bSPKU',
+ id: 'abBdk8bSPKU',
})
const previewVotes = this.render(
{
statistics: { likeCount: 10236, dislikeCount: 396 },
- videoId: 'pU9Q6oiQNd0',
+ id: 'pU9Q6oiQNd0',
},
- {
- withDislikes: '',
- }
+ { withDislikes: '' }
)
// link[] is not allowed in examples
delete previewLikes.link
@@ -59,11 +57,11 @@ module.exports = class YouTubeLikes extends YouTubeBase {
]
}
- static render({ statistics, videoId }, queryParams) {
+ static render({ statistics, id }, queryParams) {
let renderedBadge = super.renderSingleStat({
statistics,
statisticName: 'like',
- videoId,
+ id,
})
if (queryParams && typeof queryParams.withDislikes !== 'undefined') {
renderedBadge = {
diff --git a/services/youtube/youtube-likes.tester.js b/services/youtube/youtube-likes.tester.js
index cd4adf86b9c44..5c266e0987323 100644
--- a/services/youtube/youtube-likes.tester.js
+++ b/services/youtube/youtube-likes.tester.js
@@ -13,7 +13,7 @@ t.create('video like count')
label: 'likes',
message: isMetric,
color: 'red',
- link: ['https://www.youtube.com/watch?v=pU9Q6oiQNd0'],
+ link: ['https://www.youtube.com/video/pU9Q6oiQNd0'],
})
t.create('video vote count')
@@ -25,7 +25,7 @@ t.create('video vote count')
/^([1-9][0-9]*[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) 👍 ([1-9][0-9]*[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) 👎$/
),
color: 'red',
- link: ['https://www.youtube.com/watch?v=pU9Q6oiQNd0'],
+ link: ['https://www.youtube.com/video/pU9Q6oiQNd0'],
})
t.create('video not found')
diff --git a/services/youtube/youtube-subscribers.service.js b/services/youtube/youtube-subscribers.service.js
index 1fe1e3ed25780..408b451bae908 100644
--- a/services/youtube/youtube-subscribers.service.js
+++ b/services/youtube/youtube-subscribers.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeChannelBase } = require('./youtube-base')
-module.exports = class YouTubeSubscribes extends YouTubeBase {
+module.exports = class YouTubeSubscribes extends YouTubeChannelBase {
static route = {
base: 'youtube/channel/subscribers',
pattern: ':channelId',
@@ -11,7 +11,7 @@ module.exports = class YouTubeSubscribes extends YouTubeBase {
static get examples() {
const preview = this.render({
statistics: { subscriberCount: 14577 },
- channelId: 'UC8butISFwT-Wl7EV0hUK0BQ',
+ id: 'UC8butISFwT-Wl7EV0hUK0BQ',
})
// link[] is not allowed in examples
delete preview.link
@@ -25,11 +25,11 @@ module.exports = class YouTubeSubscribes extends YouTubeBase {
]
}
- static render({ statistics, channelId }) {
+ static render({ statistics, id }) {
return super.renderSingleStat({
statistics,
statisticName: 'subscriber',
- channelId,
+ id,
})
}
}
diff --git a/services/youtube/youtube-views.service.js b/services/youtube/youtube-views.service.js
index 2516df780b7ce..5259e6818add2 100644
--- a/services/youtube/youtube-views.service.js
+++ b/services/youtube/youtube-views.service.js
@@ -1,8 +1,8 @@
'use strict'
-const { documentation, YouTubeBase } = require('./youtube-base')
+const { documentation, YouTubeVideoBase } = require('./youtube-base')
-module.exports = class YouTubeViews extends YouTubeBase {
+module.exports = class YouTubeViews extends YouTubeVideoBase {
static route = {
base: 'youtube/views',
pattern: ':videoId',
@@ -11,7 +11,7 @@ module.exports = class YouTubeViews extends YouTubeBase {
static get examples() {
const preview = this.render({
statistics: { viewCount: 14577 },
- videoId: 'abBdk8bSPKU',
+ id: 'abBdk8bSPKU',
})
// link[] is not allowed in examples
delete preview.link
@@ -25,11 +25,7 @@ module.exports = class YouTubeViews extends YouTubeBase {
]
}
- static render({ statistics, videoId }) {
- return super.renderSingleStat({
- statistics,
- statisticName: 'view',
- videoId,
- })
+ static render({ statistics, id }) {
+ return super.renderSingleStat({ statistics, statisticName: 'view', id })
}
}
diff --git a/services/youtube/youtube-views.tester.js b/services/youtube/youtube-views.tester.js
index 1c44b4b0ae8f9..af7c036daff38 100644
--- a/services/youtube/youtube-views.tester.js
+++ b/services/youtube/youtube-views.tester.js
@@ -12,7 +12,7 @@ t.create('video view count')
label: 'views',
message: isMetric,
color: 'red',
- link: ['https://www.youtube.com/watch?v=abBdk8bSPKU'],
+ link: ['https://www.youtube.com/video/abBdk8bSPKU'],
})
t.create('video not found')