@meltwater/conversations-api-services 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/data-access/http/youtube.native.js +94 -0
- package/dist/cjs/data-access/index.js +3 -0
- package/dist/esm/data-access/http/youtube.native.js +83 -0
- package/dist/esm/data-access/index.js +2 -1
- package/package.json +1 -1
- package/src/data-access/http/youtube.native.js +147 -0
- package/src/data-access/index.js +2 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.comment = comment;
|
|
7
|
+
exports.likeVideo = likeVideo;
|
|
8
|
+
exports.reply = reply;
|
|
9
|
+
exports.sendRequest = sendRequest;
|
|
10
|
+
exports.unlikeVideo = unlikeVideo;
|
|
11
|
+
var _superagent = _interopRequireDefault(require("superagent"));
|
|
12
|
+
var _externalIdHelpers = require("../../lib/externalId.helpers.js");
|
|
13
|
+
var _loggerHelpers = require("../../lib/logger.helpers.js");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const YOUTUBE_API_URL = "https://www.googleapis.com/youtube/v3/";
|
|
16
|
+
async function sendPost(token) {
|
|
17
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
18
|
+
let postData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
19
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
20
|
+
let response = {};
|
|
21
|
+
try {
|
|
22
|
+
response = await _superagent.default.post(YOUTUBE_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Authorization', `Bearer ${token}`).send(postData);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
25
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
26
|
+
} else {
|
|
27
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}`, err);
|
|
28
|
+
}
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
async function sendRequest(token) {
|
|
34
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
35
|
+
let logger = arguments.length > 2 ? arguments[2] : undefined;
|
|
36
|
+
let response = {};
|
|
37
|
+
try {
|
|
38
|
+
response = await _superagent.default.get(YOUTUBE_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Authorization', `Bearer ${token}`).send();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
41
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
42
|
+
} else {
|
|
43
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call youtube api for paramString ${paramString}`, err);
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
if (response.status !== 200) {
|
|
48
|
+
(0, _loggerHelpers.loggerError)(logger, `Failed to call facebook api`, {
|
|
49
|
+
responseBody: JSON.stringify(response.body)
|
|
50
|
+
});
|
|
51
|
+
let error = new Error(`Failed to call facebook api`);
|
|
52
|
+
error.code = response.status;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
return response.body;
|
|
56
|
+
}
|
|
57
|
+
async function likeVideo(token, externalId, logger) {
|
|
58
|
+
return setVideoRating(token, externalId, true, logger);
|
|
59
|
+
}
|
|
60
|
+
async function unlikeVideo(token, externalId, logger) {
|
|
61
|
+
return setVideoRating(token, externalId, false, logger);
|
|
62
|
+
}
|
|
63
|
+
async function setVideoRating(token, externalId) {
|
|
64
|
+
let like = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
65
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
66
|
+
const requestResult = await sendPost(token, `videos/rate?id=${(0, _externalIdHelpers.removePrefix)(externalId)}&rating=${like ? 'like' : 'dislike'}`, logger);
|
|
67
|
+
return requestResult;
|
|
68
|
+
}
|
|
69
|
+
async function comment(token, inReplyToId, textOriginal, logger) {
|
|
70
|
+
const {
|
|
71
|
+
body: publishedMessage
|
|
72
|
+
} = (await sendPost(token, 'commentThreads?part=snippet', {
|
|
73
|
+
snippet: {
|
|
74
|
+
videoId: inReplyToId,
|
|
75
|
+
topLevelComment: {
|
|
76
|
+
snippet: {
|
|
77
|
+
textOriginal
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, logger)) || {};
|
|
82
|
+
return publishedMessage;
|
|
83
|
+
}
|
|
84
|
+
async function reply(token, inReplyToId, textOriginal, logger) {
|
|
85
|
+
const {
|
|
86
|
+
body: publishedMessage
|
|
87
|
+
} = await sendPost(token, 'comments?part=snippet', {
|
|
88
|
+
snippet: {
|
|
89
|
+
textOriginal,
|
|
90
|
+
parentId: inReplyToId
|
|
91
|
+
}
|
|
92
|
+
}, logger);
|
|
93
|
+
return publishedMessage;
|
|
94
|
+
}
|
|
@@ -85,6 +85,7 @@ Object.defineProperty(exports, "WarpZoneApiClient", {
|
|
|
85
85
|
return _WarpZoneApiClient.WarpZoneApiClient;
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
|
+
exports.YoutubeNative = void 0;
|
|
88
89
|
Object.defineProperty(exports, "assetManagerTvmRepository", {
|
|
89
90
|
enumerable: true,
|
|
90
91
|
get: function () {
|
|
@@ -119,6 +120,8 @@ var FacebookNative = _interopRequireWildcard(require("./http/facebook.native.js"
|
|
|
119
120
|
exports.FacebookNative = FacebookNative;
|
|
120
121
|
var TiktokNative = _interopRequireWildcard(require("./http/tiktok.native.js"));
|
|
121
122
|
exports.TiktokNative = TiktokNative;
|
|
123
|
+
var YoutubeNative = _interopRequireWildcard(require("./http/youtube.native.js"));
|
|
124
|
+
exports.YoutubeNative = YoutubeNative;
|
|
122
125
|
var LinkedinNative = _interopRequireWildcard(require("./http/linkedin.native.js"));
|
|
123
126
|
exports.LinkedinNative = LinkedinNative;
|
|
124
127
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import superagent from 'superagent';
|
|
2
|
+
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
|
+
import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
|
|
4
|
+
const YOUTUBE_API_URL = "https://www.googleapis.com/youtube/v3/";
|
|
5
|
+
async function sendPost(token) {
|
|
6
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
7
|
+
let postData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
8
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
9
|
+
let response = {};
|
|
10
|
+
try {
|
|
11
|
+
response = await superagent.post(YOUTUBE_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Authorization', `Bearer ${token}`).send(postData);
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
14
|
+
loggerError(logger, `Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
15
|
+
} else {
|
|
16
|
+
loggerError(logger, `Failed to call youtube api for paramString ${paramString}`, err);
|
|
17
|
+
}
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
export async function sendRequest(token) {
|
|
23
|
+
let paramString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
24
|
+
let logger = arguments.length > 2 ? arguments[2] : undefined;
|
|
25
|
+
let response = {};
|
|
26
|
+
try {
|
|
27
|
+
response = await superagent.get(YOUTUBE_API_URL + paramString).set('Accept', 'application/json').set('Content-Type', 'application/json').set('Authorization', `Bearer ${token}`).send();
|
|
28
|
+
} catch (err) {
|
|
29
|
+
if (err && err.response && err.response.body && err.response.body.error) {
|
|
30
|
+
loggerError(logger, `Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`);
|
|
31
|
+
} else {
|
|
32
|
+
loggerError(logger, `Failed to call youtube api for paramString ${paramString}`, err);
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
if (response.status !== 200) {
|
|
37
|
+
loggerError(logger, `Failed to call facebook api`, {
|
|
38
|
+
responseBody: JSON.stringify(response.body)
|
|
39
|
+
});
|
|
40
|
+
let error = new Error(`Failed to call facebook api`);
|
|
41
|
+
error.code = response.status;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
return response.body;
|
|
45
|
+
}
|
|
46
|
+
export async function likeVideo(token, externalId, logger) {
|
|
47
|
+
return setVideoRating(token, externalId, true, logger);
|
|
48
|
+
}
|
|
49
|
+
export async function unlikeVideo(token, externalId, logger) {
|
|
50
|
+
return setVideoRating(token, externalId, false, logger);
|
|
51
|
+
}
|
|
52
|
+
async function setVideoRating(token, externalId) {
|
|
53
|
+
let like = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
54
|
+
let logger = arguments.length > 3 ? arguments[3] : undefined;
|
|
55
|
+
const requestResult = await sendPost(token, `videos/rate?id=${removePrefix(externalId)}&rating=${like ? 'like' : 'dislike'}`, logger);
|
|
56
|
+
return requestResult;
|
|
57
|
+
}
|
|
58
|
+
export async function comment(token, inReplyToId, textOriginal, logger) {
|
|
59
|
+
const {
|
|
60
|
+
body: publishedMessage
|
|
61
|
+
} = (await sendPost(token, 'commentThreads?part=snippet', {
|
|
62
|
+
snippet: {
|
|
63
|
+
videoId: inReplyToId,
|
|
64
|
+
topLevelComment: {
|
|
65
|
+
snippet: {
|
|
66
|
+
textOriginal
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, logger)) || {};
|
|
71
|
+
return publishedMessage;
|
|
72
|
+
}
|
|
73
|
+
export async function reply(token, inReplyToId, textOriginal, logger) {
|
|
74
|
+
const {
|
|
75
|
+
body: publishedMessage
|
|
76
|
+
} = await sendPost(token, 'comments?part=snippet', {
|
|
77
|
+
snippet: {
|
|
78
|
+
textOriginal,
|
|
79
|
+
parentId: inReplyToId
|
|
80
|
+
}
|
|
81
|
+
}, logger);
|
|
82
|
+
return publishedMessage;
|
|
83
|
+
}
|
|
@@ -18,6 +18,7 @@ import * as applicationTagFunctions from '../lib/applicationTags.helpers.js';
|
|
|
18
18
|
import * as hiddenHelpers from '../lib/hidden.helpers.js';
|
|
19
19
|
import * as FacebookNative from './http/facebook.native.js';
|
|
20
20
|
import * as TiktokNative from './http/tiktok.native.js';
|
|
21
|
+
import * as YoutubeNative from './http/youtube.native.js';
|
|
21
22
|
import * as LinkedinNative from './http/linkedin.native.js';
|
|
22
23
|
const DocumentHelperFunctions = {
|
|
23
24
|
...messageHelpers,
|
|
@@ -28,4 +29,4 @@ const LinkedInHelpers = {
|
|
|
28
29
|
getOrganization,
|
|
29
30
|
getProfile
|
|
30
31
|
};
|
|
31
|
-
export { FacebookNative, TiktokNative, LinkedinNative, awsS3Client, assetManagerTvmRepository, CompanyApiClient, CredentialsApiClient, EntitlementsApiClient, FacebookApiClient, FeatureToggleClient, IdentityServicesClient, InstagramApiClient, InstagramVideoClient, IRClient, LinkedInApiClient, TikTokApiClient, MasfClient, WarpZoneApiClient, DocumentHelperFunctions, LinkedInHelpers };
|
|
32
|
+
export { FacebookNative, TiktokNative, YoutubeNative, LinkedinNative, awsS3Client, assetManagerTvmRepository, CompanyApiClient, CredentialsApiClient, EntitlementsApiClient, FacebookApiClient, FeatureToggleClient, IdentityServicesClient, InstagramApiClient, InstagramVideoClient, IRClient, LinkedInApiClient, TikTokApiClient, MasfClient, WarpZoneApiClient, DocumentHelperFunctions, LinkedInHelpers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meltwater/conversations-api-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "Repository to contain all conversations api services shared across our services",
|
|
5
5
|
"main": "dist/cjs/data-access/index.js",
|
|
6
6
|
"module": "dist/esm/data-access/index.js",
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import superagent from 'superagent';
|
|
2
|
+
import { removePrefix } from '../../lib/externalId.helpers.js';
|
|
3
|
+
import { loggerDebug, loggerError, loggerInfo } from '../../lib/logger.helpers.js';
|
|
4
|
+
|
|
5
|
+
const YOUTUBE_API_URL = "https://www.googleapis.com/youtube/v3/"
|
|
6
|
+
|
|
7
|
+
async function sendPost(
|
|
8
|
+
token,
|
|
9
|
+
paramString = '',
|
|
10
|
+
postData = undefined,
|
|
11
|
+
logger
|
|
12
|
+
) {
|
|
13
|
+
|
|
14
|
+
let response = {};
|
|
15
|
+
try {
|
|
16
|
+
response = await superagent
|
|
17
|
+
.post(YOUTUBE_API_URL + paramString)
|
|
18
|
+
.set('Accept', 'application/json')
|
|
19
|
+
.set('Content-Type', 'application/json')
|
|
20
|
+
.set('Authorization', `Bearer ${token}`)
|
|
21
|
+
.send(postData);
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (
|
|
24
|
+
err &&
|
|
25
|
+
err.response &&
|
|
26
|
+
err.response.body &&
|
|
27
|
+
err.response.body.error
|
|
28
|
+
) {
|
|
29
|
+
loggerError(logger,
|
|
30
|
+
`Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`
|
|
31
|
+
);
|
|
32
|
+
} else {
|
|
33
|
+
loggerError(logger,
|
|
34
|
+
`Failed to call youtube api for paramString ${paramString}`,
|
|
35
|
+
err
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function sendRequest(
|
|
46
|
+
token,
|
|
47
|
+
paramString = '',
|
|
48
|
+
logger
|
|
49
|
+
) {
|
|
50
|
+
let response = {};
|
|
51
|
+
try {
|
|
52
|
+
response = await superagent
|
|
53
|
+
.get(YOUTUBE_API_URL + paramString)
|
|
54
|
+
.set('Accept', 'application/json')
|
|
55
|
+
.set('Content-Type', 'application/json')
|
|
56
|
+
.set('Authorization', `Bearer ${token}`)
|
|
57
|
+
.send();
|
|
58
|
+
} catch (err) {
|
|
59
|
+
if (
|
|
60
|
+
err &&
|
|
61
|
+
err.response &&
|
|
62
|
+
err.response.body &&
|
|
63
|
+
err.response.body.error
|
|
64
|
+
) {
|
|
65
|
+
loggerError( logger,
|
|
66
|
+
`Failed to call youtube api for paramString ${paramString}: ${err.response.body.error.message}`
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
69
|
+
loggerError( logger,
|
|
70
|
+
`Failed to call youtube api for paramString ${paramString}`,
|
|
71
|
+
err
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (response.status !== 200) {
|
|
79
|
+
loggerError(logger,
|
|
80
|
+
`Failed to call facebook api`,
|
|
81
|
+
{ responseBody: JSON.stringify(response.body) }
|
|
82
|
+
);
|
|
83
|
+
let error = new Error(
|
|
84
|
+
`Failed to call facebook api`
|
|
85
|
+
);
|
|
86
|
+
error.code = response.status;
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return response.body;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function likeVideo(token, externalId, logger) {
|
|
94
|
+
return setVideoRating(token, externalId, true, logger);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function unlikeVideo(token, externalId, logger) {
|
|
98
|
+
return setVideoRating(token, externalId, false, logger);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
async function setVideoRating(token, externalId, like = true, logger) {
|
|
103
|
+
const requestResult = await sendPost(
|
|
104
|
+
token,
|
|
105
|
+
`videos/rate?id=${removePrefix(
|
|
106
|
+
externalId
|
|
107
|
+
)}&rating=${like ? 'like' : 'dislike'}`,
|
|
108
|
+
logger
|
|
109
|
+
);
|
|
110
|
+
return requestResult;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function comment(token, inReplyToId, textOriginal, logger) {
|
|
114
|
+
const { body: publishedMessage } =
|
|
115
|
+
(await sendPost(
|
|
116
|
+
token,
|
|
117
|
+
'commentThreads?part=snippet',
|
|
118
|
+
{
|
|
119
|
+
snippet: {
|
|
120
|
+
videoId:inReplyToId,
|
|
121
|
+
topLevelComment: {
|
|
122
|
+
snippet: {
|
|
123
|
+
textOriginal,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
logger,
|
|
129
|
+
)) || {};
|
|
130
|
+
return publishedMessage;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function reply(token, inReplyToId, textOriginal, logger) {
|
|
134
|
+
const { body: publishedMessage } = await sendPost(
|
|
135
|
+
token,
|
|
136
|
+
'comments?part=snippet',
|
|
137
|
+
{
|
|
138
|
+
snippet: {
|
|
139
|
+
textOriginal,
|
|
140
|
+
parentId:inReplyToId,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
logger,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return publishedMessage;
|
|
147
|
+
}
|
package/src/data-access/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import * as applicationTagFunctions from '../lib/applicationTags.helpers.js';
|
|
|
18
18
|
import * as hiddenHelpers from '../lib/hidden.helpers.js';
|
|
19
19
|
import * as FacebookNative from './http/facebook.native.js';
|
|
20
20
|
import * as TiktokNative from './http/tiktok.native.js';
|
|
21
|
+
import * as YoutubeNative from './http/youtube.native.js';
|
|
21
22
|
import * as LinkedinNative from './http/linkedin.native.js';
|
|
22
23
|
|
|
23
24
|
const DocumentHelperFunctions = {
|
|
@@ -33,6 +34,7 @@ const LinkedInHelpers = {
|
|
|
33
34
|
export {
|
|
34
35
|
FacebookNative,
|
|
35
36
|
TiktokNative,
|
|
37
|
+
YoutubeNative,
|
|
36
38
|
LinkedinNative,
|
|
37
39
|
awsS3Client,
|
|
38
40
|
assetManagerTvmRepository,
|