Full field metapolicy_struct

Full field metapolicy_struct

ℹ️

This page:

  • Gives an example on working with the metapolicy_struct field.
  • Covers code samples in Node.js and Python.
  • Uses the Retrieve hotel dump call:
💡

Recommendations

  • Change the unspecified values to something that will work for you.
  • Change other values to a readable format.
  • Make sure you process nullable or empty objects.

Process the dump

Use the instruction.

Read the deposit object and show its data to the user

 1// hotel is the hotel object
 2async function showDeposit(hotel) {
 3  const deposits = hotel.metapolicy_struct.deposit;
 4  if (deposits.length == 0) {
 5    console.log('No deposit');
 6    return;
 7  }
 8  // TODO: your logic
 9  console.log('Deposits');
10  for (const deposit of deposits) {
11    let unspecified = false;
12    let depositType = deposit.deposit_type;
13    if (depositType == 'unspecified') {
14      depositType = 'No deposit type.';
15      unspecified = true;
16    } else {
17      depositType = String(depositType).charAt(0).toUpperCase()
18      + String(depositType).slice(1) + '.';
19    }
20    let depositPaymentType = deposit.payment_type;
21    if (depositPaymentType == 'unspecified') {
22      depositPaymentType = 'No deposit payment type.';
23      unspecified = true;
24    } else {
25      depositPaymentType = 'The deposit is made by ' + depositPaymentType + '.';
26    }
27    let depositPriceUnit = deposit.price_unit;
28    if (depositPriceUnit == 'unspecified') {
29      depositPriceUnit = '(no price unit)';
30      unspecified = true;
31    } else {
32      depositPriceUnit = String(depositPriceUnit).replaceAll('_', ' ');
33    }
34    let depositPricingMethod = deposit["pricing_method"];
35    if (depositPricingMethod == 'unspecified') {
36      depositPricingMethod = 'No pricing method.';
37      unspecified = true;
38    } else {
39      depositPricingMethod = 'The deposit has the ' + depositPricingMethod + ' pricing method.';
40    }
41    const depositUnspecified = unspecified == true ? ' Contact the provider to know more.' : '';
42    const depositAvailability = deposit.availability;
43    if (depositAvailability == 'unspecified') {
44      console.log('No information on the deposit availability. '+
45        '%s %s %s The price is %s %s %s. %s ',
46        depositType, depositPaymentType, depositPricingMethod, deposit.price, deposit.currency, depositPriceUnit, ' Contact the provider to know more.');
47    } else if (depositAvailability == 'available') {
48      console.log('Deposit is available to have. ' +
49        '%s %s %s The price is %s %s %s. %s',
50        depositType, depositPaymentType, depositPricingMethod, deposit.price, deposit.currency, depositPriceUnit, depositUnspecified);
51    }
52    else {
53      console.log('Deposit isn’t available to have. ' +
54        '%s %s %s The price is %s %s %s. %s',
55        depositType, depositPaymentType, depositPricingMethod, deposit.price, deposit.currency, depositPriceUnit, depositUnspecified);
56    }
57  }
58}
59
60await function showDeposit(hotel);
 1# hotel is the hotel object
 2def show_deposit(hotel):
 3    deposits = hotel['metapolicy_struct']['deposit']
 4    if len(deposits) == 0:
 5        print("No deposit")
 6        return
 7    # TODO: your logic
 8    print("Deposits")
 9    for deposit in deposits:
