require 'rest'
module Twitter
URL = "http://twitter.com/"
class Connection
def initialize(username, password)
@conn = REST::Connection.new(URL, :username => username, :password => password)
@status = Status.new(@conn)
end
attr_reader :status
end
class Status
def initialize(conn)
@conn = conn
end
def update(message)
res = @conn.request_post("statuses/update.xml", :status => message)
end
end
end
#Example 1: Find a State in a Specific Sort Order
#A. Import the XMLPRC Library (Thanx Michael Nuemann)
require 'xmlrpc/client'
#B. You have to define the web address that will run the RPC against
server = XMLRPC::Client.new2('http://betty.userland.com/RPC2')
puts server.call('examples.getStateName', 1)
#Example 2: Find product information based on a UPC number
#C. You have to define the web address that will run the RPC against
server = XMLRPC::Client.new2('http://dev.upcdatabase.com/rpc')
#D. lookupUPC is a method, the number is a product UPC
@item = server.call('lookupUPC', '720642442524')
#E. Store the result in an array
p @item
puts "Description :: " + @item["description"]
puts "Type :: " + @item["size"]
def func1
i = 0
while i <= 5
puts "func1 at: #{Time.now}"
sleep(2)
i = i + 1
end
end
def func2
i = 0
while i <= 5
puts "func2 at: #{Time.now}"
sleep(1)
i = i + 1
end
end
puts "Start at: #{Time.now}"
t1 = Thread.new{func1()}
t2 = Thread.new{func2()}
t1.join
t2.join
puts "End at: #{Time.now}"