require 'blather/client' require 'vcard' # USAGE: ruby rosterAdd.rb jid@server.tld password path/to/vcf [path/to/second/vcf etc] # # One way to install dependencies and run this is the following: # # $ bundle install --path=.gems # $ bundle exec ruby rosterAdd.rb [args] tels = ARGV.slice!(2..-1).flat_map do |file| Vcard::Vcard.decode(open(file).read).flat_map do |vcard| vcard.telephones.select {|tel| tel.location.include?('cell') }.map { |tel| tel = tel.to_s.gsub(/[^0-9\+]/, '') tel = "+1#{tel}" if tel.length == 10 && tel[0] != '+' { tel: tel, fn: vcard.name.fullname } } end end Blather.logger = Class.new { def send(level, message) warn message end }.new subscription :request? do |s| if s.from.domain == "cheogram.com" puts "Approving #{s.from}" write_to_stream s.approve! end end when_ready do puts "Connected..." tels.each do |tel| item = Blather::RosterItem.new(Blather::JID.new(tel[:tel], "cheogram.com")) item.name = tel[:fn] item.groups = ['SMS'] puts "Adding #{item.jid}" my_roster << item self << Blather::Stanza::Presence::Subscription.new(item.jid, :subscribe) end end