Expander v0.0.1 Expander.Url View Source

Defines an Expanding URL.

This module defines a Expander.Url struct and the main functions for composing URL Expander. As it is the contract for the public APIs of Expander it is a good idea to make use of these functions rather than build the struct yourself.

## Url fields

  • short_url - the short url before expanding, example: "http://stpz.co/haddafios"
  • long_url - the long url after expanding, example: "https://itunes.apple.com/us/app/haddaf-hdaf/id872585884"

## Examples

url = new() |> short_url(“http://stpz.co/haddafios”)

The composable nature makes it very easy to continue expanding upon a given url. url = url |> long_url(“https://itunes.apple.com/us/app/haddaf-hdaf/id872585884”)

You can also directly pass arguments to the new/1 function.

url = new(short_url: “http://stpz.co/haddafios”, long_url: “https://itunes.apple.com/us/app/haddaf-hdaf/id872585884”)

Link to this section Summary

Functions

Sets the long_url field

Returns a Expander.Url struct

Sets the short_url field

Link to this section Types

Link to this type long_url() View Source
long_url() :: URI.t
Link to this type short_url() View Source
short_url() :: URI.t
Link to this type t() View Source
t() :: %Expander.Url{long_url: URI.t, short_url: URI.t}

Link to this section Functions

Link to this function long_url(url, long_url) View Source
long_url(t, long_url) :: t

Sets the long_url field.

The long_url must be a valid url.

Examples

iex> new() |> long_url("https://itunes.apple.com/us/app/haddaf-hdaf/id872585884")
%Expander.Url{long_url: "https://itunes.apple.com/us/app/haddaf-hdaf/id872585884", short_url: nil}
Link to this function new(opts \\ []) View Source
new(none | Enum.t) :: t

Returns a Expander.Url struct.

You can pass a keyword list or a map argument to the function that will be used to populate the fields of that struct. Note that it will silently ignore any fields that it doesn’t know about.

Examples

iex> new()
%Expander.Url{}

iex> new(short_url: "http://stpz.co/haddafios")
%Expander.Url{short_url: "http://stpz.co/haddafios"}

iex> new(long_url: "https://itunes.apple.com/us/app/haddaf-hdaf/id872585884")
%Expander.Url{long_url: "https://itunes.apple.com/us/app/haddaf-hdaf/id872585884"}

You can obviously combine these arguments together:

iex> new(short_url: "http://stpz.co/haddafios", long_url: "https://itunes.apple.com/us/app/haddaf-hdaf/id872585884")
%Expander.Url{short_url: "http://stpz.co/haddafios", long_url: "https://itunes.apple.com/us/app/haddaf-hdaf/id872585884"}
Link to this function short_url(url, short_url) View Source
short_url(t, short_url) :: t

Sets the short_url field.

The short_url must be a valid url.

Examples

iex> new() |> short_url("http://stpz.co/haddafios")
%Expander.Url{short_url: "http://stpz.co/haddafios", long_url: nil}