Ramp.JSON (ramp v1.0.0)

Copy Markdown View Source

Small decoding helpers shared by every resource module.

These centralize the two recurring conversions needed when mapping Ramp's JSON payloads onto typed structs: parsing RFC 3339 timestamps into DateTime and safely converting map fields into keyword lists suitable for URI.encode_query/1.

Summary

Functions

Passes through non-nil values, drops nils -- used for building query keyword lists.

Parses an RFC 3339 timestamp string into a DateTime, passing nil through.

Encodes an enum-like atom/string value to the wire string Ramp expects.

Formats a DateTime (or ISO date/naive/date) as an RFC 3339 string for query params.

Functions

compact(kw)

@spec compact(keyword()) :: keyword()

Passes through non-nil values, drops nils -- used for building query keyword lists.

datetime(str)

@spec datetime(String.t() | nil) :: DateTime.t() | nil

Parses an RFC 3339 timestamp string into a DateTime, passing nil through.

enum(value)

@spec enum(atom() | String.t() | nil) :: String.t() | nil

Encodes an enum-like atom/string value to the wire string Ramp expects.

to_iso8601(dt)

@spec to_iso8601(DateTime.t() | NaiveDateTime.t() | Date.t() | nil) ::
  String.t() | nil

Formats a DateTime (or ISO date/naive/date) as an RFC 3339 string for query params.