10        unspecified = False
11        deposit_type = deposit['deposit_type']
12        if deposit_type == "unspecified":
13          deposit_type = "No deposit type."
14          unspecified = True
15        else:
16          deposit_type = deposit_type[0:1].capitalize() + deposit_type[1:] + "."
17        deposit_payment_type = deposit['payment_type']
18        if deposit_payment_type == "unspecified":
19          deposit_payment_type = "No deposit payment type."
20          unspecified = True
21        else:
22          deposit_payment_type = "The deposit is made by " + deposit_payment_type + "."
23        deposit_price_unit = deposit['price_unit']
24        if deposit_price_unit == "unspecified":
25          deposit_price_unit = "(no price unit)"
26          unspecified = True
27        else:
28          deposit_price_unit = deposit_price_unit.replace("_", " ")
29        deposit_pricing_method = deposit.pricing_method
30        if deposit_pricing_method == "unspecified":
31          deposit_pricing_method = "No pricing method."
32          unspecified = True
33        else:
34          deposit_pricing_method = "The deposit has the " + deposit_pricing_method + " pricing method."
35        deposit_unspecified = " Contact the provider to know more." if unspecified == True else ""
36        deposit_availability = deposit['availability']
37        if deposit_availability == "unspecified":
38            print(
39                f"No information on the deposit availability. " +
40                f"{deposit_type} {deposit_payment_type} {deposit_pricing_method} " +
41                f"The price is {deposit['price']} {deposit['currency']} {deposit_price_unit}. Contact the provider to know more."
42                )
43        elif deposit_availability == 'available':
44            print(
45                f"Deposit is available to have. " +
46                f"{deposit_type} {deposit_payment_type} {deposit_pricing_method} " +
47                f"The price is {deposit['price']} {deposit['currency']} {deposit_price_unit}.{deposit_unspecified}"
48            )
49        else:
50            print('Deposit isn’t available to have. ' +
51                f"{deposit_type} {deposit_payment_type} {deposit_pricing_method} " +
52                f"The price is {deposit['price']} {deposit['currency']} {deposit_price_unit}.{deposit_unspecified}"
53            )
54
55
56if __name__ == "__main__":
57    show_deposit(hotel)

Read the internet object and show its data to the user

 1// hotel is the hotel object
 2async function showInternet(hotel) {
 3  const internets = hotel.metapolicy_struct.internet;
 4  if (internets.length == 0) {
 5    console.log('No internet');
 6    return;
 7  }
 8  // TODO: your logic
 9  console.log('Internet');
10  for (const internet of internets) {
11    let unspecified = false;
12    let internetType = internet.internet_type;
13    if (internetType == 'unspecified') {
14      internetType = 'No internet type.';
15      unspecified = true;
16    } else {
17      internetType = 'Internet is ' + internetType + '.';
18    }
19    let internetPriceUnit = internet.price_unit;
20    if (internetPriceUnit == 'unspecified') {
21      internetPriceUnit = '(no price unit)';
22      unspecified = true;
23    } else {
24      internetPriceUnit = String(internetPriceUnit).replaceAll('_', ' ');
25    }
26    let internetWorkArea = internet.work_area;
27    if (internetWorkArea == 'unspecified') {
28      internetWorkArea = 'No internet coverage.';
29      unspecified = true;
30    } else {
31      internetWorkArea = 'The internet covers the ' + internetWorkArea + '.';
32    }
33    const internetUnspecified = unspecified == true ? ' Contact the provider to know more.' : '';
34    const internetInclusion = internet.inclusion;
35    if (internetInclusion == 'unspecified') {
36      console.log('%s The price is %s %s %s. %s ' +
37        'No information on the internet inclusion to the overall price.%s',
38        internetType, internet.price, internet.currency, internetPriceUnit, internetWorkArea, ' Contact the provider to know more.');
39    } else if (internetInclusion == 'included') {
40      console.log('%s The price is %s %s %s. %s ' +
41        'The internet is included to the overall price.%s',
42        internetType, internet.price, internet.currency, internetPriceUnit, internetWorkArea, internetUnspecified);
43    }
44    else {
45      console.log('%s The price is %s %s %s. %s ' +
46        'The internet isn’t included to the overall price.%s',
47        internetType, internet.price, internet.currency, internetPriceUnit, internetWorkArea, internetUnspecified);
48    }
49  }
50}
51
52await function showInternet(hotel);
 1# hotel is the hotel object
 2def show_internet(hotel):
 3    internets = hotel["metapolicy_struct"]["internet"]
 4    if len(internets) == 0:
 5        print("No internet")
 6        return
 7    # TODO: your logic
 8    print("Internet")
 9    for internet in internets:
