fluminus v1.4.1 Fluminus.API View Source

Provides an abstraction over the LumiNUS API.

This module is dependent on Fluminus.Authorization to authorize to the LumiNUS servers.

Link to this section Summary

Functions

Makes a LumiNUS API call with a given authorization, and then parses the JSON response.

Returns information about the current term.

Returns the modules that the user with the given authorization is taking.

Returns the name of the user with the given authorization.

Link to this section Types

Link to this type

headers()

View Source
headers() :: [{String.t(), String.t()}]

Link to this section Functions

Link to this function

api(authorization, path, method \\ :get, body \\ "", headers \\ [])

View Source
api(Fluminus.Authorization.t(), String.t(), :get | :post, String.t(), headers()) ::
  {:ok, map()}
  | {:error, :expired_token}
  | {:error, {:unexpected_content, any()}}
  | {:error, any()}

Makes a LumiNUS API call with a given authorization, and then parses the JSON response.

Examples

iex> Fluminus.API.api(authorization, "/user/Profile")
{:ok,
 %{
   "displayPhoto" => true,
   "email" => "e0123456@u.nus.edu",
   "expireDate" => "2018-03-10T01:23:45.67+08:00",
   "id" => "01234567-1c23-5abc-def1-2345ad7efcd2",
   "nickName" => "",
   "officialEmail" => "",
   "userID" => "e0123456",
   "userNameOriginal" => "JOHN SMITH"
 }}
Link to this function

current_term(auth)

View Source
current_term(Fluminus.Authorization.t()) ::
  {:ok, %{term: String.t(), description: String.t()}} | {:error, any()}

Returns information about the current term.

Examples

iex> Fluminus.API.current_term(auth)
%{term: "1820", description: "2018/2019 Semester 2"}
Link to this function

modules(auth, current_term_only \\ false)

View Source

Returns the modules that the user with the given authorization is taking.

  • current_term_only - if true, will only return modules that the user is currently taking this semester. Otherwise, return all modules that are still in the LumiNUS system.

Examples

iex> Fluminus.API.modules(auth)
{:ok,
  [
    %Fluminus.API.Module{
      code: "CS2100",
      id: "063773a9-43ac-4dc0-bdc6-4be2f5b50300",
      name: "Computer Organisation",
      teaching?: true,
      term: "1820"
    },
    %Fluminus.API.Module{
      code: "ST2334",
      id: "40582141-1a1d-41b6-ba3a-efa44ff7fd05",
      name: "Probability and Statistics",
      teaching?: false,
      term: "1820"
    },
    %Fluminus.API.Module{
      code: "CS1101S",
      id: "8722e9a5-abc5-4160-820d-bf69d8a63c6f",
      name: "Programming Methodology",
      teaching?: true,
      term: "1810"
    }
  ]
}

iex> Fluminus.API.modules(auth, true)
{:ok,
  [
    %Fluminus.API.Module{
      code: "CS2100",
      id: "063773a9-43ac-4dc0-bdc6-4be2f5b50300",
      name: "Computer Organisation",
      teaching?: true,
      term: "1820"
    },
    %Fluminus.API.Module{
      code: "ST2334",
      id: "40582141-1a1d-41b6-ba3a-efa44ff7fd05",
      name: "Probability and Statistics",
      teaching?: false,
      term: "1820"
    }
  ]
}

Returns the name of the user with the given authorization.

The LumiNUS API returns the name of the user all capitalised, but this function normalises the capitalisation to Title Case.

Examples

iex> Fluminus.API.name(auth)
"John Smith"