feat: add merchandise parser

This commit is contained in:
LuanRT
2022-06-10 01:50:21 -03:00
parent 049fd16aab
commit 73de36b946
9 changed files with 120 additions and 13 deletions

View File

@@ -0,0 +1,17 @@
'use strict';
const Text = require('./Text');
const Parser = require('..');
const NavigationEndpoint = require('./NavigationEndpoint');
class EmergencyOnebox {
type = 'emergencyOneboxRenderer';
constructor(data) {
this.title = new Text(data.title);
this.first_option = Parser.parse(data.firstOption);
this.menu = Parser.parse(data.menu);
}
}
module.exports = EmergencyOnebox;

View File

@@ -0,0 +1,25 @@
'use strict';
const Text = require('./Text');
const Thumbnail = require('./Thumbnail');
const NavigationEndpoint = require('./NavigationEndpoint');
class MerchandiseItem {
type = 'merchandiseItemRenderer';
constructor(data) {
this.title = data.title;
this.description = data.description;
this.thumbnails = new Thumbnail(data.thumbnail).thumbnails;
this.price = data.price;
this.vendor_name = data.vendorName;
this.button_text = data.buttonText;
this.button_accessibility_text = data.buttonAccessibilityText;
this.from_vendor_text = data.fromVendorText;
this.additional_fees_text = data.additionalFeesText;
this.region_format = data.regionFormat;
this.endpoint = new NavigationEndpoint(data.buttonCommand);
}
}
module.exports = MerchandiseItem;

View File

@@ -0,0 +1,15 @@
'use strict';
const Parser = require('..');
class MerchandiseShelf {
type = 'merchandiseShelfRenderer';
constructor(data) {
this.title = data.title;
this.menu = Parser.parse(data.actionButton);
this.items = Parser.parse(data.items);
}
}
module.exports = MerchandiseShelf;

View File

@@ -8,13 +8,20 @@ class NavigationEndpoint {
constructor(data) {
data?.serviceEndpoint &&
(data = data.serviceEndpoint);
this.metadata = {
url: data?.commandMetadata?.webCommandMetadata.url || null,
page_type: data?.commandMetadata?.webCommandMetadata.webPageType || null,
api_url: data?.commandMetadata?.webCommandMetadata.apiUrl || null,
send_post: data?.commandMetadata?.webCommandMetadata.sendPost || null
}
this.metadata = {};
data?.commandMetadata?.webCommandMetadata?.url &&
(this.metadata.url = data.commandMetadata.webCommandMetadata.url);
data?.commandMetadata?.webCommandMetadata?.webPageType &&
(this.metadata.page_type = data.commandMetadata.webCommandMetadata.webPageType);
data?.commandMetadata?.webCommandMetadata?.apiUrl &&
(this.metadata.api_url = data.commandMetadata.webCommandMetadata.apiUrl);
data?.commandMetadata?.webCommandMetadata?.sendPost &&
(this.metadata.send_post = data.commandMetadata.webCommandMetadata.sendPost);
if (data?.browseEndpoint) {
this.browse = {

View File

@@ -0,0 +1,19 @@
'use strict';
const Parser = require('..');
const Text = require('./Text');
const Thumbnail = require('./Thumbnail');
class PlayerErrorMessage {
type = 'playerErrorMessageRenderer';
constructor(data) {
this.subreason = new Text(data.subreason);
this.reason = new Text(data.reason);
this.proceed_button = Parser.parse(data.proceedButton);
this.thumbnails = new Thumbnail(data.thumbnail).thumbnails;
this.icon_type = data.icon.iconType;
}
}
module.exports = PlayerErrorMessage;

View File

@@ -0,0 +1,18 @@
'use strict';
const Text = require('./Text');
const NavigationEndpoint = require('./NavigationEndpoint');
class SingleActionEmergencySupport {
type = 'singleActionEmergencySupportRenderer';
constructor(data) {
this.action_text = new Text(data.actionText);
this.nav_text = new Text(data.navigationText);
this.details = new Text(data.detailsText);
this.icon_type = data.icon.iconType;
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
}
}
module.exports = SingleActionEmergencySupport;

View File

@@ -16,11 +16,11 @@ class TwoColumnWatchNextResults {
}
get secondary_results() {
return Parser.parse(this.#data.secondaryResults.secondaryResults.results);
return Parser.parse(this.#data.secondaryResults?.secondaryResults.results);
}
get conversation_bar() {
return Parser.parse(this.#data.conversationBar);
return Parser.parse(this.#data?.conversationBar);
}
}