require 'gtk2'
require 'net/http'
require "uri"
window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
window.border_width = 10
window.title = "lndr.org.es"
window.signal_connect('delete_event') { false }
window.signal_connect('destroy') { Gtk.main_quit }
vbox = Gtk::VBox.new(false, 0)
window.add(vbox)
button1 = Gtk::Button.new("Acórtamela" )
vbox.pack_start(button1, true, true, 0)
button1.show
$caja = Gtk::Entry.new
$caja.set_width_chars( 40 )
vbox.pack_start($caja, true, true, 0 )
$caja.show
scrollwindow = Gtk::ScrolledWindow.new( nil, nil )
$textview = Gtk::TextView.new
$buffer = $textview.buffer
vbox.pack_start(scrollwindow, true)
$textview.set_size_request(40, 10)
$textview.show
button1.signal_connect( "clicked" ) do |w|
callback("AVISO")
end
def callback(txt)
resp = Net::HTTP.post_form(URI('http://lndr.org.es'),
{'longurl'=> $caja.text,
'mi_param_secreto'=> 69})
first, second, third = resp.body.scan(/http:\/\/lndr.org.es\/(.\w+)/)
puts first
$buffer.text = "http://lndr.org.es/" + first[0]
end
$caja.grab_focus
scrollwindow.add($textview)
vbox.show
window.show_all
Gtk.main