10        unspecified = False
11        internet_type = internet["internet_type"]
12        if internet_type == "unspecified":
13            internet_type = "No internet type."
14            unspecified = True
15        else:
16            internet_type = "Internet is " + internet_type
17        internet_price_unit = internet["price_unit"]
18        if internet_price_unit == "unspecified":
19            internet_price_unit = "(no price unit)"
20            unspecified = True
21        else:
22            internet_price_unit = internet_price_unit.replace("_", " ")
23        internet_work_area = internet["work_area"]
24        if internet_work_area == "unspecified":
25            internet_work_area = "No internet coverage."
26            unspecified = True
27        else:
28            internet_work_area = "The internet covers the " + internet_work_area + "."
29        internet_unspecified = " Contact the provider to know more." if unspecified == True else ""
30        internet_inclusion = internet["inclusion"]
31        if internet_inclusion == "unspecified":
32            print(
33                f"{internet_type} The price is {internet['price']} {internet['currency']} {internet_price_unit}. {internet_work_area} " +
34                f"No information on the internet inclusion to the overall price. Contact the provider to know more."
35            )
36        elif internet_inclusion == "included":
37            print(
38                f"{internet_type} The price is {internet['price']} {internet['currency']} {internet_price_unit}. {internet_work_area} " +
39                f"The internet is included to the overall price.{internet_unspecified}"
40            )
41        else:
42            print(
43                f"{internet_type} The price is {internet['price']} {internet['currency']} {internet_price_unit}. {internet_work_area} " +
44                f"The internet isn’t included to the overall price.{internet_unspecified}"
45            )
46
47
48if __name__ == "__main__":
49    show_internet(hotel)

Read the meal object and show its data to the user

 1// hotel is the hotel object
 2async function showMeal(hotel) {
 3  const meals = hotel.metapolicy_struct.meal;
 4  if (meals.length == 0) {
 5    console.log('No meals for adults');
 6    return;
 7  }
 8  // TODO: your logic
 9  console.log('Meals for adults');
10  for (const meal of meals) {
11    let unspecified = false;
12    let mealType = meal.meal_type;
13    if (mealType == 'unspecified') {
14      mealType = 'No meal type.';
15      unspecified = true;
16    } else {
17      mealType = String(mealType).charAt(0).toUpperCase()
18        + String(mealType).slice(1);
19      mealType = String(mealType).replaceAll('-', ' ') + '.';
20    }
21    const mealUnspecified = unspecified == true ? ' Contact the provider to know more.' : '';
22    const mealInclusion = meal.inclusion;
23    if (mealInclusion == 'unspecified') {
24      console.log('%s The price is %s %s per a person. ' +
25        'No information on the meal inclusion to the overall price.%s',
26        mealType, meal.price, meal.currency, ' Contact the provider to know more.');
27    }
28    else if (mealInclusion == 'included') {
29      console.log('%s The price is %s %s per a person. ' +
30        'The meal is included to the overall price.%s',
31        mealType, meal.price, meal.currency, mealUnspecified);
32    }
33    else {
34      console.log('%s The price is %s %s per a person. ' +
35        'The meal isn’t included to the overall price.%s',
36        mealType, meal.price, meal.currency, mealUnspecified);
37    }
38  }
39}
40
41await function showMeal(hotel);
 1# hotel is the hotel object
 2def show_meal(hotel):
 3    meals = hotel["metapolicy_struct"]["meal"]
 4    if len(meals) == 0:
 5        print("No meals for adults")
 6        return
 7    # TODO: your logic
 8    print("Meals for adults")
 9    for meal in meals:
