Skip to content

Commit 87984d6

Browse files
committed
WIP
- Working on Notion API integration
1 parent 73da6da commit 87984d6

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

site/config/routes.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,42 @@
3838
[
3939
'pattern' => '/andrea/url/(:any)',
4040
'method' => 'get',
41-
'action' => function () {
42-
$mock = Remote::get('https://jsonplaceholder.typicode.com/posts/1');
43-
44-
$content = (object) json_decode($mock->content(), true);
45-
return Page::factory([
46-
'slug' => 'first',
47-
'template' => 'article',
48-
'content' => [
49-
'title' => $content->title,
50-
'subtitle' => $content->title,
51-
'published_at' => '2025-03-11',
52-
'blocks' => $content->body,
53-
]
41+
'action' => function ($slug) {
42+
// Define el ID de la página de Notion que deseas recuperar
43+
$notionPageId = 'Ciclo-de-vida-de-software-1754e2b34628803b9557cd1d9d07370a';
44+
45+
// Configura los encabezados necesarios para la API de Notion
46+
$headers = [
47+
'Authorization' => 'Bearer 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',
48+
'Notion-Version' => '2021-08-16',
49+
];
50+
51+
// Realiza la solicitud GET a la API de Notion
52+
$response = Remote::get("https://api.notion.com/v1/pages/{$notionPageId}", [
53+
'headers' => $headers
5454
]);
55+
56+
// Verifica si la respuesta es exitosa
57+
if ($response->code() === 200) {
58+
$content = json_decode($response->content(), true);
59+
60+
// Procesa el contenido según la estructura de tu página en Notion
61+
return Page::factory([
62+
'slug' => $slug,
63+
'template' => 'article',
64+
'content' => [
65+
'title' => $content['properties']['title']['title'][0]['text']['content'],
66+
'subtitle' => $content['properties']['subtitle']['rich_text'][0]['text']['content'],
67+
'published_at' => $content['properties']['published_at']['date']['start'],
68+
'blocks' => $content['properties']['content']['rich_text'][0]['text']['content'],
69+
]
70+
]);
71+
} else {
72+
// Maneja el error en caso de que la solicitud falle
73+
return 'Error al obtener datos de Notion';
74+
}
5575
}
56-
],
76+
],
5777
[
5878
'pattern' => '/search',
5979
'method' => 'get',

0 commit comments

Comments
 (0)