Handwrite v1.0.0 Handwrite.Model.Letter View Source

Represents the a valid letter that can be sent via Handwrite.

Example

letter = %Handwrite.Model.Letter{
  message: "Hey! Thanks for being awesome.",
  handwriting: "5dc306b0bc08d20016f1ec34",
  card: "5dc304cfbc08d20016f1ec2f",
  recipients: [
    %Handwrite.Model.Recipient{
      first_name: "First",
      last_name: "Last",
      street1: "543 Market St",
      city: "San Francisco",
      state: "CA",
      zip: "54321"
    }
  ],
  from: %Handwrite.Model.Sender{
    first_name: "First",
    last_name: "Last",
    street1: "123 6 Mile",
    street2: nil,
    city: "Detroit",
    state: "MI",
    zip: "12345"
  }
}

Link to this section Summary

Functions

Encoding, in this case, means converting a %Letter{} struct into a simple map, but providing validation feedback in the process. encode is also called on the nested Handwrite.Model.Sender struct and list of Handwrite.Model.Recipient structs.

Link to this section Types

Specs

t() :: %Handwrite.Model.Letter{
  card: String.t(),
  from: %Handwrite.Model.Sender{
    city: term(),
    first_name: term(),
    last_name: term(),
    state: term(),
    street1: term(),
    street2: term(),
    zip: term()
  },
  handwriting: String.t(),
  message: String.t(),
  recipients: [
    %Handwrite.Model.Recipient{
      city: term(),
      first_name: term(),
      last_name: term(),
      state: term(),
      street1: term(),
      zip: term()
    }
  ]
}

Link to this section Functions

Specs

encode(Handwrite.Model.Letter.t()) :: {:error, any()} | {:ok, map()}

Encoding, in this case, means converting a %Letter{} struct into a simple map, but providing validation feedback in the process. encode is also called on the nested Handwrite.Model.Sender struct and list of Handwrite.Model.Recipient structs.

Typically, you shouldn't need to call encode directly, as it is handled inside of the send_letter function.

Example

iex> letter = %Handwrite.Model.Letter{...}
iex> Handwrite.Model.Letter.encode(letter)

Returns one of the following:

{:ok, %{...}}
{:error, "A message is required"}
{:error, "A handwriting is required"}
{:error, "A card is required"}
{:error, "A recipient is required"}

{:error, "A recipient's first name is required"}
{:error, "A recipient's last name is required"}
{:error, "A recipient's address requires a street"}
{:error, "A recipient's address requires a city"}
{:error, "A recipient's address requires a state"}
{:error, "A recipient's address requires a zip"}

{:error, "A sender's first name is required"}
{:error, "A sender's last name is required"}
{:error, "A sender's address requires a street"}
{:error, "A sender's address requires a city"}
{:error, "A sender's address requires a state"}
{:error, "A sender's address requires a zip"}