Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "rubygems"
- require "xmpp4r"
- require "stringio"
- requests = StringIO.new
- responses = StringIO.new
- def new_cabulous_register(username=nil, password=nil)
- iq = Jabber::Iq.new(:set)
- iq.attributes['id'] = "register_guest"
- query = Jabber::IqQuery.new
- query.add_namespace('jabber:iq:register:cabulous')
- query.add(REXML::Element.new('username').add_text(username)) if username
- query.add(REXML::Element.new('password').add_text(password)) if password
- query.add(REXML::Element.new('device').add_text("iphone"))
- iq.add(query)
- iq
- end
- def new_element(node_name)
- REXML::Element.new(node_name)
- end
- def get_nearby_cabbies()
- iq = Jabber::Iq.new(:get)
- iq.attributes['id'] = "get_nearby_cabbies"
- query = Jabber::IqQuery.new
- query.add_namespace('jabber:iq:public:presence:get')
- options_element = new_element('options')
- options_element.attributes['hailing_nearest'] = 'false'
- options_element.attributes['including_outside'] = 'false'
- query.add(options_element)
- query.add(new_element('upper_left')).add_text('37.729045,-122.470779')
- query.add(new_element('lower_right')).add_text('37.841919,-122.360916')
- iq.add(query)
- iq
- end
- def cabulous_identify_iq(username)
- puts "cabulous_identify_iq(#{username})"
- iq = Jabber::Iq.new(:get)
- iq.attributes['id'] = "cabulous_identify"
- query = Jabber::IqQuery.new
- query.add_namespace('jabber:iq:cabulous:identify')
- query.add(new_element('login')).add_text(username)
- iq.add(query)
- iq
- end
- client = Jabber::Client.new("foo@localhost")
- client.add_stanza_callback do |res|
- if res.attributes['id'] == 'register_guest'
- puts "Found register_guest response!"
- puts
- puts res
- puts
- username = res.get_elements("//username").first.texts.first
- password = res.get_elements("//password").first.texts.first
- puts "Auth'ing with #{username}/#{password}"
- auth_iq = cabulous_identify_iq(username)
- requests.puts auth_iq
- client.send(auth_iq)
- #
- # elsif res.attributes['id'] == 'cabulous_identify'
- # # gnc = get_nearby_cabbies
- # # requests.puts gnc
- # # client.send(gnc)
- end
- responses.puts res # unless res.get_elements("stream").size == 0
- end
- client.connect("75.101.142.197")
- # Login
- cr = new_cabulous_register("guest", "random")
- requests.puts cr
- client.send(cr)
- sleep 5
- puts "Requests:"
- puts requests.string
- puts
- puts "Responses:"
- puts responses.string
- # U: 12669436266594541
- # P: y747
- CabulousSession.as_guest do |session|
- session.nearby_cabbies do |nearby_cabbies|
- nearby_cabbies.each do |cabbie|
- puts cabbie
- end
- end
- end
Add Comment
Please, Sign In to add comment