10        unspecified = False
11        meal_type = meal["meal_type"]
12        if meal_type == "unspecified":
13            meal_type = "No meal type."
14            unspecified = True
15        else:
16            meal_type = meal_type[0:1].capitalize() + meal_type[1:]
17            meal_type = meal_type.replace("-", " ") + "."
18        meal_unspecified = " Contact the provider to know more." if unspecified == True else ""
19        meal_inclusion = meal["inclusion"]
20        if meal_inclusion == "unspecified":
21            print(
22                f"{meal_type} The price is {meal['price']} {meal['currency']} per a person. "
23                f"No information on the meal inclusion to the overall price. Contact the provider to know more."
24            )
25        elif meal_inclusion == "included":
26            print(
27                f"{meal_type} The price is {meal['price']} {meal['currency']} per a person. " +
28                f"The meal is included to the overall price.{meal_unspecified}"
29            )
30        else:
31            print(
32                f"{meal_type} The price is {meal['price']} {meal['currency']} per a person. " +
33                f"The meal isn’t included to the overall price.{meal_unspecified}"
34            )
35
36
37if __name__ == "__main__":
38    show_meal(hotel)

Read the children_meal object and show its data to the user

 1// hotel is the hotel object
 2async function showChildrenMeal(hotel) {
 3  const childrenMeals = hotel.metapolicy_struct.children_meal;
 4  if (childrenMeals.length == 0) {
 5    console.log('No meals for children');
 6    return;
 7  }
 8  // TODO: your logic
 9  console.log('Meals for children');
10  for (const meal of childrenMeals) {
11    let unspecified = false;
12    let mealType = meal.meal_type;
13    if (mealType == 'unspecified') {
14      mealType = 'No meal type.';
15      unspecified = true;
16    } else {
17      mealType = String(mealType).charAt(0).toUpperCase()
18        + String(mealType).slice(1);
19      mealType = String(mealType).replaceAll('-', ' ') + '.';
20    }
21    let mealAgeStart = meal.age_start;
22    let mealAgeEnd = meal.age_end;
23    let mealAge = mealAgeStart == mealAgeEnd ? String(mealAgeStart) : String(mealAgeStart) + '-' + String(mealAgeEnd);
24    const mealUnspecified = unspecified == true ? ' Contact the provider to know more.' : '';
25    const mealInclusion = meal.inclusion;
26    if (mealInclusion == 'unspecified') {
27      console.log('%s For children of %s y.o. The price is %s %s per a child. ' +
28        'No information on the meal inclusion to the overall price.%s',
29        mealType, mealAge, meal.price, meal.currency, ' Contact the provider to know more.');
30    }
31    else if (mealInclusion == 'included') {
32      console.log('%s For children of %s y.o. The price is %s %s per a child. ' +
33        'The meal is included to the overall price.%s',
34        mealType, mealAge, meal.price, meal.currency, mealUnspecified);
35    }
36    else {
37      console.log('%s For children of %s y.o. The price is %s %s per a child. ' +
38        'The meal isn’t included to the overall price.%s',
39        mealType, mealAge, meal.price, meal.currency, mealUnspecified);
40    }
41  }
42}
43
44await function showChildrenMeal(hotel);
 1# hotel is the hotel object
 2def show_children_meal(hotel):
 3    children_meals = hotel["metapolicy_struct"]["children_meal"]
 4    if len(children_meals) == 0:
 5        print("No meals for children")
 6        return
 7    # TODO: your logic
 8    print("Meals for children")
 9    for meal in children_meals:
