calendar strip - move api call to proxy route
This commit is contained in:
parent
fde6a9cc83
commit
5773c1ef49
5 changed files with 116 additions and 20 deletions
|
|
@ -14,19 +14,6 @@ function getDatesInMonth(month) {
|
|||
}
|
||||
|
||||
async function getMapadoDates(monthNumb) {
|
||||
const myHeaders = new Headers();
|
||||
|
||||
const mapadoToken =
|
||||
"9bc321f5f47cf366c1c69eab4db69fe2a46819c75018237570473e2c961e210e227cc1e8cd8da7ba";
|
||||
|
||||
myHeaders.append("Authorization", "Bearer " + mapadoToken);
|
||||
|
||||
const requestOptions = {
|
||||
method: "GET",
|
||||
headers: myHeaders,
|
||||
redirect: "follow",
|
||||
};
|
||||
|
||||
const contractId = "1941";
|
||||
|
||||
const firstDayOfMonth = dayjs()
|
||||
|
|
@ -37,10 +24,44 @@ async function getMapadoDates(monthNumb) {
|
|||
.add(1, "month")
|
||||
.format("YYYY-MM-DD");
|
||||
|
||||
const url = `https://ticketing.mapado.net/v1/event_dates?itemsPerPage=100&contract=${contractId}&after=${firstDayOfMonth}&before=${firstDayOfNextMonth}&order=asc&fields=startDate,bookableStock,ticketing{@id,title,venue{@id,name,seatingName,address,zipCode,city,countryCode,timezone}}`;
|
||||
const requestEndPoint = 'event_dates'
|
||||
const requestParams = [
|
||||
{ name: 'itemsPerPage', value: 100 },
|
||||
{ name: 'contract', value: contractId },
|
||||
{ name: 'after', value: firstDayOfMonth },
|
||||
{ name: 'before', value: firstDayOfNextMonth },
|
||||
{ name: 'order', value: 'asc' }
|
||||
]
|
||||
|
||||
const requestFields = [
|
||||
{ name: 'startDate', },
|
||||
{ name: 'bookableStock', },
|
||||
{ name: 'ticketing', subfields: [
|
||||
{ name: "@id", },
|
||||
{ name: "title", },
|
||||
{ name: "venue", subfields: [
|
||||
{ name: "@id" },
|
||||
{ name: "address" },
|
||||
{ name: "zipCode" },
|
||||
{ name: "city" },
|
||||
{ name: "countryCode" },
|
||||
{ name: "timezone" },
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
];
|
||||
|
||||
const requestOptions = {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({requestEndPoint, requestParams, requestFields})
|
||||
}
|
||||
|
||||
const response = await fetch(url, requestOptions);
|
||||
const response = await fetch('/mapado.json', requestOptions);
|
||||
console.log(response)
|
||||
const json = await response.json();
|
||||
console.log(json)
|
||||
|
||||
const eventDates = json["hydra:member"];
|
||||
|
||||
console.log(
|
||||
|
|
|
|||
8
site/config/config.php
Normal file
8
site/config/config.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'debug' => true,
|
||||
'routes' => [
|
||||
require_once(__DIR__ . '/routes/mapado.php')
|
||||
]
|
||||
];
|
||||
34
site/config/routes/mapado.php
Normal file
34
site/config/routes/mapado.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
return [
|
||||
'pattern' => '/mapado.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$jsonRequest = file_get_contents("php://input");
|
||||
$request = json_decode($jsonRequest, true);
|
||||
|
||||
$token = site()->mapadoToken();
|
||||
$contractId = site()->mapadoContractId();
|
||||
$requestEndPoint = $request['requestEndPoint'];
|
||||
$requestParams = $request['requestParams'];
|
||||
$requestFields = $request['requestFields'];
|
||||
|
||||
$url = "https://ticketing.mapado.net/v1/$requestEndPoint?contract=$contractId&";
|
||||
|
||||
$url .= buildParamsString($requestParams);
|
||||
$url .= buildFieldsString($requestFields);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $token
|
||||
]);
|
||||
|
||||
$responseString = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$responseJson = json_encode(json_decode($responseString));
|
||||
|
||||
return $responseJson;
|
||||
}
|
||||
];
|
||||
33
site/plugins/helpers/index.php
Normal file
33
site/plugins/helpers/index.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
function buildFieldsString($requestFields) {
|
||||
$fields = [];
|
||||
foreach ($requestFields as $field) {
|
||||
if (isset($field['subfields'])) {
|
||||
$subfields = [];
|
||||
foreach ($field['subfields'] as $subfield) {
|
||||
if (isset($subfield['subfields'])) {
|
||||
$subsubfields = [];
|
||||
foreach ($subfield['subfields'] as $subsubfield) {
|
||||
$subsubfields[] = $subsubfield['name'];
|
||||
}
|
||||
$subfields[] = $subfield['name'] . '{' . implode(',', $subsubfields) . '}';
|
||||
} else {
|
||||
$subfields[] = $subfield['name'];
|
||||
}
|
||||
}
|
||||
$fields[] = $field['name'] . '{' . implode(',', $subfields) . '}';
|
||||
} else {
|
||||
$fields[] = $field['name'];
|
||||
}
|
||||
}
|
||||
return '&fields=' . implode(',', $fields);
|
||||
}
|
||||
|
||||
function buildParamsString($requestParams) {
|
||||
$queryString = [];
|
||||
foreach ($requestParams as $param) {
|
||||
$queryString[] = urlencode($param['name']) . '=' . urlencode($param['value']);
|
||||
}
|
||||
return implode('&', $queryString);
|
||||
}
|
||||
|
|
@ -14,12 +14,12 @@
|
|||
this.dates = getDatesInMonth(this.monthNumb);
|
||||
|
||||
const mapadoDates = await getMapadoDates(this.monthNumb)
|
||||
mapadoDates.forEach(mapadoDate => {
|
||||
const day = parseInt(mapadoDate.day)
|
||||
this.dates[day].push(mapadoDate.name)
|
||||
})
|
||||
// mapadoDates.forEach(mapadoDate => {
|
||||
// const day = parseInt(mapadoDate.day)
|
||||
// this.dates[day].push(mapadoDate.name)
|
||||
// })
|
||||
|
||||
console.log('dates', this.dates)
|
||||
// console.log('dates', this.dates)
|
||||
}
|
||||
}"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue