crowous
Version:
A wrapper for the Crous Mobile internal API.
387 lines (367 loc) • 9.83 kB
TypeScript
/**
* An article for a feed.
* @hideconstructor
*/
declare class Article {
category: string;
content: string;
id: string;
imageUrl: string;
publishedAt: Date;
title: string;
}
/**
* Contact information.
* @hideconstructor
*/
declare class Contact {
email: string | null;
/**
* Note that there is no specific format for this field,
* so be prepared to receive any phone number format.
*/
phone: string;
}
/**
* Each day of the week.
*
* Values are very important since they match {@link Restaurant|restaurants'} `opening` day index.
*/
declare enum Day {
Friday = 4,
Monday = 0,
Saturday = 5,
Sunday = 6,
Thursday = 3,
Tuesday = 1,
Wednesday = 2
}
/**
* A feed is a CROUS instance in France.
* @hideconstructor
*/
declare class Feed {
/**
* Internal identifier of the CROUS instance,
* will be used for further requests.
*/
identifier: string;
/**
* Not sure what is this for, it is always on `false`.
*/
isDefault: boolean;
/**
* Name of the CROUS instance.
*/
name: string;
/**
* Get news for the current feed.
*/
getNews(): Promise<Array<Article>>;
/**
* Get residences for the current feed.
*/
getResidences(): Promise<Array<Residence>>;
/**
* Get restaurants for the current feed.
*/
getRestaurants(): Promise<Array<Restaurant>>;
/**
* Get services for the current feed.
*/
getServices(): Promise<Array<Service>>;
}
/**
* A category of a meal.
* @hideconstructor
*/
declare class FoodCategory {
/**
* All dishes available in this category.
*/
dishes: string[];
/**
* Name of the category.
*/
name: string;
}
/**
* An image with a description.
* @hideconstructor
*/
declare class Image {
/**
* Description of the linked image, probably for an `alt` attribute.
*/
description: string;
href: string | null;
}
/**
* A meal of a menu.
* @hideconstructor
*/
declare class Meal {
/**
* Each categories of the meal.
*/
categories: FoodCategory[];
/**
* Sometimes, when something goes wrong or when something needs to be shared
* (e.g.: they exceptionnaly close for this day) it is written here
* and `categories` ends up being an empty list.
*/
information: null | string;
/**
* For when this meal is made for during the day.
*/
moment: Moment;
private static handleFoodCategories;
}
/**
* Menu of a specific date with meals details.
* @hideconstructor
*/
declare class Menu {
/**
* For when this menu is made for.
*/
date: Date;
/**
* Meals available in this menu.
*/
meals: Meal[];
}
/**
* Each moment of the day.
*/
declare enum Moment {
Evening = "soir",
Lunch = "midi",
Morning = "matin"
}
/**
* Payment methods allowed in a specific restaurant.
*/
declare enum PaymentMethod {
Card = "Carte bancaire",
Cash = "Esp\u00E8ce",
Izly = "IZLY",
Moneo = "Mon\u00E9o"
}
/**
* @hideconstructor
*/
declare class Residence {
address: string | null;
albumUrl: string | null;
appointmentUrl: string | null;
area: string;
bookingUrl: string | null;
contact: string;
crousAndGoUrl: string | null;
description: string | null;
email: string;
fullInformation: string;
id: string;
images: string[];
inHomeServices: string[];
latitude: number;
localServices: string;
longitude: number;
phone: string | null;
title: string;
troubleshootingUrl: string | null;
virtualVisitUrl: string | null;
websiteUrl: string | null;
}
/**
* @hideconstructor
*/
declare class Restaurant {
access: string | null;
accessibility: boolean;
/**
* Full address of the restaurant.
*/
address: string;
album: Image | null;
area: string;
closing: string;
/**
* Contact of the restaurant owners.
*/
contact: Contact;
crousAndGoUrl: string | null;
description: string;
id: number;
kind: RestaurantKind;
latitude: number | null;
longitude: number | null;
/**
* Menus for each day of the current month and a bit more sometimes.
* Not sure when they decide to unpublish old menus and publish new ones.
*
* Also, note that they might be subject to change the menu of a given date frequently.
*/
menus: Menu[];
/**
* An opening day string is three boolean (0 or 1).
* Each day of the week is separated by commas (`,`) and each day
* contains three booleans (`0` or `1`).
*
* Those three booleans are {@link Moment|"Morning, Lunch, Evening" values} in this order
* and values `0` means closed and `1` means open.
*
* @example
* // Let's take the following `opening` string.
* "010,011,011,011,111,000,000"
* // - Monday is closed on Morning and Evening, but is opened on Lunch.
* // - Tuesday, Wednesday and Thursday are closed on Morning, but is opened on Lunch and Evening.
* // - Friday is opened all day long (Morning, Lunch and Evening)
* // - Saturday and Sunday are closed all day long (Morning, Lunch and Evening)
*/
opening: string;
operationalHours: string | null;
paymentMethods: PaymentMethod[];
photo: Image | null;
shortDescription: string;
title: string;
/**
* Whether the restaurant has Wi-Fi or not.
*/
wifi: boolean;
/**
* Get the meals of the restaurant for a given date.
*
* @returns A list of the meals for that date or `null` if nothing is found.
*/
getMeals(date: Date): Array<Meal> | null;
/**
* Checks whether the restaurant is opened at a certain date on a certain moment.
*
* @example
* const today = new Date();
* const open = restaurant.isOpen(today, Moment.Lunch);
*/
isOpen(date: Date, moment: Moment): boolean;
/**
* Checks whether the restaurant is opened at a certain day index on a certain moment.
*
* @example
* const open = restaurant.isOpen(Day.Monday, Moment.Lunch);
*/
isOpen(day: Day, moment: Moment): boolean;
}
declare enum RestaurantKind {
AdministrativeRestaurant = "Restaurant administratif",
ApprovedRestaurant = "Restaurant agr\u00E9\u00E9",
Brewery = "Brasserie",
Cafeteria = "Caf\u00E9t\u00E9ria",
CoffeeCorner = "Coffee Corner",
CrousAndGo = "crous and go",
FoodTruck = "Foodtruck",
GroceryStore = "\u00E9picerie",
Kiosk = "Kiosque",
ManagedRestaurant = "Restaurant g\u00E9r\u00E9",
Pizzeria = "Pizz\u00E9ria",
Restaurant = "Restaurant",
SandwichShop = "Sandwicherie",
Scooter = "Triporteur",
SelfService = "Libre-service",
Space = "Space"
}
/**
* @hideconstructor
*/
declare class Service {
description: string | null;
id: string;
imageUrl: string;
title: string;
url: string;
}
/**
* Get all available {@link Feed|feeds}, so every CROUS instance in France.
* @returns A list of all available {@link Feed|feeds}.
*
* @example
* const feeds = await getFeeds();
*/
declare function getFeeds(): Promise<Array<Feed>>;
/**
* Get all {@link Article|articles} for a given identifier.
*
* @param identifier - Where we should look for articles.
* @returns A list of all {@link Article|articles} for a given identifier.
*
* @example
* const news = await getNewsFrom("bordeaux");
*
* for (const article of news) {
* console.log(article.category, article.title);
* }
*
* @example
* const feeds = await getFeeds();
* const news = await getNewsFrom(feeds[0].identifier);
* // ...
*/
declare function getNewsFrom(identifier: string): Promise<Array<Article>>;
/**
* Get all {@link Residence|residences} for a given identifier.
*
* @param identifier - Where we should look for residences.
* @returns A list of all {@link Residence|residences} for a given identifier.
*
* @example
* const residences = await getResidencesFrom("bordeaux");
*
* for (const home of residences) {
* console.log(`[${home.area}]: ${home.title}`);
* }
*
* @example
* const feeds = await getFeeds();
* const residences = await getResidencesFrom(feeds[0].identifier);
* // ...
*/
declare function getResidencesFrom(identifier: string): Promise<Array<Residence>>;
/**
* Get all {@link Restaurant|restaurants} for a given identifier.
*
* @param identifier - Where we should look for restaurants.
* @returns A list of all {@link Restaurant|restaurants} for a given identifier.
*
* @example
* const restaurants = await getRestaurantsFrom("bordeaux");
*
* for (const restaurant of restaurants) {
* console.log(restaurant.title, restaurant.address);
* }
*
* @example
* const feeds = await getFeeds();
* const restaurants = await getRestaurantsFrom(feeds[0].identifier);
* // ...
*/
declare function getRestaurantsFrom(identifier: string): Promise<Array<Restaurant>>;
/**
* Get all {@link Service|services} for a given identifier.
*
* @param identifier - Where we should look for services.
* @returns A list of all {@link Service|services} for a given identifier.
*
* @example
* const services = await getServicesFrom("bordeaux");
*
* for (const service of services) {
* console.log(service.title, service.url);
* }
*
* @example
* const feeds = await getFeeds();
* const services = await getServicesFrom(feeds[0].identifier);
* // ...
*/
declare function getServicesFrom(identifier: string): Promise<Array<Service>>;
export { Article, Contact, Day, Feed, FoodCategory, Image, Meal, Menu, Moment, PaymentMethod, Residence, Restaurant, RestaurantKind, Service, getFeeds, getNewsFrom, getResidencesFrom, getRestaurantsFrom, getServicesFrom };