Skip to content

Code Documentation

Oscar edited this page Jul 11, 2024 · 42 revisions

MWApiWrapper Documentation

Class Methods

baseEndpoint

Returns the base URL for the OpenMensa API.

mealsPostfix

Returns the postfix URL for fetching meals, with placeholders for canteen ID and date.

locationPostfix

Returns a postfix for a URL to get all canteens within the area of coordinates, which includes placeholders for longitude, latitude, and a radius.

getMealsFrom:on:using:

This function fetches the meals from openmensa.org for a specified canteen on a specified date using a specified endpoint. Both parameters should be strings, and the date needs to be formatted as 'YYYY-MM-DD'. The endpoint should be a class, e.g. WebClient. The return type is a JSON string.

getOutletDictFrom:and:andRadius:

This function fetches all canteens within the radius of the coordinates from openmensa.org. All parameters should be strings. The return type is a Json.

Tests

testApiCallWithInvalidUrl

Tests the API call with an invalid URL. Asserts that the response is empty or a network error occurred.

testApiCallWithValidUrl

Tests the API call with a valid URL. Asserts that the response from 'MWApiWrapper' matches the expected content from the unwrapped call or a network error occurred.

testApiCallWithoutNetwork

This version ensures that the terminology and capitalization are consistent and correct, and it clarifies the purpose of the test.

MWParser Documentation

Class Methods

put:in:

Translates the Dataset into a Json or multiple Jsons and reads the information provided into the instance of a given class. The function returns a list of instances of the provided class, as many as there are valid JSON objects in the Dataset.

set:on:from:

Sets a desired instance variable on any class instance from a dataset. If no data is provided for the given instance variable, nil is the default value.

Tests

testMWParserSetOnFromInvalidData

It tests that the MWParser puts nil in the instance variable fields for which no data is provided.

testMWParserSetOnFromValidData

It tests that the MWParser puts the correct values into the instance variables if data is provided.

testMWParserSetOnFromValidExtensiveData

It tests that the MWParser ignores any additional properties in datasets.

testMWParserWithMultipleJSONObjects

It tests that the MWParser correctly returns two class instances with the correct instance variables for multiple provided JSON objects.

testMWParserWithOneJSONObject

It tests that the MWParser correctly returns a class instance with the values provided by the data put into the instance variables.

MWDataGettingWrapper Documentation

Class Methods

hpiLatitude, hpiLongitude, hpiRadius

Return the coordinates of the HPI values for latitude, longitude, and radius.

initialLatitude, initialLongitude, initialRadius

Return the most recently selected values for latitude, longitude, and radius by the user. If the user has never set these values, they default to the coordinates of the HPI.

canteenDict

Returns a dictionary with canteen ID strings as keys and corresponding canteen name strings as values.

getTodaysMeals

Returns a Collection of CanteenObjects filled in with id, name, date, and meals using the date of today and all in the dictionary, that is stored classside, canteenids. It works by unsing the MWParser and MWApiWrapper look there for more documentation.

getMealsOn:

Returns a Collection of CanteenObjects filled in with id, name, date and meals using the date that is given to the function in the dict, that is stored classside, canteenids. It works by unsing the MWParser and MWApiWrapper look there for more documentation.

requestUserInput

Requests User Input for latitude, longitude, and radius via a Popup window.

switchLocation

Switches the canteen dictionary to the current canteens in the area of the specified latitude, longitude, and radius.

switchToDefaultLocation

Switches the canteen dictionary to the canteens in the area of HPI.

Tests

testSize

It tests that the Collection returned by todaysMeals is equal to the size of the keys in the dictionary stored classside.

testCollectionClasses

It tests that all objects in the Collection returned by todaysMeals are of the MWCanteen class.

testCollectionValues

It tests that all objects in the Collection returned by todaysMeals have data filled in, and no field is nil.

testEmptyCanteen

It tests that the Wrapper correctly handles an empty canteen dictionary.

MWFrame Documentation

Class Methods

register

This method initializes the Mensa Widget label in the Apps menu and opens the widget.

Instance Methods

initialize

This is a method that allows instance creation, assembling all the necessary parts.

createFrame

It assembles all parts of the frame itself, providing position, extent, and other important information.

addText

This adds a TextMorph displaying the text Lunchtime as a placeholder for the actual meal information and adds it as PaneMorph.

Tests

testContent

Tests that the Frame has Panemorphs to make sure it has some sort of content.

testCorrectSubclass

Tests that the Frame as a class is the subclass of a PluggableSystemWindow as it should be.

testCorrectTitle

Tests that the Frame has the right title, "Mensa Widget."

testOpened

Tests the Frame one two things. First, it tests that it has been opened in the world and is, therefore, visible. Secondly, it tests that it is opened and not collapsed on the side.

testSize

Tests that the Frame is not bigger initially than the world it is in.

MWMeals Documentation

Instance variables

category

The category is a String correlating to the meal category provided by the endpoint.

id

The ID is a number correlating to the ID provided by the endpoint.

name

The name is a String correlating to the provided name by the endpoint.

notes

The notes are an ordered collection of additional info provided by the endpoint.

prices

The prices are JSON objects that store the prices for students, employees, pupils, and others provided by the endpoint.

MWCanteens Documentation

Instance Variables

id

The canteen ID is a string correlating to the ID at the endpoint.

name

The canteen's name in German.

date

The date when the following meals for this canteen are available as a string in the format yyyy-mm-dd.

meals

An OrderedCollection of meals that are available at the specified day at this canteen.

MWColorTheme Documentation

Class Methods

primaryColor

Returns a Color that is meant to be the primary color of the widget.

secondaryColor

Returns a Color that is meant to be the secondary color of the widget.

backgroundColor

Returns a Color that is meant to be the background color of the widget.

transparentColor

Returns a Color that is meant to be the transparent color of the widget.

MWMenuBar Documentation

Instance Methodes

decreaseDate:

Given an event stemming from a button click, the date will be updated and the menus newly rendered for the previous day. Also the button will give visual feedback by changing color for that duration.

increaseDate:

Given an event stemming from a button click, the date will be updated, and the menus will be newly rendered for the following day. Also, the button will give visual feedback by changing color for that duration.

updateDate

The date display that shows the user its date will update to the date stored in the instance variable, and also, the target being the window the MenuBar belongs to, will display the meals for the day being shown.

MWMealCleaner Documentation

Class Methods

clean:

This method takes a Meal list as input and executes several cleanings for every meal in this list, according to hard-filtered errors within one meal.