10        unspecified = False
11        meal_type = meal["meal_type"]
12        if meal_type == "unspecified":
13            meal_type = "No meal type."
14            unspecified = True
15        else:
16            meal_type = meal_type[0:1].capitalize() + meal_type[1:]
17            meal_type = meal_type.replace("-", " ") + "."
18        meal_age_start = meal["age_start"]
19        meal_age_end = meal["age_end"]
20        meal_age = f"{meal_age_start}" if meal_age_start == meal_age_end else f"{meal_age_start}-{meal_age_end}"
21        meal_unspecified = " Contact the provider to know more." if unspecified == True else ""
22        meal_inclusion = meal["inclusion"]
23        if meal_inclusion == "unspecified":
24            print(
25                f"{meal_type} For children of {meal_age} y.o. The price is {meal['price']} {meal['currency']} per a child. "
26                f"No information on the meal inclusion to the overall price.{meal_unspecified}"
27            )
28        elif meal_inclusion == "included":
29            print(
30                f"{meal_type} For children of {meal_age} y.o. The price is {meal['price']} {meal['currency']} per a child. " +
31                f"The meal is included to the overall price.{meal_unspecified}"
32            )
33        else:
34            print(
35                f"{meal_type} For children of {meal_age} y.o. The price is {meal['price']} {meal['currency']} per a child. " +
36                f"The meal isn’t included to the overall price.{meal_unspecified}"
37            )
38
39
40if __name__ == "__main__":
41    show_children_meal(hotel)

Read the extra_bed object and show its data to the user

 1// hotel is the hotel object
 2async function showExtraBed(hotel) {
 3  const beds = hotel.metapolicy_struct.extra_bed;
 4  if (beds.length == 0) {
 5    console.log('No extra beds');
 6    return;
 7  }
 8  // TODO: your logic
 9  console.log('Extra beds');
10  for (const bed of beds) {
11    let unspecified = false;
12    let bedPriceUnit = bed.price_unit;
13    if (bedPriceUnit == 'unspecified') {
14      bedPriceUnit = '(no price unit)';
15      unspecified = true;
16    } else {
17      bedPriceUnit = String(bedPriceUnit).replaceAll('_', ' ');
18    }
19    const bedUnspecified = unspecified == true ? ' Contact the provider to know more.' : '';
20    const bedInclusion = bed.inclusion;
21    if (bedInclusion == 'unspecified') {
22      console.log('%s bed(s). The price is %s %s %s. ' +
23        'No information on the extra beds’ inclusion to the overall price.%s',
24        bed.amount, bed.price, bed.currency, bedPriceUnit, ' Contact the provider to know more.');
25    }
26    else if (bedInclusion == 'included') {
27      console.log('%s bed(s). The price is %s %s %s. ' +
28        'The extra beds are included to the overall price.%s',
29        bed.amount, bed.price, bed.currency, bedPriceUnit, bedUnspecified);
30    }
31    else {
32      console.log('%s bed(s). The price is %s %s %s. ' +
33        'The extra beds aren’t included to the overall price.%s',
34        bed.amount, bed.price, bed.currency, bedPriceUnit, bedUnspecified);
35    }
36  }
37}
38
39await function showExatraBed(hotel);
 1# hotel is the hotel object
 2def show_extra_bed(hotel):
 3    beds = hotel["metapolicy_struct"]["extra_bed"]
 4    if len(beds) == 0:
 5        print("No extra bed")
 6        return
 7    # TODO: your logic
 8    print("Extra beds")
 9    for bed in beds:
10        unspecified = False
11        bed_price_unit = bed["price_unit"]
12        if bed_price_unit == "unspecified":
13          bed_price_unit = "(no price unit)"
14          unspecified = True
15        else:
16          bed_price_unit = bed_price_unit.replace('_', ' ')
17        bed_unspecified = " Contact the provider to know more." if unspecified == True else ""
18        bed_inclusion = bed["inclusion"]
19        if bed_inclusion == "unspecified":
20            print(f"{bed.amount} bed(s). The price is {bed.price} {bed.currency} {bed_price_unit}. " +
21                  f"No information on the extra beds inclusion to the overall price. Contact the provider to know more."
22            )
23        elif bed_inclusion == 'included':
24            print(f"{bed.amount} bed(s). The price is {bed.price} {bed.currency} {bed_price_unit}. " +
25                  f"The extra beds are included to the overall price.{bed_unspecified}"
26            )
27        else:
28            print(f"{bed.amount} bed(s). The price is {bed.price} {bed.currency} {bed_price_unit}. " +
29                  f"The extra beds aren’t included to the overall price.{bed_unspecified}"
30            )
31
32
33if __name__ == "__main__":
34    show_extra_bed(hotel)