Class: JabberAdmin::Commands::SetVcard
- Inherits:
-
Object
- Object
- JabberAdmin::Commands::SetVcard
- Defined in:
- lib/jabber_admin/commands/set_vcard.rb
Overview
Set contents in a vCard.
Examples:
JabberAdmin.set_vcard!(
user: '[email protected]',
'org.orgunit[]' => %w[Marketing Production],
fn: 'Max Mustermann',
'n.given': 'Max',
'n.family' => 'Mustermann'
)
# => {"org.orgunit[]"=>["Marketing", "Production"],
# "n.family"=>"Mustermann",
# :fn=>"Max Mustermann",
# :"n.given"=>"Max"}
Class Method Summary collapse
-
.call(callable, args = {}, user:, **sym_args) ⇒ Hash
Pass the correct data to the given callable.
Class Method Details
.call(callable, args = {}, user:, **sym_args) ⇒ Hash
Pass the correct data to the given callable.
rubocop:disable Metrics/MethodLength – because the ejabberd REST API
is hard to use in complex scenarios, so we have to work
around it
rubocop:disable Metrics/AbcSize – ditto
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jabber_admin/commands/set_vcard.rb', line 39 def self.call(callable, args = {}, user:, **sym_args) args = args.merge(sym_args) uid, host = user.split('@') set = proc do |key, val| parts = key.to_s.upcase.split('.') body = { name: parts.shift, content: val } meth = 'set_vcard' unless parts.empty? body[:subname] = parts.shift meth = 'set_vcard2' if body[:subname].end_with? '[]' meth += '_multi' body[:subname].delete_suffix!('[]') body[:contents] = body.delete(:content) end end callable.call(meth, user: uid, host: host, **body) end args.each { |key, val| set[key, val] } args end |