ICal (iCal v1.0.0)

View Source

The ICal struct which suppports data serialization and deserialization of iCalendar data, as well as integration with Plug and Phoenix.

Summary

Types

t()

An iCalendar. Event structs are found in events, while vendor-specific X-name-style entries are recorded in custom_properties. All other fields conform to the iCalendar standard.

Functions

Returns the default product ID for calendars generated with the ICal library. To customize this, either set the produdct_id on an %ICal{} struct before serializing it with to_ics, or use the set_vendor/2 convenience function.

To create a Phoenix/Plug endpoint to retrieve ICal data from, add this to the application's config.exs

Converts the data in the file at file_path to an ICal{} struct.

Converts a string containing iCalendar data to an ICal{} struct.

Allows setting a custom vendor string while maintaiing the rest of the default product ID string. This helps identify both the application using this library as well as this library when looking at generated output, which can be useful for debug purposes.

Converts an ICal{} struct to iodata.

Types

custom_properties()

@type custom_properties() :: %{required(String.t()) => custom_value()}

custom_value()

@type custom_value() :: %{params: map(), value: String.t()}

t()

@type t() :: %ICal{
  __other_components: term(),
  alarms: term(),
  custom_properties: custom_properties(),
  default_timezone: String.t(),
  events: [ICal.Event.t()],
  method: String.t() | nil,
  name: String.t() | nil,
  product_id: String.t() | nil,
  scale: String.t(),
  version: String.t()
}

An iCalendar. Event structs are found in events, while vendor-specific X-name-style entries are recorded in custom_properties. All other fields conform to the iCalendar standard.

Functions

default_product_id()

Returns the default product ID for calendars generated with the ICal library. To customize this, either set the produdct_id on an %ICal{} struct before serializing it with to_ics, or use the set_vendor/2 convenience function.

encode_to_iodata(calendar, options \\ [])

To create a Phoenix/Plug endpoint to retrieve ICal data from, add this to the application's config.exs:

config :phoenix, :format_encoders, ics: ICal

Adding this to a controller will trigger the serialization to occur:

calendar = %ICal{ events: events }
render(conn, "index.ics", calendar: calendar)

The file suffix .ics triggers the format_encoder as configured.

The same in a view:

def render("index.ics", %{calendar: calendar}) do
  calendar
end

encode_to_iodata!(calendar, options \\ [])

from_file(file_path)

@spec from_file(file_path :: String.t()) :: t()

Converts the data in the file at file_path to an ICal{} struct.

from_ics(data)

@spec from_ics(ics_data :: String.t()) :: t()

Converts a string containing iCalendar data to an ICal{} struct.

set_vendor(calendar, vendor)

@spec set_vendor(t(), vendor :: String.t()) :: t()

Allows setting a custom vendor string while maintaiing the rest of the default product ID string. This helps identify both the application using this library as well as this library when looking at generated output, which can be useful for debug purposes.

As such, this should be prefered to changing the product_id field on an %ICal{} directly.

to_ics(calendar)

@spec to_ics(t()) :: iolist()

Converts an ICal{} struct to iodata.

The returned iodata can be written directly to a file, sent across the network, or turned into a string locally by passing the return value to to_string/1