diff --git a/stanza/builder.go b/stanza/builder.go new file mode 100644 index 0000000..23d131f --- /dev/null +++ b/stanza/builder.go @@ -0,0 +1,62 @@ +package stanza + +import ( + "encoding/xml" +) + +type builder struct{ lang string } + +// NewBuilder create a builder structure. It act as an interface for packet generation. +// The goal is to work well with code completion to more easily. +// +// Using the builder to format and create packets is optional. You can always prepare +// your packet dealing with the struct manually and initializing them with the right values. +func NewBuilder() *builder { + return &builder{} +} + +// Set default language +func (b *builder) Lang(lang string) *builder { + b.lang = lang + return b +} + +func (b *builder) IQ(a Attrs) IQ { + return IQ{ + XMLName: xml.Name{Local: "iq"}, + Attrs: a, + } +} + +func (b *builder) Message(a Attrs) Message { + return Message{ + XMLName: xml.Name{Local: "message"}, + Attrs: a, + } +} + +func (b *builder) Presence(a Attrs) Presence { + return Presence{ + XMLName: xml.Name{Local: "presence"}, + Attrs: a, + } +} + +// ====================================================================================== +// IQ payloads + +// DiscoInfo builds a default DiscoInfo payload +func (*builder) DiscoInfo() *DiscoInfo { + d := DiscoInfo{ + XMLName: xml.Name{ + Space: NSDiscoInfo, + Local: "query", + }, + } + return &d +} + +// Identity builds a identity struct for use in Disco +func (*builder) Identity(name, category, typ string) *Identity { + return &Identity{} +}