exampple v0.3.0 Exampple.Xmpp.Jid

Link to this section Summary

Functions

Returns true if the JID is a full JID, false otherwise.

Creates a new JID passing node, server and resource data.

Parse a binary to a Jid struct.

This sigil help us to define JIDs using a simple format and get their struct representation.

Converts JID to a bare JID in binary format.

Link to this section Types

Link to this type

t()

t() :: %Exampple.Xmpp.Jid{
  node: binary(),
  original: term(),
  resource: binary(),
  server: binary()
}

Link to this section Functions

Link to this function

is_full?(jid)

is_full?(binary() | t()) :: boolean() | {:error, :enojid}

Returns true if the JID is a full JID, false otherwise.

Examples: iex> Exampple.Xmpp.Jid.is_full?("alice@example.com") false

iex> Exampple.Xmpp.Jid.is_full?("comp.example.com/data") true

iex> Exampple.Xmpp.Jid.is_full?("bob@example.com/res") true

iex> Exampple.Xmpp.Jid.is_full?("/abc/xyz")

Link to this function

new(node, server, resource)

new(node :: binary(), server :: binary(), resource :: binary()) :: t()

Creates a new JID passing node, server and resource data.

Note that XMPP standard says the JID is case insensitive therefore, and to make easier the handle of comparisons, we put everything in downcase mode.

Examples:

iex> Exampple.Xmpp.Jid.new("foo", "bar", "baz")
%Exampple.Xmpp.Jid{node: "foo", server: "bar", resource: "baz", original: "foo@bar/baz"}

iex> Exampple.Xmpp.Jid.new("FOO", "BAR", "BAZ")
%Exampple.Xmpp.Jid{node: "foo", server: "bar", resource: "BAZ", original: "FOO@BAR/BAZ"}
Link to this function

parse(jid)

parse(jid :: binary()) :: t() | {:error, :enojid}

Parse a binary to a Jid struct.

Examples:

iex> Exampple.Xmpp.Jid.parse("alice@example.com/resource")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", resource: "resource", original: "alice@example.com/resource"}

iex> Exampple.Xmpp.Jid.parse("AlicE@Example.Com/Resource")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", resource: "Resource", original: "AlicE@Example.Com/Resource"}

iex> Exampple.Xmpp.Jid.parse("alice@example.com")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", original: "alice@example.com"}

iex> Exampple.Xmpp.Jid.parse("AlicE@Example.Com")
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", original: "AlicE@Example.Com"}

iex> Exampple.Xmpp.Jid.parse("example.com/resource")
%Exampple.Xmpp.Jid{server: "example.com", resource: "resource", original: "example.com/resource"}

iex> Exampple.Xmpp.Jid.parse("Example.Com/Resource")
%Exampple.Xmpp.Jid{server: "example.com", resource: "Resource", original: "Example.Com/Resource"}

iex> Exampple.Xmpp.Jid.parse("example.com")
%Exampple.Xmpp.Jid{server: "example.com", original: "example.com"}

iex> Exampple.Xmpp.Jid.parse("Example.Com")
%Exampple.Xmpp.Jid{server: "example.com", original: "Example.Com"}

iex> Exampple.Xmpp.Jid.parse(nil)
nil

iex> Exampple.Xmpp.Jid.parse("")
""

iex> Exampple.Xmpp.Jid.parse("/example.com/resource")
{:error, :enojid}
Link to this function

sigil_j(binary, opts)

This sigil help us to define JIDs using a simple format and get their struct representation.

Examples:

iex> import Exampple.Xmpp.Jid
iex> ~j[alice@example.com/ios]
%Exampple.Xmpp.Jid{node: "alice", server: "example.com", resource: "ios", original: "alice@example.com/ios"}
Link to this function

to_bare(jid)

to_bare(binary() | t()) :: binary()

Converts JID to a bare JID in binary format.

Examples: iex> Exampple.Xmpp.Jid.to_bare("alice@example.com") "alice@example.com"

iex> Exampple.Xmpp.Jid.to_bare("alice@example.com/resource") "alice@example.com"

iex> Exampple.Xmpp.Jid.to_bare("example.com") "example.com"

iex> Exampple.Xmpp.Jid.to_bare("example.com/resource") "example.com"