Skip to content

Commit

Permalink
feat: provide a @id attribute with the API endpoint call to get that …
Browse files Browse the repository at this point in the history
…object
  • Loading branch information
erral committed Dec 10, 2022
1 parent 3c5d00f commit 8cfa061
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
22 changes: 1 addition & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
TV_API_PATH,
TV_API_CATEGORIES,
TV_API_CATEGORY,
TV_API_CATEGORY_PROGRAM,
TV_API_PROGRAMS,
TV_API_CATEGORY_PROGRAM_PLAYLIST,
TV_API_CATEGORY_PROGRAM_PLAYLIST_CHAPTER,
} from '../constants.js';

export const build_tv_category_url = (item) => {
return `${TV_API_PATH}${TV_API_CATEGORY}/${item.CLASIFICACION}/`;
};

export const build_tv_category_program_url = (item) => {
return `${TV_API_PATH}${TV_API_CATEGORY_PROGRAM}/${item.ID_WEB_GROUP}/`;
};

export const build_tv_category_program_playlist_url = (item) => {
return `${TV_API_PATH}${TV_API_CATEGORY_PROGRAM_PLAYLIST}/${item.ID}/`;
};

export const build_tv_category_program_playlist_program_url = (item) => {
return `${TV_API_PATH}${TV_API_CATEGORY_PROGRAM_PLAYLIST_CHAPTER}/${item.ID}/`;
};
14 changes: 13 additions & 1 deletion src/tv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@ import {
TV_API_CATEGORIES,
TV_API_CATEGORY,
TV_API_CATEGORY_PROGRAM,
TV_API_PROGRAMS,
TV_API_CATEGORY_PROGRAM_PLAYLIST,
TV_API_CATEGORY_PROGRAM_PLAYLIST_CHAPTER,
TV_API_PROGRAMS,
} from './constants.js';
import { fetchAPI } from './helpers/fetch.js';
import { parseImage } from './helpers/parsers.js';
import {
build_tv_category_url,
build_tv_category_program_url,
build_tv_category_program_playlist_url,
build_tv_category_program_playlist_program_url,
} from './helpers/utils.js';

const getTVCategories = () => {
return new Promise(async (resolve, reject) => {
try {
const data = await fetchAPI(TV_API_CATEGORIES);

const parsedData = {
count: data.num,
timestamp: data.timestamp,
categories: data.web_clasif.map((item) => {
return {
'@id': build_tv_category_url(item),
id: item.ID_WEB_CLASIF,
slug: item.CLASIFICACION,
eu: item.CLASIFICACION_EU,
Expand All @@ -43,6 +51,7 @@ const getTVCategory = (category_slug) => {
timestamp: data.timestamp,
program: data.web_group.map((item) => {
return {
'@id': build_tv_category_program_url(item),
id: item.ID_WEB_GROUP,
title: item.NOMBRE_GROUP,
order: item.ORDEN,
Expand Down Expand Up @@ -77,6 +86,7 @@ const getTVCategoryPrograms = (category_id) => {
: [],
playlist: data.web_group[0].web_playlist.map((item) => {
return {
'@id': build_tv_category_program_playlist_url(item),
id: item.ID,
name: item.NAME,
order: item.ORDER,
Expand Down Expand Up @@ -111,6 +121,7 @@ const getTVCategoryProgramPlaylist = (playlist_id) => {
description: data.desc_playlist,
playlist: data.web_media.map((item) => {
return {
'@id': build_tv_category_program_playlist_program_url(item),
id: item.ID,
name: item[`NAME_${item.IDIOMA}`],
chapter_title: item[`CHAPTER_${item.IDIOMA}`],
Expand Down Expand Up @@ -148,6 +159,7 @@ const getTVCategoryProgramPlaylistChapter = (chapter_id) => {
description: data.desc_playlist,
playlist: data.web_media.map((item) => {
return {
'@id': build_tv_category_program_playlist_program_url(item),
id: item.ID,
name: item[`NAME_${item.IDIOMA}`],
chapter_title: item[`CHAPTER_${item.IDIOMA}`],
Expand Down

0 comments on commit 8cfa061

Please sign in to comment.