Skip to content

Commit

Permalink
basic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bipoza committed Dec 9, 2022
1 parent ea681c0 commit 8c392e6
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 59 deletions.
91 changes: 91 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nahieran-JS</title>
<link rel="stylesheet" href="./style.css">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous"></script>
</head>

<body>
<div class="container">
<h1>NahieranJS</h1>
<section>
<h2>Get TV Categories</h2>
<code lang="javascript">import { getTVCategories } from "nahieran-js";
getTVCategories().then(res => {
console.log("Response: ", res);
}, err => {
console.error("Response error: ", err);
});
</code>

<br>
DEMO: <button type="button" class="btn btn-primary" onclick="getDocTVCategories()">Get TV
Categories</button>
</section>



<section>
<h2>Get TV Category</h2>

<br>
DEMO: <button type="button" class="btn btn-primary" onclick="getDocTVCategory('PELICULAS')">Get TV Category</button>
</section>
</div>


<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalTitle">...</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="modalBody">
...
</div>

</div>
</div>
</div>
</body>


<script type="module">
import { getTVCategories, getTVCategory } from "../src/index.js";
const myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
const getDocTVCategories = () => {
getTVCategories().then(res => {
console.log("Response: ", res);
document.getElementById("modalTitle").innerText = "Get TV Categories";
document.getElementById("modalBody").innerText = JSON.stringify(res);
myModal.show();
}, err => console.error("Response error: ", err));
};

const getDocTVCategory = (category_slug) => {
getTVCategory(category_slug).then(res => {
console.log("Response: ", res);
document.getElementById("modalTitle").innerText = "Get TV Categories";
document.getElementById("modalBody").innerText = JSON.stringify(res);
myModal.show();
}, err => console.error("Response error: ", err));
};
window.getDocTVCategories = getDocTVCategories;
window.getDocTVCategory = getDocTVCategory;

</script>

</html>
9 changes: 9 additions & 0 deletions docs/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
code {
font-family: Consolas,"courier new";
color: crimson;
background-color: #f1f1f1;
padding: 2px;
font-size: 105%;
/* white-space: pre-wrap */
white-space: pre-line
}
21 changes: 0 additions & 21 deletions example.html

This file was deleted.

12 changes: 0 additions & 12 deletions index.ts

This file was deleted.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"name": "nahieran-js",
"version": "1.0.0",
"description": "Nahieran erabiltzeko beharrezko funtzioak",
"main": "node dist/index.js",
"main": "node src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "tsc --watch",
"start-dev": "http-server -p 3000"
"start-doc": "http-server -p 3000 -o docs/index.html"
},
"author": "",
"author": "bipoza",
"license": "ISC",
"devDependencies": {
"http-server": "^14.1.1",
"typescript": "^4.9.4"
"http-server": "^14.1.1"
}
}
9 changes: 0 additions & 9 deletions server.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/contants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const TV_DOMAIN_PATH = "https://mam.eitb.eus"

export const TV_API_PATH = `${TV_DOMAIN_PATH}/mam/REST/ServiceMultiweb`;

export const TV_API_CATEGORIES = '/WebClasif/MULTIWEBTV/8/1/0/';
export const TV_API_CATEGORY = '/Grouplist/Clasification/MULTIWEBTV/8';
13 changes: 13 additions & 0 deletions src/helpers/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import { TV_API_PATH } from "../contants.js";

const fetchAPI = (param) => {
return new Promise((resolve, reject) => {
fetch(`${TV_API_PATH}${param}`)
.then((response) => response.json())
.then((data) => resolve(data)).catch(err => reject(err));
});

};

export { fetchAPI };
65 changes: 65 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { TV_API_CATEGORIES, TV_API_CATEGORY } from "./contants.js"
import { fetchAPI } from "./helpers/fetch.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: item.ID_WEB_CLASIF,
slug: item.CLASIFICACION,
eu: item.CLASIFICACION_EU,
es: item.CLASIFICACION_ES,
fr: item.CLASIFICACION_FR,
en: item.CLASIFICACION_EN
}
})
};
resolve(parsedData);
} catch (err) {
reject(err);
}
})
}

const getTVCategory = (category_slug) => {
return new Promise(async (resolve, reject) => {
try {
const data = await fetchAPI(`${TV_API_CATEGORY}/${category_slug}/`);
console.log("Get TV category: ", data)
const parsedData = {
count: data.num,
timestamp: data.timestamp,
program: data.web_group.map(item => {
return {
id: item.ID_WEB_GROUP,
title: item.NOMBRE_GROUP,
order: item.ORDEN,
description: item.SHORT_DESC,
images: item.images.map(image => {
return {
height: image.HEIGHT,
width: image.WIDTH,
order: image.ORDEN,
url: data.vod_url + image.URL
}
})
}
})
};
resolve(parsedData);
} catch (err) {
reject(err);
}
})
}

// export default getTelesaiak;
export {
getTVCategories,
getTVCategory
}
12 changes: 0 additions & 12 deletions tsconfig.json

This file was deleted.

0 comments on commit 8c392e6

Please sign in to comment.