Sha256: c20cf7250387ed009a4952c477ad6173652b70639d84a08815d0e31830e5bdf8

Contents?: true

Size: 1.57 KB

Versions: 30

Compression:

Stored size: 1.57 KB

Contents

#!/usr/bin/ruby

# Demonstration of the Vcard helper class
#
# * Retrieves your own vCard
# * Modify fields given on the command line
# * Dumps the vCard
# * Send your vCard to the server

$:.unshift('../../../../../lib')

require 'xmpp4r'
require 'xmpp4r/vcard/helper/vcard'
include Jabber


# settings
if ARGV.length < 2
  puts "Usage:\t./send_vcard.rb <jid> <password> [<field1>=<value1> [... <fieldN>=<valueN>] ]"
  puts "Example:\t./send_vcard.rb user@server/resource password NICKNAME=User \"FN=A user\""
  exit 1
end

# Do the client stuff...
myJID = JID.new(ARGV.shift)
myPassword = ARGV.shift
cl = Client.new(myJID)
cl.connect
cl.auth(myPassword)

# The Vcard helper
vcard_helper = Vcard::Helper.new(cl)

begin
  puts "Retrieving vCard information for #{cl.jid.strip}"
  vcard = vcard_helper.get


  # Inspect the command line for vCard fields to be changed
  ARGV.each { |arg|
    arg.scan(/^(.+?)=(.*)$/) { |field,text|
      puts "field #{field}: #{vcard[field].inspect} => #{text.inspect}"
      vcard[field] = text
    }
  }

  # Dump the vCard
  vcard.fields.each { |field|
    if field.split(/\//).pop == 'BINVAL'
      puts "#{field}:\tBINVAL"
    else
      puts "#{field}:\t#{vcard[field].inspect}"
    end
  }

  begin
    puts "Sending vCard information for #{cl.jid.strip}"
    vcard_helper.set(vcard)
  rescue Exception => e
    puts "Sorry, we stumbled upon the following when sending the vCard of #{cl.jid.strip}: #{e.to_s.inspect}"
  end

rescue Exception => e
  puts "Sorry, we stumbled upon the following when requesting the vCard of #{cl.jid.strip}: #{e.to_s.inspect}"
end

cl.close

Version data entries

30 entries across 30 versions & 12 rubygems

Version Path
brontes3d-xmpp4r-0.4 data/doc/xmpp4r/examples/basic/send_vcard.rb
bryanl-xmpp4r-0.3.2 data/doc/xmpp4r/examples/basic/send_vcard.rb
edavey-xmpp4r-0.4.1 data/doc/xmpp4r/examples/basic/send_vcard.rb
edavey-xmpp4r-0.4.2 data/doc/xmpp4r/examples/basic/send_vcard.rb
edavey-xmpp4r-0.4 data/doc/xmpp4r/examples/basic/send_vcard.rb
heipei-xmpp4r-0.3.2 data/doc/xmpp4r/examples/basic/send_vcard.rb
ln-xmpp4r-0.5 data/doc/xmpp4r/examples/basic/send_vcard.rb
mojodna-xmpp4r-0.4.0.2 data/doc/xmpp4r/examples/basic/send_vcard.rb
mojodna-xmpp4r-0.4.0.3 data/doc/xmpp4r/examples/basic/send_vcard.rb
seanohalpin-xmpp4r-0.4.1 data/doc/xmpp4r/examples/basic/send_vcard.rb
xmpp4r-0.5.6 data/doc/xmpp4r/examples/basic/send_vcard.rb
xmpp4r-0.5.5 data/doc/xmpp4r/examples/basic/send_vcard.rb
mad-p-xmpp4r-0.6.3 data/doc/xmpp4r/examples/basic/send_vcard.rb
mad-p-xmpp4r-0.6.2 data/doc/xmpp4r/examples/basic/send_vcard.rb
mad-p-xmpp4r-0.6.1 data/doc/xmpp4r/examples/basic/send_vcard.rb
mad-p-xmpp4r-0.6.0 data/doc/xmpp4r/examples/basic/send_vcard.rb
cerberus-0.8.0 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/basic/send_vcard.rb
cerberus-0.7.9 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/basic/send_vcard.rb
edavis10-cerberus-0.7.8 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/basic/send_vcard.rb
cerberus-0.7.8 lib/vendor/xmpp4r/data/doc/xmpp4r/examples/basic/send_vcard.rb