Commit 1c4ccc93 authored by Ben Galloway's avatar Ben Galloway

Add and parse new VisitorStats method

parent 7dc80fe9
......@@ -3,7 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.gammaModifiedMembers = exports.gammaMembershipSubscriptionsLoad = exports.gammaMembershipCancellation = exports.gammaMembershipPurchase = exports.gammaChangeMemberDetails = exports.gammaCancelSeats = exports.gammaReserveXTSeats = exports.gammaCancelBookAvailableSpaces = exports.gammaBookAvailableSpacesRequest = exports.gammaUpdateBookingStatus = exports.gammaUpdateBooking = exports.gammaSaveCustomerDetails = exports.gammaRemoveContactInterests = exports.gammaCancelBookingRequest = exports.gammaBookingAllSave = exports.gammaAmendBooking = exports.gammaVoucherListLoad = exports.gammaVoucherDiscountCheck = exports.gammaViewResourcesLoad = exports.gammaResourceViewListLoad = exports.gammaResourceListLoad = exports.gammaResourceListByViewLoad = exports.gammaResourceListByViewByDateLoad = exports.gammaResourceDatesListLoad = exports.gammaRedeemedBookings = exports.gammaProductMapListLoad = exports.gammaProductListLoad = exports.gammaGetTourList = exports.gammaGetBookingStatusList = exports.gammaGetBookingHistory = exports.gammaEventsOnlyListLoad = exports.gammaEventListLoad = exports.gammaEventEditList = exports.gammaCustomerLoad = exports.gammaContactInterests = exports.gammaBookingStatusUpdateCheck = exports.gammaBookingETicketExportRequest = exports.gammaAllContactInterests = undefined;
exports.gammaModifiedMembers = exports.gammaMembershipSubscriptionsLoad = exports.gammaMembershipCancellation = exports.gammaMembershipPurchase = exports.gammaChangeMemberDetails = exports.gammaCancelSeats = exports.gammaReserveXTSeats = exports.gammaCancelBookAvailableSpaces = exports.gammaBookAvailableSpacesRequest = exports.gammaUpdateBookingStatus = exports.gammaUpdateBooking = exports.gammaSaveCustomerDetails = exports.gammaRemoveContactInterests = exports.gammaCancelBookingRequest = exports.gammaBookingAllSave = exports.gammaAmendBooking = exports.gammaVisitorStats = exports.gammaVoucherListLoad = exports.gammaVoucherDiscountCheck = exports.gammaViewResourcesLoad = exports.gammaResourceViewListLoad = exports.gammaResourceListLoad = exports.gammaResourceListByViewLoad = exports.gammaResourceListByViewByDateLoad = exports.gammaResourceDatesListLoad = exports.gammaRedeemedBookings = exports.gammaProductMapListLoad = exports.gammaProductListLoad = exports.gammaGetTourList = exports.gammaGetBookingStatusList = exports.gammaGetBookingHistory = exports.gammaEventsOnlyListLoad = exports.gammaEventListLoad = exports.gammaEventEditList = exports.gammaCustomerLoad = exports.gammaContactInterests = exports.gammaBookingStatusUpdateCheck = exports.gammaBookingETicketExportRequest = exports.gammaAllContactInterests = undefined;
var _methods = require("./methods");
......@@ -56,6 +56,7 @@ const gammaResourceViewListLoad = exports.gammaResourceViewListLoad = create("Re
const gammaViewResourcesLoad = exports.gammaViewResourcesLoad = create("ViewResourcesLoad");
const gammaVoucherDiscountCheck = exports.gammaVoucherDiscountCheck = create("VoucherDiscountCheck");
const gammaVoucherListLoad = exports.gammaVoucherListLoad = create("VoucherListLoad");
const gammaVisitorStats = exports.gammaVisitorStats = create("VisitorStats");
// These methods seem to be unsupported by the Gamma API (based on testing in May 2018).
// They are not made available individually here, to discourage their use.
//export const gammaResourceDatesNotAvailable = create("ResourceDatesNotAvailable");
......
......@@ -264,6 +264,17 @@ const availabilityMethods = [{
inputFormat: {
VouchCode: "Optional"
}
}, {
name: "VisitorStats",
// This method is not in the general documentation - it is GSC-specific!
type: "XMLVisitorStatsRequest",
responseWrapper: "XMLVisitorStatsResponse",
returnType: false,
endpoint: "availability",
inputFormat: {
StartDate: "Undocumented",
EndDate: "Undocumented"
}
}];
exports.default = availabilityMethods;
\ No newline at end of file
......@@ -57,8 +57,13 @@ const getXml = exports.getXml = (callObject, method) => {
const parseResponseField = (fieldContents, fieldKey, methodSpecs) => {
if (fieldContents.constructor === Object && Object.keys(fieldContents).length === 0) return { [fieldKey]: "" };
if (fieldKey === "xs:schema") return {};
if (fieldKey === "mResults" && fieldContents.hasOwnProperty("diffgr:diffgram")) return {
[fieldKey]: processAnyType(fieldContents["diffgr:diffgram"].NewDataSet.Table, methodSpecs, true)
};
if (methodSpecs.returnType === false && fieldKey === "_attributes" && fieldContents.hasOwnProperty("xmlns:xsi") && fieldContents.hasOwnProperty("xmlns:xsd")) return { GammaResponseType: methodSpecs.responseWrapper };
if (fieldKey === "_attributes" && fieldContents.hasOwnProperty("xsi:type")) return { GammaResponseType: fieldContents["xsi:type"] };
if (fieldKey === "_attributes" && fieldContents.hasOwnProperty("diffgr:id") && fieldContents.hasOwnProperty("msdata:rowOrder")) return { GammaResponseType: "VisitorStatsDay" };
if (fieldContents.hasOwnProperty("_text")) return { [fieldKey]: fieldContents["_text"] };
if (fieldContents.hasOwnProperty("anyType")) return { [fieldKey]: processAnyType(fieldContents.anyType, methodSpecs) };
if (fieldContents.hasOwnProperty(fieldKey)) return { [fieldKey]: parseResponseField(fieldContents[fieldKey], fieldKey, methodSpecs) };
......@@ -71,7 +76,7 @@ const parseResponseField = (fieldContents, fieldKey, methodSpecs) => {
return { [fieldKey]: fieldContents };
};
const processAnyType = (anyType, methodSpecs) => {
const processAnyType = (anyType, methodSpecs, internal = false) => {
// A single <anyType></anyType> response needs converted for the array operations to work
const anyTypeArray = Array.isArray(anyType) ? anyType : new Array(anyType);
......@@ -83,7 +88,7 @@ const processAnyType = (anyType, methodSpecs) => {
return distilled;
});
const result = methodSpecs.returnType === false && reduced.length === 1 ? reduced[0] : reduced; // Only return an array if necessary
const result = !internal && methodSpecs.returnType === false && reduced.length === 1 ? reduced[0] : reduced; // Only return an array if necessary
return result;
};
......
......@@ -39,6 +39,7 @@ export const gammaResourceViewListLoad = create("ResourceViewListLoad");
export const gammaViewResourcesLoad = create("ViewResourcesLoad");
export const gammaVoucherDiscountCheck = create("VoucherDiscountCheck");
export const gammaVoucherListLoad = create("VoucherListLoad");
export const gammaVisitorStats = create("VisitorStats");
// These methods seem to be unsupported by the Gamma API (based on testing in May 2018).
// They are not made available individually here, to discourage their use.
//export const gammaResourceDatesNotAvailable = create("ResourceDatesNotAvailable");
......
......@@ -284,6 +284,18 @@ const availabilityMethods = [
VouchCode: "Optional",
},
},
{
name: "VisitorStats",
// This method is not in the general documentation - it is GSC-specific!
type: "XMLVisitorStatsRequest",
responseWrapper: "XMLVisitorStatsResponse",
returnType: false,
endpoint: "availability",
inputFormat: {
StartDate: "Undocumented",
EndDate: "Undocumented",
},
},
];
export default availabilityMethods;
......@@ -45,6 +45,11 @@ export const getXml = (callObject, method) => {
const parseResponseField = (fieldContents, fieldKey, methodSpecs) => {
if (fieldContents.constructor === Object && Object.keys(fieldContents).length === 0) return { [fieldKey]: "" };
if (fieldKey === "xs:schema") return {};
if (fieldKey === "mResults" && fieldContents.hasOwnProperty("diffgr:diffgram"))
return {
[fieldKey]: processAnyType(fieldContents["diffgr:diffgram"].NewDataSet.Table, methodSpecs, true),
};
if (
methodSpecs.returnType === false &&
fieldKey === "_attributes" &&
......@@ -54,6 +59,12 @@ const parseResponseField = (fieldContents, fieldKey, methodSpecs) => {
return { GammaResponseType: methodSpecs.responseWrapper };
if (fieldKey === "_attributes" && fieldContents.hasOwnProperty("xsi:type"))
return { GammaResponseType: fieldContents["xsi:type"] };
if (
fieldKey === "_attributes" &&
fieldContents.hasOwnProperty("diffgr:id") &&
fieldContents.hasOwnProperty("msdata:rowOrder")
)
return { GammaResponseType: "VisitorStatsDay" };
if (fieldContents.hasOwnProperty("_text")) return { [fieldKey]: fieldContents["_text"] };
if (fieldContents.hasOwnProperty("anyType"))
return { [fieldKey]: processAnyType(fieldContents.anyType, methodSpecs) };
......@@ -68,7 +79,7 @@ const parseResponseField = (fieldContents, fieldKey, methodSpecs) => {
return { [fieldKey]: fieldContents };
};
const processAnyType = (anyType, methodSpecs) => {
const processAnyType = (anyType, methodSpecs, internal = false) => {
// A single <anyType></anyType> response needs converted for the array operations to work
const anyTypeArray = Array.isArray(anyType) ? anyType : new Array(anyType);
......@@ -80,7 +91,7 @@ const processAnyType = (anyType, methodSpecs) => {
return distilled;
});
const result = methodSpecs.returnType === false && reduced.length === 1 ? reduced[0] : reduced; // Only return an array if necessary
const result = !internal && methodSpecs.returnType === false && reduced.length === 1 ? reduced[0] : reduced; // Only return an array if necessary
return result;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment